Skip to content

Commit 0da797a

Browse files
authored
Merge pull request #15 from Deduction42/DEV
qparse no longer applies ubase (improves consistency with uparse)
2 parents c9f0c7d + 5b9547d commit 0da797a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FlexUnits"
22
uuid = "76e01b6b-c995-4ce6-8559-91e72a3d4e95"
33
authors = ["Ruben Gonzalez <[email protected]> and contributors"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[compat]
77
julia = "1.10"

src/RegistryTools.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function uparse(str::String, reg::AbstractDict{Symbol, U}) where {U<:AbstractUni
207207
end
208208

209209
function qparse(str::String, reg::AbstractDict{Symbol,U}) where {U<:AbstractUnitLike}
210-
return eval(qparse_expr(str, reg)) :: Quantity{Float64, dimtype(U)}
210+
return eval(qparse_expr(str, reg)) :: Quantity{Float64, U}
211211
end
212212

213213
# Expression parsing (for dynamic and macros) ==============================================================
@@ -239,9 +239,9 @@ end
239239

240240

241241
function qparse_expr(ex::PARSE_CASES, reg::AbstractDict{Symbol, U}) where U <: AbstractUnitLike
242-
Q = Quantity{Float64, dimtype(U)}
243-
ex = _parse_expr(ex, reg)
244-
return :($convert($Q, ubase($ex)))
242+
Q = Quantity{Float64, U}
243+
ex_new = _parse_expr(ex, reg)
244+
return :($convert($Q, $ex_new))
245245
end
246246

247247
# Casing out parsing ======================================================================================

test/runtests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ end
259259
@test ustrip(x) == 1.3
260260
@test ustrip_base(x) == 1300 # SI base units
261261
@test x == q"1.3km/s^2"
262-
@test x !== q"1.3km/s^2"
263-
@test abs(x) === q"1.3km/s^2"
262+
@test typeof(x) == typeof(q"1.3km/s^2")
263+
@test abs(x) === ubase(q"1.3km/s^2")
264264

265265
y = 0.9u"sqrt(mΩ)"
266266
@test typeof(y) == Quantity{Float64, AffineUnits{Dimensions{DEFAULT_RATIONAL}}}
@@ -275,11 +275,11 @@ end
275275
y32 = convert(Quantity{Float32, AffineUnits{Dimensions{DEFAULT_RATIONAL}}}, y)
276276
@test typeof(y32) == Quantity{Float32, AffineUnits{Dimensions{DEFAULT_RATIONAL}}}
277277

278-
z = 1*u"yr"
278+
z = 1.0*u"yr"
279279
@test ustrip_base(z) 60 * 60 * 24 * 365.25
280-
@test z == 1*uparse("yr")
281-
@test z == qparse("1yr")
282-
@test 1/z == qparse("1/yr")
280+
@test z === 1.0*uparse("yr")
281+
@test z === qparse("1yr")
282+
@test 1/z === ubase(qparse("1/yr"))
283283
@test_throws MethodError qparse("yr")
284284

285285
# Test type stability of extreme range of units

0 commit comments

Comments
 (0)