diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-15 03:27:37 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-15 03:27:37 +0000 |
commit | 2386407223a5074a25e1a3827ed2e1be81ec3a40 (patch) | |
tree | 2b943b0b61adc2d4dcae96ef0cd357761e10777d /test/ruby/envutil.rb | |
parent | 7643c2b37d84b73250626587a912ecacc0d4d4fe (diff) |
* test/ruby/envutil.rb (assert_regexp_list): New assertion method.
* test/ruby/test_rubyoptions.rb: Use assert_regexp_list.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/envutil.rb')
-rw-r--r-- | test/ruby/envutil.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index 81b982cc70..ab07289876 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -477,6 +477,36 @@ eom AssertFile end + # pattern_list is an array which contains regexp and :*. + # :* means any sequence. + # + # pattern_list is anchored. + # Use [:*, regexp, :*] for non-anchored match. + def assert_regexp_list(pattern_list, actual, message=nil) + rest = actual + anchored = true + pattern_list.each {|pattern| + if pattern == :* + anchored = false + else + if anchored + match = /\A#{pattern}/.match(rest) + else + match = pattern.match(rest) + end + unless match + msg = message(msg) { "Expected #{mu_pp pattern}\nto match #{mu_pp rest}" } + assert false, msg + end + rest = match.post_match + anchored = true + end + } + if anchored + assert_equal("", rest) + end + end + class << (AssertFile = Struct.new(:failure_message).new) include Assertions def assert_file_predicate(predicate, *args) |