-
Notifications
You must be signed in to change notification settings - Fork 122
Round Trip Printing. update tests for repr and show methods #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anandijain
wants to merge
9
commits into
JuliaPhysics:master
Choose a base branch
from
anandijain:myb/show
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c10d8b
Round-trip printing
YingboMa 2a9717f
update tests
anandijain 89099f9
fix dimerror display, overload print, fix test
anandijain ad7c114
Update src/display.jl
anandijain 06f7df1
Update src/display.jl
anandijain a6093e0
Update test/runtests.jl
anandijain 318149c
Update test/runtests.jl
anandijain 7cd3862
Update src/utils.jl
anandijain 9caac72
Update src/utils.jl
anandijain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1291,21 +1291,21 @@ end | |
| withenv("UNITFUL_FANCY_EXPONENTS" => false) do | ||
| @static if VERSION ≥ v"1.6.0-DEV.770" | ||
| @test string(typeof(1.0m/s)) == | ||
| "Quantity{Float64, 𝐋 𝐓^-1, FreeUnits{(m, s^-1), 𝐋 𝐓^-1, nothing}}" | ||
| "Quantity{Float64, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, -1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), nothing}}" | ||
| @test string(typeof(m/s)) == | ||
| "FreeUnits{(m, s^-1), 𝐋 𝐓^-1, nothing}" | ||
| "FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, -1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), nothing}" | ||
| else | ||
| @test string(typeof(1.0m/s)) == | ||
| "Quantity{Float64,𝐋 𝐓^-1,FreeUnits{(m, s^-1),𝐋 𝐓^-1,nothing}}" | ||
| "Quantity{Float64, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, -1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), nothing}}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (and some other tests) would need to be changed to match the old printing of type parameters (no spaces after commas), that’s why that |
||
| @test string(typeof(m/s)) == | ||
| "FreeUnits{(m, s^-1),𝐋 𝐓^-1,nothing}" | ||
| "FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, -1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), nothing}" | ||
| end | ||
| @test string(dimension(1u"m/s")) == "𝐋 𝐓^-1" | ||
| @test string(NoDims) == "NoDims" | ||
| @test string(dimension(1u"m/s")) == "Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}()" | ||
| @test string(NoDims) == "Unitful.Dimensions{()}()" | ||
| end | ||
| @testset ":fancy_exponent IOContext property" begin | ||
| @test sprint(io -> show(IOContext(io, :fancy_exponent => true), u"m/s")) == "m s⁻¹" | ||
| @test sprint(io -> show(IOContext(io, :fancy_exponent => false), u"m/s")) == "m s^-1" | ||
| @test sprint(io -> show(IOContext(io, :fancy_exponent => true), u"m/s")) == "FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, -1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), nothing}()" | ||
| @test sprint(io -> show(IOContext(io, :fancy_exponent => false), u"m/s")) == "FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, -1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), nothing}()" | ||
anandijain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
|
|
||
|
|
@@ -1315,31 +1315,37 @@ Base.show(io::IO, ::MIME"text/plain", ::Foo) = print(io, "42.0") | |
|
|
||
| @testset "Show quantities" begin | ||
| withenv("UNITFUL_FANCY_EXPONENTS" => false) do | ||
| @test repr(1.0 * u"m * s * kg^-1") == "1.0 m s kg^-1" | ||
| @test repr(1.0 * u"m * s * kg^-1") == "Quantity{Float64, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Mass}(-1//1), Unitful.Dimension{:Time}(1//1))}(), FreeUnits{(Unitful.Unit{:Gram, Unitful.Dimensions{(Unitful.Dimension{:Mass}(1//1),)}()}(3, -1//1), Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, 1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Mass}(-1//1), Unitful.Dimension{:Time}(1//1))}(), nothing}}(1.0)" | ||
| @test repr("text/plain", 1.0 * u"m * s * kg^-1") == "1.0 m s kg^-1" | ||
| @test repr(Foo() * u"m * s * kg^-1") == "1 m s kg^-1" | ||
| @test repr(Foo() * u"m * s * kg^-1") == "Quantity{Foo, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Mass}(-1//1), Unitful.Dimension{:Time}(1//1))}(), FreeUnits{(Unitful.Unit{:Gram, Unitful.Dimensions{(Unitful.Dimension{:Mass}(1//1),)}()}(3, -1//1), Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, 1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Mass}(-1//1), Unitful.Dimension{:Time}(1//1))}(), nothing}}(1)" | ||
| @test repr("text/plain", Foo() * u"m * s * kg^-1") == "42.0 m s kg^-1" | ||
|
|
||
| # Complex quantities | ||
| @test repr((1+2im) * u"m/s") == "(1 + 2im) m s^-1" | ||
| @test repr((1+2im) * u"m/s") == "Quantity{Complex{Int64}, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1), Unitful.Unit{:Second, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}()}(0, -1//1)), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}(), nothing}}(1 + 2im)" | ||
| @test repr("text/plain", (1+2im) * u"m/s") == "(1 + 2im) m s^-1" | ||
|
|
||
| # Angular degree printing #253 | ||
| @test sprint(show, 1.0°) == "1.0°" | ||
| @test sprint(show, 1.0°) == "Quantity{Float64, Unitful.Dimensions{()}(), FreeUnits{(Unitful.Unit{:Degree, Unitful.Dimensions{()}()}(0, 1//1),), Unitful.Dimensions{()}(), nothing}}(1.0)" | ||
| @test repr("text/plain", 1.0°) == "1.0°" | ||
|
|
||
| # Concise printing of ranges | ||
| @test repr((1:10)*u"kg/m^3") == "(1:10) kg m^-3" | ||
| @test repr((1.0:0.1:10.0)*u"kg/m^3") == "(1.0:0.1:10.0) kg m^-3" | ||
| @test repr((1:10)*°) == "(1:10)°" | ||
| @test repr("text/plain", (1:10)*u"kg/m^3") == "(1:10) kg m^-3" | ||
| @test repr("text/plain", (1.0:0.1:10.0)*u"kg/m^3") == "(1.0:0.1:10.0) kg m^-3" | ||
| @test repr("text/plain", (1:10)*°) == "(1:10)°" | ||
| end | ||
| withenv("UNITFUL_FANCY_EXPONENTS" => true) do | ||
| @test repr(1.0 * u"m * s * kg^(-1//2)") == "1.0 m s kg⁻¹ᐟ²" | ||
| @test repr("text/plain", 1.0 * u"m * s * kg^(-1//2)") == "1.0 m s kg⁻¹ᐟ²" | ||
| end | ||
| withenv("UNITFUL_FANCY_EXPONENTS" => nothing) do | ||
| @test repr(1.0 * u"m * s * kg^(-1//2)") == | ||
| @test repr("text/plain", 1.0 * u"m * s * kg^(-1//2)") == | ||
| (Sys.isapple() ? "1.0 m s kg⁻¹ᐟ²" : "1.0 m s kg^-1/2") | ||
| end | ||
|
|
||
| @testset "roundtripping show" begin | ||
| u = u"m/s" | ||
| u2 = eval(Meta.parse(repr(u))) | ||
| @test u == u2 | ||
anandijain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
|
|
||
| @testset "DimensionError message" begin | ||
|
|
@@ -1349,11 +1355,11 @@ end | |
| String(take!(b)) | ||
| end | ||
| @test errorstr(DimensionError(1u"m",2)) == | ||
| "DimensionError: 1 m and 2 are not dimensionally compatible." | ||
| "DimensionError: Quantity{Int64, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}(), FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1),), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}(), nothing}}(1) and 2 are not dimensionally compatible." | ||
anandijain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @test errorstr(DimensionError(1u"m",NoDims)) == | ||
| "DimensionError: 1 m and NoDims are not dimensionally compatible." | ||
| "DimensionError: Quantity{Int64, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}(), FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1),), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}(), nothing}}(1) and Unitful.Dimensions{()}() are not dimensionally compatible." | ||
| @test errorstr(DimensionError(u"m",2)) == | ||
| "DimensionError: m and 2 are not dimensionally compatible." | ||
| "DimensionError: FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}()}(0, 1//1),), Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}(), nothing}() and 2 are not dimensionally compatible." | ||
| end | ||
|
|
||
| @testset "Logarithmic quantities" begin | ||
|
|
@@ -1673,12 +1679,12 @@ end | |
|
|
||
| @testset "> Display" begin | ||
| withenv("UNITFUL_FANCY_EXPONENTS" => false) do | ||
| @test repr(3u"dB/Hz") == "[3 dB] Hz^-1" | ||
| @test repr(3u"dB/Hz") == "Quantity{Gain{LogInfo{:Decibel, 10, 10}, :?, Int64}, Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}(), FreeUnits{(Unitful.Unit{:Hertz, Unitful.Dimensions{(Unitful.Dimension{:Time}(-1//1),)}()}(0, -1//1),), Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}(), nothing}}(Gain{LogInfo{:Decibel, 10, 10}, :?, Int64}(3))" | ||
| @test repr("text/plain", 3u"dB/Hz") == "[3 dB] Hz^-1" | ||
| end | ||
| @test Unitful.abbr(3u"dBm") == "dBm" | ||
| @test Unitful.abbr(@dB 3V/1.241V) == "dB (1.241 V)" | ||
| @test string(360°) == "360°" | ||
| @test Unitful.abbr(@dB 3V/1.241V) == "dB (Quantity{Float64, Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}(), FreeUnits{(Unitful.Unit{:Volt, Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}()}(0, 1//1),), Unitful.Dimensions{(Unitful.Dimension{:Current}(-1//1), Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}(), nothing}}(1.241))" | ||
| @test repr("text/plain", 360°) == "360°" | ||
anandijain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| @testset "> Thanks for signing up for Log Facts!" begin | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.