Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/FixFunctionArgument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ module FixFunctionArgument
@noinline function throw_too_few_args()
throw(ArgumentError("too few positional arguments given in call of a `Fix`"))
end
@noinline function throw_not_int()
throw(ArgumentError("the type parameter `N` must be an `Int`"))
end
@noinline function throw_not_positive()
throw(ArgumentError("the type parameter `N` must be greater than zero"))
end
@inline function check_positive(n::Int)
@inline function check_positive(n)
if !(n isa Int)
throw_not_int()
end
n = n::Int
if n < 1
throw_not_positive()
end
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ using Test
end
@testset "basic" begin
@test sin(0.3) === @inferred Fix1(sin, 0.3)()
@test (7 - 3) === @inferred Fix1(-, 7)(3)
@test (7 - 3) === @inferred Fix2(-, 3)(7)
end
@testset "invalid `N`" begin
for N ∈ (-1, 0, true)
@test_throws ArgumentError Fix{N}(+, 7)
end
end
@testset "too few arguments in call" begin
@test_throws ArgumentError Fix{10}(Returns(nothing), 7)(1, 2, 3)
end
end

Expand Down