File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -66,27 +66,20 @@ function map_to_scope(ex::Expr)
66
66
elseif ex. head == :tuple
67
67
ex. args[:] = map (map_to_scope, ex. args)
68
68
return ex
69
- elseif ex. head == :.
70
- if ex. args[1 ] == :Constants
71
- @assert ex. args[2 ] isa QuoteNode
72
- return lookup_constant (ex. args[2 ]. value)
73
- else
74
- return ex
75
- end
69
+ elseif ex. head == :. && ex. args[1 ] == :Constants
70
+ @assert ex. args[2 ] isa QuoteNode
71
+ return lookup_constant (ex. args[2 ]. value)
76
72
else
77
- throw (ArgumentError (" Unexpected expression: $ex . Only `:call`, `:tuple`, and `:.` are expected." ))
78
- return ex
73
+ throw (ArgumentError (" Unexpected expression: $ex . Only `:call`, `:tuple`, and `:.` (for `Constants`) are expected." ))
79
74
end
80
75
end
81
76
function map_to_scope (sym:: Symbol )
82
77
if sym in UNIT_SYMBOLS
83
78
return lookup_unit (sym)
84
79
elseif sym in CONSTANT_SYMBOLS
85
80
throw (ArgumentError (" Symbol $sym found in `Constants` but not `Units`. Please access the `Constants` module. For example, `u\" Constants.$sym \" `." ))
86
- return sym
87
81
else
88
82
throw (ArgumentError (" Symbol $sym not found in `Units` or `Constants`." ))
89
- return sym
90
83
end
91
84
end
92
85
function map_to_scope (ex)
Original file line number Diff line number Diff line change 471
471
@test typeof (u " fm" ) == DEFAULT_QUANTITY_TYPE
472
472
@test typeof (u " fm" ^ 2 ) == DEFAULT_QUANTITY_TYPE
473
473
474
+ # Can also use tuples:
475
+ @test typeof (u " (m, s)" ) == Tuple{DEFAULT_QUANTITY_TYPE, DEFAULT_QUANTITY_TYPE}
476
+
474
477
@test_throws LoadError eval (:(u " x" ))
475
478
VERSION >= v " 1.9" && @test_throws " Symbol x not found" uparse (" x" )
476
479
VERSION >= v " 1.9" && @test_throws " Symbol c found in `Constants` but not `Units`" uparse (" c" )
480
+ VERSION >= v " 1.9" && @test_throws " Unexpected expression" uparse (" import ..Units" )
477
481
end
478
482
479
483
@testset " Constants" begin
You can’t perform that action at this time.
0 commit comments