Skip to content
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

Try u_str without eval #161

Merged
merged 1 commit into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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