1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Allow strings in assert_pattern_list

This commit is contained in:
Nobuyoshi Nakada 2022-08-18 23:42:53 +09:00
parent 8c44b07fa4
commit d903e76726
Notes: git 2022-08-19 01:28:54 +09:00
2 changed files with 14 additions and 4 deletions

View file

@ -548,11 +548,13 @@ eom
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
}
assert false, msg
end
rest = match.post_match
rest = post_match
anchored = true
end
}

View file

@ -35,6 +35,14 @@ class TestAssertion < Test::Unit::TestCase
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)