|
12 | 12 | x::Int |
13 | 13 | path::String |
14 | 14 | vec::Vector{Float64} |
| 15 | + a::Float32 |
| 16 | + b::Float32 |
| 17 | + c::Float64 |
| 18 | + d::Float64 |
15 | 19 | end |
16 | | - Base.show(io::IO, ::MIME"text/plain", a::A) = print(io, "Object with Int($(a.x)), $(a.path) and $(a.vec)") |
17 | | - a = A(1, "/usr/bin/bash", [1.0, π, 7.5, √2]) |
18 | | - @test parse_show(a) ≈ "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]" |
19 | | - @test "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]" ≈ parse_show(a) |
20 | | - @test parse_show("Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]") ≈ parse_show(a) |
21 | | - @test_throws AssertionError parse_show(a) ≈ "Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]" |
22 | | - @test !isapprox(parse_show(a), "Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]"; assertion_error=false) |
| 20 | + Base.show(io::IO, ::MIME"text/plain", a::A) = |
| 21 | + print(io, """ |
| 22 | + Object with Int($(a.x)), $(a.path) and $(a.vec) vector. |
| 23 | + a, b, c, d = $(a.a), $(a.b), $(a.c), $(a.d) |
| 24 | + """) |
| 25 | + a = A(1, "/usr/bin/bash", [1.0, π, 7.5, √2], 1.3f-17, 2.6f17, 1.3e-17, 2.6f17) |
| 26 | + @test parse_show(a) ≈ """ |
| 27 | + Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951] vector. |
| 28 | + a, b, c, d = 1.3e-17, 2.6e17, 1.3e-17, 2.6000000279170253e17 |
| 29 | + """ |
| 30 | + @test """ |
| 31 | + Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951] vector. |
| 32 | + a, b, c, d = 1.3e-17, 2.6e17, 1.3e-17, 2.6000000279170253e17 |
| 33 | + """ ≈ parse_show(a) |
| 34 | + @test parse_show(""" |
| 35 | + Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951] vector. |
| 36 | + a, b, c, d = 1.3e-17, 2.6e17, 1.3e-17, 2.6000000279170253e17 |
| 37 | + """) ≈ parse_show(a) |
| 38 | + @test_throws "comparison failed" parse_show(a) ≈ "Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]" |
| 39 | + # do not throw error with assertion_error == false |
| 40 | + @test !isapprox(parse_show(a), """ |
| 41 | + Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]" |
| 42 | + """; assertion_error=false) |
23 | 43 | # Test show method |
24 | 44 | @test contains(repr("text/plain", parse_show(a)), "Object with Int( 1 )") |
25 | | - @test parse_show([a, a, a, a]; repl=["/usr/bin/bash" => "", r"^((?:[^\n]*\n){3}).*"s => s"\1"]) ≈ """ |
26 | | - 4 -element Vector{A}: |
27 | | - Object with Int( 1 ), and [ 1.0 1.4142135623730951 ] |
28 | | - Object with Int( 1 ), and [ 1.0 1.4142135623730951 ] |
| 45 | + # Test custom multiple substitions (keep only first 3 lines) |
| 46 | + @test parse_show([a, a, a, a]; repl=["/usr/bin/bash" => "", r"^((?:[^\n]*\n){3}).*"s => s"\1"], vector_simplify=false) ≈ """ |
| 47 | + 4-element Vector{A}: |
| 48 | + A(1, "/usr/bin/bash", [1.0, 3.141592653589793, 7.5, 1.4142135623730951], 1.3f-17, 2.6f17, 1.3e-17, 2.6000000279170253e17) |
| 49 | + A(1, "/usr/bin/bash", [1.0, 3.141592653589793, 7.5, 1.4142135623730951], 1.3f-17, 2.6f17, 1.3e-17, 2.6000000279170253e17) |
29 | 50 | """ |
30 | 51 | @test_throws ArgumentError parse_show([a, a, a, a]; repl=["a", "b"]) |
31 | 52 | # compact printing |
|
0 commit comments