Skip to content

Commit a77e345

Browse files
committed
Add more _check_overflow tests
1 parent 838e138 commit a77e345

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

test/parse_tests.jl

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ const IntegerTypes = (SignedIntegerTypes..., UnsignedIntegerTypes...)
9191
end
9292
end
9393
end
94+
95+
@testset "$T" for T in UnsignedIntegerTypes
96+
@testset "$V" for V in (UInt64, UInt128, BigInt)
97+
@test !FixedPointDecimals._check_overflows(T, V(0), true)
98+
@test !FixedPointDecimals._check_overflows(T, V(0), false)
99+
@test !FixedPointDecimals._check_overflows(T, V(1), false)
100+
101+
if V === BigInt
102+
@test FixedPointDecimals._check_overflows(T, V(1), true)
103+
@test FixedPointDecimals._check_overflows(T, V(typemax(T) - 1), true)
104+
@test FixedPointDecimals._check_overflows(T, V(typemax(T)), true)
105+
@test FixedPointDecimals._check_overflows(T, V(V(typemax(T)) + 1), true)
106+
@test FixedPointDecimals._check_overflows(T, V(V(typemax(T)) + 2), true)
107+
end
108+
109+
if V === BigInt || typemax(T) == typemax(V)
110+
@test !FixedPointDecimals._check_overflows(T, V(typemax(T) - 1), false)
111+
@test !FixedPointDecimals._check_overflows(T, V(typemax(T)), false)
112+
end
113+
114+
if V === BigInt || typemax(T) < typemax(V)
115+
@test FixedPointDecimals._check_overflows(T, V(V(typemax(T)) + 1), false)
116+
@test FixedPointDecimals._check_overflows(T, V(V(typemax(T)) + 2), false)
117+
end
118+
119+
if V !== BigInt && typemax(T) > typemax(V)
120+
@test !FixedPointDecimals._check_overflows(T, typemax(V), false)
121+
end
122+
end
123+
end
94124
end
95125

96126
T = Int64
@@ -427,7 +457,6 @@ end
427457
end
428458
end # @testset "xparse"
429459

430-
431460
@testset "parse" begin
432461
# Note: the underscore used in the reinterpreted integer is used to indicate the decimal
433462
# place.
@@ -553,8 +582,7 @@ end # @testset "xparse"
553582
@test_throws ArgumentError parse(FD4, "1.2.3")
554583
@test_throws ArgumentError parse(FD4, "1.2", RoundUp)
555584
end
556-
end
557-
585+
end # @testset "parse"
558586

559587
@testset "tryparse" begin
560588
# Note: the underscore used in the reinterpreted integer is used to indicate the decimal
@@ -679,6 +707,6 @@ end
679707
@test isnothing(tryparse(FD4, "1.2e100"))
680708
@test isnothing(tryparse(FD4, "foo"))
681709
@test isnothing(tryparse(FD4, "1.2.3"))
682-
@test isnothing(tryparse(FD4, "1.2", RoundUp))
710+
@test_throws ArgumentError tryparse(FD4, "1.2", RoundUp)
683711
end
684-
end
712+
end # @testset "tryparse"

0 commit comments

Comments
 (0)