Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Jul 7, 2017
1 parent 9aedbf2 commit fa0feb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ArgCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ end

iscomparison(ex) = false
function iscomparison(ex::Expr)
ex.head == :comparison && return true
# TODO
# support chains like 1 == 2 < 3
# ex.head == :comparison && return true
# Expr(:call, ≈, 1, 2) should also be a comparison.
if ex.head == :call && length(ex.args) == 3
op = ex.args[1]
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ import ArgCheck: iscomparison
@test iscomparison(:(f(2x) + 1 f(x)))
@test iscomparison(:(<(2,3)))
@test !iscomparison(:(f(1,1)))

@test_broken iscomparison_symbol(:(1 == 2 == 3))
end

@testset "Chained comparisons" begin
#6
x=y=z = 1
@test x == y == z
@argcheck x == y == z
z = 2
@test_throws ArgumentError @argcheck x == y == z

@test_throws ArgumentError @argcheck 1 2 == 2
@argcheck 1 == 1 1 < 2 > 1.2
@test_throws DimensionMismatch @argcheck 1 < 2 ==3 DimensionMismatch
end

@testset "@argcheck" begin
Expand Down

0 comments on commit fa0feb7

Please sign in to comment.