|
| 1 | +using DataTypesBasic |
| 2 | +using Test |
| 3 | + |
| 4 | +@test Try(4) == Identity(4) |
| 5 | +@test Try(ErrorException("hi")) == Const(ErrorException("hi")) |
| 6 | + |
| 7 | +@test istry(Identity(4)) |
| 8 | +@test istry(Const(ErrorException("hi"))) |
| 9 | +@test istry(@Try error("an error")) |
| 10 | +@test istry(@Try :value) |
| 11 | +@test istry(@TryCatch ErrorException error("an error")) |
| 12 | +@test istry(@TryCatch ErrorException :value) |
| 13 | + |
1 | 14 | @test issuccess(@Try 5) |
2 | 15 | @test !issuccess(@Try error("hi")) |
| 16 | +@test_throws MethodError issuccess(Const("other")) |
| 17 | + |
3 | 18 | @test isexception(@Try error("hi")) |
4 | 19 | @test !isexception(@Try 5) |
| 20 | +@test_throws MethodError isexception(Const("other")) |
5 | 21 |
|
6 | | -@test (@Try error("hi")) isa Const{<:Thrown} |
| 22 | +@test Thrown(ErrorException("one"), []) == Thrown(ErrorException("one"), []) |
| 23 | +@test repr(Thrown(ErrorException("some"), [])) == """Thrown(ErrorException("some"))""" |
7 | 24 |
|
8 | 25 |
|
| 26 | + |
| 27 | +@test (@Try error("hi")) isa Const{<:Thrown} |
| 28 | +@test (@TryCatch ErrorException error("hi")) isa Const{<:Thrown} |
| 29 | +@test_throws ArgumentError (@TryCatch ErrorException throw(ArgumentError("bad"))) |
| 30 | + |
9 | 31 | me = MultipleExceptions(ErrorException("hi")) |
10 | 32 | @test me.exceptions == (ErrorException("hi"),) |
11 | 33 | @test MultipleExceptions(me, ErrorException("ho")).exceptions == (ErrorException("hi"), ErrorException("ho")) |
12 | 34 |
|
| 35 | +e1 = Thrown(ErrorException("one"), []) |
| 36 | +e2 = AssertionError("error") |
| 37 | +@test merge(e1, e2) == MultipleExceptions(e1, e2) |
| 38 | +@test merge(e2, e1) == MultipleExceptions(e2, e1) |
| 39 | +@test merge(e1, e1) == MultipleExceptions(e1, e1) |
| 40 | +m12 = MultipleExceptions(e1, e2) |
| 41 | +@test merge(e2, m12) == MultipleExceptions(e2, e1, e2) |
| 42 | +@test merge(m12, e2) == MultipleExceptions(e1, e2, e2) |
| 43 | +@test merge(m12, m12) == MultipleExceptions(e1, e2, e1, e2) |
| 44 | + |
13 | 45 |
|
14 | 46 | @test eltype(Try{Int}) == Int |
15 | 47 | @test eltype(Identity{Int}) == Int |
16 | 48 | @test eltype(Thrown) == Any |
17 | 49 | @test eltype(Const{Thrown}) == Any |
| 50 | +@test eltype(Try) == Any |
0 commit comments