[前][次][番号順一覧][スレッド一覧]

ruby-changes:29740

From: knu <ko1@a...>
Date: Fri, 5 Jul 2013 16:07:39 +0900 (JST)
Subject: [ruby-changes:29740] knu:r41792 (trunk): * test/ruby/test_regexp.rb

knu	2013-07-05 16:07:28 +0900 (Fri, 05 Jul 2013)

  New Revision: 41792

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41792

  Log:
    * test/ruby/test_regexp.rb
      (TestRegexp#test_options_in_look_behind)
      (TestRegexp#assert_match_at): Add tests for another problem
      fixed in Onigmo 5.13.5.  Previously Onigmo did not allow option
      enclosures in look-behind, which makes it impossible to
      interpolate a regexp into another in the middle of a look-behind
      pattern.  cf. https://github.com/k-takata/Onigmo/pull/17

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_regexp.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41791)
+++ ChangeLog	(revision 41792)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul  5 16:01:21 2013  Akinori MUSHA  <knu@i...>
+
+	* test/ruby/test_regexp.rb
+	  (TestRegexp#test_options_in_look_behind)
+	  (TestRegexp#assert_match_at): Add tests for another problem
+	  fixed in Onigmo 5.13.5.  Previously Onigmo did not allow option
+	  enclosures in look-behind, which makes it impossible to
+	  interpolate a regexp into another in the middle of a look-behind
+	  pattern.  cf. https://github.com/k-takata/Onigmo/pull/17
+
 Fri Jul  5 12:14:40 2013  NAKAMURA Usaku  <usa@r...>
 
 	* test/ruby/test_rubyoptions.rb (TestRubyOptions#test_notfound): after
@@ -19,7 +29,6 @@ Fri Jul  5 11:08:00 2013  NAKAMURA Usaku https://github.com/ruby/ruby/blob/trunk/ChangeLog#L29
 	  test/webrick.
 
 Fri Jul  5 09:53:15 2013  NARUSE, Yui  <naruse@r...>
-
 	* lib/mkmf.rb (CONFIG['CPPOUTFILE']): fix r41769; CONFIG['CPPOUTFILE']
 	  may be nil.
 
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 41791)
+++ test/ruby/test_regexp.rb	(revision 41792)
@@ -944,6 +944,38 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L944
     assert_match_each(/\A((?<x>x)|(?<y>y))(?(<x>)y|x)\z/, conds, bug8583)
   end
 
+  def test_options_in_look_behind
+    assert_nothing_raised {
+      assert_match_at(/(?<=(?i)ab)cd/, "ABcd", [[2,4]])
+      assert_match_at(/(?<=(?i:ab))cd/, "ABcd", [[2,4]])
+      assert_match_at(/(?<!(?i)ab)cd/, "aacd", [[2,4]])
+      assert_match_at(/(?<!(?i:ab))cd/, "aacd", [[2,4]])
+
+      assert_not_match(/(?<=(?i)ab)cd/, "ABCD")
+      assert_not_match(/(?<=(?i:ab))cd/, "ABCD")
+      assert_not_match(/(?<!(?i)ab)cd/, "ABcd")
+      assert_not_match(/(?<!(?i:ab))cd/, "ABcd")
+    }
+  end
+
+  def assert_match_at(re, str, positions, msg = nil)
+    match = re.match(str)
+
+    assert_not_nil match, message(msg) {
+      "Expected #{re.inspect} to match #{str.inspect}"
+    }
+
+    if match
+      actual_positions = (0...match.size).map { |i|
+        [match.begin(i), match.end(i)]
+      }
+
+      assert_equal positions, actual_positions, message(msg) {
+        "Expected #{re.inspect} to match #{str.inspect} at: #{positions.inspect}"
+      }
+    end
+  end
+
   def assert_match_each(re, conds, msg = nil)
     errs = conds.select {|str, match| match ^ (re =~ str)}
     msg = message(msg) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]