Skip to content

Conversation

michikawa07
Copy link
Contributor

Nevertheless, expanded pkg of Unitful.jl (i.e., UnitfulAtomic.jl) execute Unitful.register(), Unitful.uparse did not recognize these pkgs automatically (due to the defaut value of unit_context arg is Unitful only).
This commit modified this issue.

The following example is picked up from runtest.jl

# Test that the @u_str macro will not find units in modules which are
# not loaded before the u_str invocation.
module FooUnits
    using Unitful
    @unit foo "foo" MyFoo 1u"m" false
    Unitful.register(FooUnits)
end
# ...
# Test that u_str works when FooUnits is correctly loaded.
module DoesUseFooUnits
    using Unitful, ..FooUnits
    foo() = 1u"foo"
end
@test DoesUseFooUnits.foo() === 1u"foo"

# Tests for unit extension modules in unit parsing
@test_throws ArgumentError uparse("foo", unit_context=Unitful)
################################ Here is the effect of this PR
@test uparse("foo") === u"foo" # This work, because default `unit_context` is now `vcat(Unitful, Unitful.unitmodules)`
################################
@test uparse("foo", unit_context=FooUnits) === u"foo"
@test uparse("foo", unit_context=[Unitful, FooUnits]) === u"foo"
@test uparse("foo", unit_context=[FooUnits, Unitful]) === u"foo"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant