Skip to content

Commit

Permalink
Allow strings in assert_pattern_list
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Aug 18, 2022
1 parent 8c44b07 commit d903e76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tool/lib/core_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,13 @@ def assert_pattern_list(pattern_list, actual, message=nil)
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
Expand All @@ -569,7 +571,7 @@ def assert_pattern_list(pattern_list, actual, message=nil)
}
assert false, msg
end
rest = match.post_match
rest = post_match
anchored = true
end
}
Expand Down
8 changes: 8 additions & 0 deletions tool/test/testunit/test_assertion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def test_assert_pattern_list
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)
Expand Down

0 comments on commit d903e76

Please sign in to comment.