Skip to content

Commit

Permalink
Try u_str without eval
Browse files Browse the repository at this point in the history
  • Loading branch information
tshort authored and ajkeller34 committed Oct 15, 2018
1 parent 71d5210 commit 7bdf1df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/user.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ function replace_value(ex::Expr)
ex.args[i]=replace_value(ex.args[i])
end
end
return Core.eval(@__MODULE__, ex)
return ex
elseif ex.head == :tuple
for i=1:length(ex.args)
if typeof(ex.args[i])==Symbol
Expand All @@ -491,7 +491,7 @@ function replace_value(ex::Expr)
error("only use symbols inside the tuple.")
end
end
return Core.eval(@__MODULE__, ex)
return ex
else
error("Expr head $(ex.head) must equal :call or :tuple")
end
Expand All @@ -505,7 +505,7 @@ function replace_value(sym::Symbol)

m = unitmodules[inds[end]]
u = getfield(m, sym)

any(u != u1 for u1 in getfield.(unitmodules[inds[1:(end-1)]], sym)) &&
@warn(string("Symbol $sym was found in multiple registered unit modules. ",
"We will use the one from $m."))
Expand Down
16 changes: 8 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ end
end

@testset "Unit string macro" begin
@test macroexpand(@__MODULE__, :(u"m")) == m
@test macroexpand(@__MODULE__, :(u"m,s")) == (m,s)
@test macroexpand(@__MODULE__, :(u"1.0")) == 1.0
@test macroexpand(@__MODULE__, :(u"m/s")) == m/s
@test macroexpand(@__MODULE__, :(u"1.0m/s")) == 1.0m/s
@test macroexpand(@__MODULE__, :(u"m^-1")) == m^-1
@test macroexpand(@__MODULE__, :(u"dB/Hz")) == dB/Hz
@test macroexpand(@__MODULE__, :(u"3.0dB/Hz")) == 3.0dB/Hz
@test u"m" == m
@test u"m,s" == (m,s)
@test u"1.0" == 1.0
@test u"m/s" == m/s
@test u"1.0m/s" == 1.0m/s
@test u"m^-1" == m^-1
@test u"dB/Hz" == dB/Hz
@test u"3.0dB/Hz" == 3.0dB/Hz
@test_throws LoadError macroexpand(@__MODULE__, :(u"N m"))
@test_throws LoadError macroexpand(@__MODULE__, :(u"abs(2)"))
@test_throws LoadError @eval u"basefactor"
Expand Down

0 comments on commit 7bdf1df

Please sign in to comment.