File: regexp_ext_test.rb

package info (click to toggle)
rails 2%3A5.2.2.1%2Bdfsg-1%2Bdeb10u3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 33,200 kB
  • sloc: ruby: 235,858; javascript: 20,695; yacc: 46; sql: 43; makefile: 22; sh: 14
file content (36 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require "abstract_unit"
require "active_support/core_ext/regexp"

class RegexpExtAccessTests < ActiveSupport::TestCase
  def test_multiline
    assert_equal true, //m.multiline?
    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