diff options
author | Xavier Noria <fxn@hashref.com> | 2016-07-21 23:41:03 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-07-22 00:15:52 +0200 |
commit | 575dbeeefcaafeb566afc07cdd8b55603b698d9f (patch) | |
tree | 8371e5e85e11f242c0fbb6fb42fb63b5edac6fa4 /activesupport/test | |
parent | d4ea18a8cb84601509ee4c6dc691b212af8c2c36 (diff) | |
download | rails-575dbeeefcaafeb566afc07cdd8b55603b698d9f.tar.gz rails-575dbeeefcaafeb566afc07cdd8b55603b698d9f.tar.bz2 rails-575dbeeefcaafeb566afc07cdd8b55603b698d9f.zip |
define Range#match? if Ruby < 2.4
See the rationale in the documentation included in this patch.
We are going to gradually introduce this predicate in the code base.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/regexp_ext_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/regexp_ext_test.rb b/activesupport/test/core_ext/regexp_ext_test.rb index c2398d31bd..d91e363085 100644 --- a/activesupport/test/core_ext/regexp_ext_test.rb +++ b/activesupport/test/core_ext/regexp_ext_test.rb @@ -7,4 +7,28 @@ class RegexpExtAccessTests < ActiveSupport::TestCase assert_equal false, //.multiline? assert_equal false, /(?m:)/.multiline? end + + # Based on https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb. + def test_match_p + /back(...)/ =~ 'backref' + # must match here, but not in a separate method, e.g., assert_send, + # to check if $~ is affected or not. + assert_equal false, //.match?(nil) + assert_equal true, //.match?("") + assert_equal true, /.../.match?(:abc) + assert_raise(TypeError) { /.../.match?(Object.new) } + assert_equal true, /b/.match?('abc') + assert_equal true, /b/.match?('abc', 1) + assert_equal true, /../.match?('abc', 1) + assert_equal true, /../.match?('abc', -2) + assert_equal false, /../.match?("abc", -4) + assert_equal false, /../.match?("abc", 4) + assert_equal true, /\z/.match?("") + assert_equal true, /\z/.match?("abc") + assert_equal true, /R.../.match?("Ruby") + assert_equal false, /R.../.match?("Ruby", 1) + assert_equal false, /P.../.match?("Ruby") + assert_equal 'backref', $& + assert_equal 'ref', $1 + end end |