Skip to content

Commit

Permalink
Merge pull request #52 from kmsquire/feature/fix_range_matching
Browse files Browse the repository at this point in the history
Fix range matching
  • Loading branch information
kmsquire authored Sep 2, 2018
2 parents b13bdfc + f770d5b commit 9a0e042
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/matchutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ismatch
#

ismatch(r::AbstractRange, s::Number) = s in r
ismatch(r::AbstractRange, s) = s in r
ismatch(c::Char, s::Number) = false
ismatch(s::Number, c::Char) = false
ismatch(r::Regex, s::AbstractString) = occursin(r, s)
Expand Down
15 changes: 15 additions & 0 deletions test/matchtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,21 @@ end
@test num_match("hi") == "something else"
@test num_match('c') == "something else"

function char_match(c)
@match c begin
'A':'Z' => "uppercase"
'a':'z' => "lowercase"
'0':'9' => "number"
_ => "other"
end
end

@test char_match('M') == "uppercase"
@test char_match('n') == "lowercase"
@test char_match('8') == "number"
@test char_match(' ') == "other"
@test char_match("8") == "other"
@test char_match(8) == "other"

# Interpolation of matches in quoted expressions
test_interp(item) = @match item begin
Expand Down

0 comments on commit 9a0e042

Please sign in to comment.