diff --git a/coverage.jl b/coverage.jl index d7c13633..7db2e34a 100644 --- a/coverage.jl +++ b/coverage.jl @@ -1,6 +1,7 @@ using Coverage # process '*.cov' files coverage = process_folder() # defaults to src/; alternatively, supply the folder name as argument +coverage = cat(coverage, process_folder("ext"); dims=1) # add coverage from ext/ LCOV.writefile("lcov.info", coverage) @@ -8,7 +9,7 @@ LCOV.writefile("lcov.info", coverage) coverage = merge_coverage_counts( coverage, filter!( - let prefixes = (joinpath(pwd(), "src", ""),) + let prefixes = (joinpath(pwd(), "src", ""), joinpath(pwd(), "ext", "")) c -> any(p -> startswith(c.filename, p), prefixes) end, LCOV.readfolder("test"), diff --git a/ext/DynamicQuantitiesUnitfulExt.jl b/ext/DynamicQuantitiesUnitfulExt.jl index c23902d8..4f79d258 100644 --- a/ext/DynamicQuantitiesUnitfulExt.jl +++ b/ext/DynamicQuantitiesUnitfulExt.jl @@ -34,6 +34,11 @@ Base.convert(::Type{DynamicQuantities.Quantity}, x::Unitful.Quantity) = return DynamicQuantities.Quantity(value, dimension) end +Base.convert(::Type{DynamicQuantities.Quantity}, x::Unitful.FreeUnits) = + let + convert(DynamicQuantities.Quantity, 1.0 * x) + end + Base.convert(::Type{DynamicQuantities.Dimensions}, d::Unitful.Dimensions{D}) where {D} = let cumulator = DynamicQuantities.Dimensions() @@ -45,6 +50,11 @@ Base.convert(::Type{DynamicQuantities.Dimensions}, d::Unitful.Dimensions{D}) whe cumulator end +Base.convert(::Type{DynamicQuantities.Dimensions}, x::Unitful.FreeUnits) = + let + DynamicQuantities.dimension(convert(DynamicQuantities.Quantity, x)) + end + function _map_dim_name_to_dynamic_units(::Type{Unitful.Dimension{D}}) where {D} # (We could do this automatically, but it's more obvious what we are doing this way.) D == :Length && return :length @@ -54,7 +64,7 @@ function _map_dim_name_to_dynamic_units(::Type{Unitful.Dimension{D}}) where {D} D == :Temperature && return :temperature D == :Luminosity && return :luminosity D == :Amount && return :amount - error("Unknown dimension: $D") + throw(error("Unknown dimension: $D. Valid dimensions are: (:Length, :Mass, :Time, :Current, :Temperature, :Luminosity, :Amount).")) end diff --git a/test/unitful.jl b/test/unitful.jl index 243b1eca..860e0e72 100644 --- a/test/unitful.jl +++ b/test/unitful.jl @@ -8,3 +8,14 @@ x_unitful = 0.2u"mol^2*A^(-1//2)*cd^(2//5)" @test convert(Unitful.Quantity, x) ≈ x_unitful @test convert(DynamicQuantities.Quantity, convert(Unitful.Quantity, x)) ≈ x + +@test convert(DynamicQuantities.Quantity, u"c") ≈ 2.99792458e8 * DynamicQuantities.Dimensions(length=1, time=-1) +@test convert(DynamicQuantities.Dimensions, u"c") == DynamicQuantities.Dimensions(length=1, time=-1) +@test convert(DynamicQuantities.Dimensions, Unitful.dimension(u"c")) == DynamicQuantities.Dimensions(length=1, time=-1) + +# Defining a custom dimension should throw an error: +Unitful.@dimension 𝚾 "𝚾" MyDimension +# @refunit m "m" Meter 𝐋 true +Unitful.@refunit my_unit "x" MyDimension 𝚾 true + +@test_throws "Unknown dimension: MyDimension" convert(DynamicQuantities.Quantity, 1.0 * my_unit)