ruby-changes:29715
From: nobu <ko1@a...>
Date: Thu, 4 Jul 2013 13:32:42 +0900 (JST)
Subject: [ruby-changes:29715] nobu:r41767 (trunk): test_regexp.rb: test for conditional expression
nobu 2013-07-04 13:32:32 +0900 (Thu, 04 Jul 2013) New Revision: 41767 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41767 Log: test_regexp.rb: test for conditional expression * test/ruby/test_regexp.rb (TestRegexp#test_conditional_expression): test for [Bug #8583] Modified files: trunk/test/ruby/test_regexp.rb Index: test/ruby/test_regexp.rb =================================================================== --- test/ruby/test_regexp.rb (revision 41766) +++ test/ruby/test_regexp.rb (revision 41767) @@ -935,4 +935,21 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L935 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/