Skip to content

Commit 56760f3

Browse files
authored
Update tests for show/summary (#191)
This adds the tests for Julia nightly build, which no longer needs the `showarg` customization.
1 parent 2f2a34a commit 56760f3

File tree

2 files changed

+94
-18
lines changed

2 files changed

+94
-18
lines changed

test/fixed.jl

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,6 @@ end
358358
end
359359
end
360360

361-
@testset "Show" begin
362-
x = Fixed{Int32,5}(0.25)
363-
iob = IOBuffer()
364-
show(iob, x)
365-
str = String(take!(iob))
366-
@test str == "0.25Q26f5"
367-
@test eval(Meta.parse(str)) == x
368-
end
369-
370361
@testset "rand" begin
371362
for F in (Fixed{Int8,7}, Fixed{Int16,8}, Fixed{Int16,10}, Fixed{Int32,16})
372363
@test isa(rand(F), F)
@@ -433,3 +424,55 @@ end
433424
@test promote_type(Float32,Q0f7,Int) == Float32
434425
@test promote_type(Q0f7,Q1f6,Q2f5,Q3f4,Q4f3,Q5f2) == Fixed{Int128,7}
435426
end
427+
428+
@testset "show" begin
429+
iob = IOBuffer()
430+
q0f7 = reinterpret(Q0f7, signed(0xaa))
431+
show(iob, q0f7)
432+
str = String(take!(iob))
433+
@test str == "-0.672Q0f7"
434+
@test eval(Meta.parse(str)) === q0f7
435+
436+
q15f16 = reinterpret(Q15f16, signed(0xaaaaaaaa))
437+
show(iob, q15f16)
438+
str = String(take!(iob))
439+
@test str == "-21845.33334Q15f16"
440+
@test eval(Meta.parse(str)) === q15f16
441+
442+
show(IOContext(iob, :compact=>true), q15f16)
443+
@test String(take!(iob)) == "-21845.3"
444+
445+
show(IOContext(iob, :compact=>true, :typeinfo=>Q15f16), q15f16)
446+
@test String(take!(iob)) == "-21845.3"
447+
448+
show(IOContext(iob, :compact=>true, :typeinfo=>Fixed), q15f16)
449+
@test String(take!(iob)) == "-21845.3"
450+
451+
show(IOContext(iob, :typeinfo=>Q15f16), q15f16)
452+
@test String(take!(iob)) == "-21845.33334Q15f16" # TODO: Consider removing suffix (issue #188)
453+
454+
show(IOContext(iob, :typeinfo=>Normed), q15f16)
455+
@test String(take!(iob)) == "-21845.33334Q15f16"
456+
457+
show(iob, Fixed{Int128,64}(-1.2345e6))
458+
@test_broken String(take!(iob)) == "Fixed{Int128,64}(-1.2345e6)" # "Q63f64" is not defined
459+
460+
# TODO: remove this test
461+
show(iob, reinterpret(Fixed{Int8,8}, signed(0xaa)))
462+
@test_broken String(take!(iob)) == "Fixed{Int8,8}(-0.336)" # "Q-1f8" is invalid
463+
end
464+
465+
@testset "summary" begin
466+
a = Q0f7[0.2, 0.4]
467+
aa = Fixed[0.2Q0f7 0.4Q0f15]
468+
469+
if VERSION >= v"1.6.0-DEV.356"
470+
@test_broken summary(a) == "2-element Vector{Q0f7}"
471+
@test_broken summary(view(a, 1:2)) == "2-element view(::Vector{Q0f7}, 1:2) with eltype Q0f7"
472+
@test_broken summary(aa) == "1×2 Matrix{Fixed}"
473+
else
474+
@test summary(a) == "2-element Array{Q0f7,1} with eltype Fixed{Int8,7}"
475+
@test summary(view(a, 1:2)) == "2-element view(::Array{Q0f7,1}, 1:2) with eltype Fixed{Int8,7}"
476+
@test_broken summary(aa) == "1×2 Array{Fixed,2}"
477+
end
478+
end

test/normed.jl

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,51 @@ end
403403
end
404404

405405
@testset "show" begin
406-
x = reinterpret(N0f8, 0xaa)
407406
iob = IOBuffer()
408-
show(iob, x)
407+
n0f8 = reinterpret(N0f8, 0xaa)
408+
show(iob, n0f8)
409409
str = String(take!(iob))
410410
@test str == "0.667N0f8"
411-
@test eval(Meta.parse(str)) == x
411+
@test eval(Meta.parse(str)) === n0f8
412+
413+
n16f16 = reinterpret(N16f16, 0xaaaaaaaa)
414+
show(iob, n16f16)
415+
str = String(take!(iob))
416+
@test str == "43691.33333N16f16"
417+
@test eval(Meta.parse(str)) === n16f16
418+
419+
show(IOContext(iob, :compact=>true), n16f16)
420+
@test String(take!(iob)) == "43691.3"
421+
422+
show(IOContext(iob, :compact=>true, :typeinfo=>N16f16), n16f16)
423+
@test String(take!(iob)) == "43691.3"
424+
425+
show(IOContext(iob, :compact=>true, :typeinfo=>Normed), n16f16)
426+
@test String(take!(iob)) == "43691.3"
427+
428+
show(IOContext(iob, :typeinfo=>N16f16), n16f16)
429+
@test String(take!(iob)) == "43691.33333N16f16" # TODO: Consider removing suffix (issue #188)
430+
431+
show(IOContext(iob, :typeinfo=>Normed), n16f16)
432+
@test String(take!(iob)) == "43691.33333N16f16"
433+
434+
show(iob, Normed{UInt128,64}(1.2345e6))
435+
@test_broken String(take!(iob)) == "Normed{UInt128,64}(1.2345e6)" # "N64f64" is not defined
436+
end
437+
438+
@testset "summary" begin
439+
a = N0f8[0.2, 0.4]
440+
aa = Normed[0.2N0f8 0.4N0f16]
441+
442+
if VERSION >= v"1.6.0-DEV.356"
443+
@test_broken summary(a) == "2-element Vector{N0f8}"
444+
@test_broken summary(view(a, 1:2)) == "2-element view(::Vector{N0f8}, 1:2) with eltype N0f8"
445+
@test_broken summary(aa) == "1×2 Matrix{Normed}"
446+
else
447+
@test summary(a) == "2-element Array{N0f8,1} with eltype Normed{UInt8,8}"
448+
@test summary(view(a, 1:2)) == "2-element view(::Array{N0f8,1}, 1:2) with eltype Normed{UInt8,8}"
449+
@test_broken summary(aa) == "1×2 Array{Normed,2}"
450+
end
412451
end
413452

414453
@testset "scaledual" begin
@@ -478,12 +517,6 @@ end
478517
@test Float16(1.0) % N0f16 === N0f16(1.0)
479518
end
480519

481-
@testset "summary" begin
482-
a = N0f8[0.2, 0.4]
483-
@test summary(a) == "2-element Array{N0f8,1} with eltype Normed{UInt8,8}"
484-
@test summary(view(a, 1:2)) == "2-element view(::Array{N0f8,1}, 1:2) with eltype Normed{UInt8,8}"
485-
end
486-
487520
@testset "disambiguation constructors" begin
488521
@test_throws ArgumentError Normed{UInt32,16}('a')
489522
@test_throws InexactError Normed{UInt32,16}(complex(1.0, 1.0))

0 commit comments

Comments
 (0)