Skip to content

Commit 40521a1

Browse files
committed
Add test for dimensionless dimensionerror message
1 parent 6eb5fe6 commit 40521a1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/unittests.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ using StaticArrays: SArray, MArray
99
using LinearAlgebra: norm
1010
using Test
1111

12+
function record_show(s, f=show)
13+
io = IOBuffer()
14+
f(io, s)
15+
return String(take!(io))
16+
end
17+
1218
@testset "Basic utilities" begin
1319

1420
for Q in [Quantity, GenericQuantity], T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_BASE_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
@@ -447,14 +453,8 @@ end
447453
# Conversion to Rational without specifying type
448454
@test convert(Rational, FixedRational{UInt8,6}(2)) === Rational{UInt8}(2)
449455

450-
# Showing rationals
451-
function show_string(i)
452-
io = IOBuffer()
453-
show(io, i)
454-
return String(take!(io))
455-
end
456-
@test show_string(FixedRational{Int,10}(2)) == "2"
457-
@test show_string(FixedRational{Int,10}(11//10)) == "11//10"
456+
@test record_show(FixedRational{Int,10}(2)) == "2"
457+
@test record_show(FixedRational{Int,10}(11//10)) == "11//10"
458458

459459
# Promotion rules
460460
@test promote_type(FixedRational{Int64,10},FixedRational{BigInt,10}) == FixedRational{BigInt,10}
@@ -1164,6 +1164,8 @@ end
11641164
end
11651165
end
11661166
end
1167+
s = record_show(DimensionError(u"km/s"), showerror)
1168+
@test occursin("not dimensionless", s)
11671169
end
11681170

11691171
@testset "Assorted dimensionful functions" begin

0 commit comments

Comments
 (0)