Skip to content

Commit f2be9f8

Browse files
authored
adjust exception type, add tests to increase code coverage (#1)
* test: add tests to increase code coverage * adjust exception type
1 parent 08ba374 commit f2be9f8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/FixFunctionArgument.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ module FixFunctionArgument
1717
@noinline function throw_too_few_args()
1818
throw(ArgumentError("too few positional arguments given in call of a `Fix`"))
1919
end
20+
@noinline function throw_not_int()
21+
throw(ArgumentError("the type parameter `N` must be an `Int`"))
22+
end
2023
@noinline function throw_not_positive()
2124
throw(ArgumentError("the type parameter `N` must be greater than zero"))
2225
end
23-
@inline function check_positive(n::Int)
26+
@inline function check_positive(n)
27+
if !(n isa Int)
28+
throw_not_int()
29+
end
30+
n = n::Int
2431
if n < 1
2532
throw_not_positive()
2633
end

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ using Test
1313
end
1414
@testset "basic" begin
1515
@test sin(0.3) === @inferred Fix1(sin, 0.3)()
16+
@test (7 - 3) === @inferred Fix1(-, 7)(3)
17+
@test (7 - 3) === @inferred Fix2(-, 3)(7)
18+
end
19+
@testset "invalid `N`" begin
20+
for N (-1, 0, true)
21+
@test_throws ArgumentError Fix{N}(+, 7)
22+
end
23+
end
24+
@testset "too few arguments in call" begin
25+
@test_throws ArgumentError Fix{10}(Returns(nothing), 7)(1, 2, 3)
1626
end
1727
end
1828

0 commit comments

Comments
 (0)