summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-04 04:32:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-04 04:32:32 +0000
commitc294ed5824f3e42e1bfb0c71b571f4992a8eb6e4 (patch)
tree1b2b7c0dd003bf267b5c50e92ce81d5cd223557e
parentfa7e514642de951cfe85e36ff65af669a7f482e1 (diff)
test_regexp.rb: test for conditional expression
* test/ruby/test_regexp.rb (TestRegexp#test_conditional_expression): test for [Bug #8583] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_regexp.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index a91ae8b79f..f13a900634 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -935,4 +935,21 @@ class TestRegexp < Test::Unit::TestCase
err = assert_raise(TypeError){ Regexp.quote(42) }
assert_equal 'no implicit conversion of Fixnum into String', err.message, bug7539
end
+
+ def test_conditional_expression
+ bug8583 = '[ruby-dev:47480] [Bug #8583]'
+
+ conds = {"xy"=>true, "yx"=>true, "xx"=>false, "yy"=>false}
+ assert_match_each(/\A((x)|(y))(?(2)y|x)\z/, conds, bug8583)
+ assert_match_each(/\A((?<x>x)|(?<y>y))(?(<x>)y|x)\z/, conds, bug8583)
+ end
+
+ def assert_match_each(re, conds, msg = nil)
+ errs = conds.select {|str, match| match ^ (re =~ str)}
+ msg = message(msg) {
+ "Expected #{re.inspect} to\n" +
+ errs.map {|str, match| "\t#{'not ' unless match}match #{str.inspect}"}.join(",\n")
+ }
+ assert(errs.empty?, msg)
+ end
end