Permalink
Browse files

Raise NoMatchingPatternError if no pattern matches

  • Loading branch information...
1 parent 8163994 commit 6a4f26c22d3da6ca79b2ad7c6912e5f93d5e97a4 @k-tsj committed Mar 24, 2012
Showing with 8 additions and 5 deletions.
  1. +2 −0 lib/pattern-match.rb
  2. +6 −5 test/test_pattern-match.rb
View
@@ -480,6 +480,7 @@ def tmpbinding_module(obj)
class PatternNotMatch < Exception; end
class PatternMatchError < StandardError; end
+ class NoMatchingPatternError < PatternMatchError; end
class MalformedPatternError < PatternMatchError; end
end
@@ -498,6 +499,7 @@ def call_refined_method(obj, name, *args)
end
catch(:exit_match) do
env.instance_eval(&block)
+ raise ::PatternMatch::NoMatchingPatternError
end
end
case vals.length
View
@@ -19,11 +19,12 @@ def test_basic
assert_raise(NameError) { a }
assert_raise(NameError) { b }
- ret = match(0) {
- with(1) { flunk }
- with(2) { flunk }
+ assert_raise(PatternMatch::NoMatchingPatternError) {
+ match(0) {
+ with(1) { flunk }
+ with(2) { flunk }
+ }
}
- assert_nil(ret)
match(0) {
with(i, guard { i.odd? }) { flunk }
@@ -296,7 +297,7 @@ def test_and_or_not
end
def test_match_without_argument
- assert_equal(1, 2.times.find(&match { with(1) { true } }))
+ assert_equal(1, 2.times.find(&match { with(1) { true }; with(_) { false } }))
end
def test_extractor_class

0 comments on commit 6a4f26c

Please sign in to comment.