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

ruby-changes:72963

From: Nobuyoshi <ko1@a...>
Date: Fri, 19 Aug 2022 01:28:45 +0900 (JST)
Subject: [ruby-changes:72963] d903e76726 (master): Allow strings in assert_pattern_list

https://git.ruby-lang.org/ruby.git/commit/?id=d903e76726

From d903e7672637d5a834847820a4e18b00ee30f380 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 18 Aug 2022 23:42:53 +0900
Subject: Allow strings in assert_pattern_list

---
 tool/lib/core_assertions.rb          | 10 ++++++----
 tool/test/testunit/test_assertion.rb |  8 ++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb
index 67373139ca..321ca59f56 100644
--- a/tool/lib/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -548,11 +548,13 @@ eom https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L548
             anchored = false
           else
             if anchored
-              match = /\A#{pattern}/.match(rest)
+              match = rest.rindex(pattern, 0)
             else
-              match = pattern.match(rest)
+              match = rest.index(pattern)
             end
-            unless match
+            if match
+              post_match = $~ ? $~.post_match : rest[match+pattern.size..-1]
+            else
               msg = message(msg) {
                 expect_msg = "Expected #{mu_pp pattern}\n"
                 if /\n[^\n]/ =~ rest
@@ -569,7 +571,7 @@ eom https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L571
               }
               assert false, msg
             end
-            rest = match.post_match
+            rest = post_match
             anchored = true
           end
         }
diff --git a/tool/test/testunit/test_assertion.rb b/tool/test/testunit/test_assertion.rb
index d12a794a23..709b495572 100644
--- a/tool/test/testunit/test_assertion.rb
+++ b/tool/test/testunit/test_assertion.rb
@@ -35,6 +35,14 @@ class TestAssertion < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/tool/test/testunit/test_assertion.rb#L35
     assert_pattern_list([:*, /foo?/], "afoo")
     assert_not_pattern_list([:*, /foo?/], "afoo?")
     assert_pattern_list([/foo?/, :*], "foo?")
+
+    assert_not_pattern_list(["foo?"], "foo")
+    assert_not_pattern_list(["foo?"], "afoo")
+    assert_pattern_list(["foo?"], "foo?")
+    assert_not_pattern_list([:*, "foo?", :*], "foo")
+    assert_not_pattern_list([:*, "foo?"], "afoo")
+    assert_pattern_list([:*, "foo?"], "afoo?")
+    assert_pattern_list(["foo?", :*], "foo?")
   end
 
   def assert_not_pattern_list(pattern_list, actual, message=nil)
-- 
cgit v1.2.1


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

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