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

Add AS::Multibyte::Chars#match?

This commit is contained in:
Akira Matsuda 2019-07-29 13:33:03 +09:00
parent d55dea5ef1
commit 381e8cb67a
2 changed files with 7 additions and 1 deletions

View file

@ -48,7 +48,7 @@ module ActiveSupport #:nodoc:
alias to_s wrapped_string
alias to_str wrapped_string
delegate :<=>, :=~, :acts_like_string?, to: :wrapped_string
delegate :<=>, :=~, :match?, :acts_like_string?, to: :wrapped_string
# Creates a new Chars instance by wrapping _string_.
def initialize(string)

View file

@ -204,6 +204,12 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase
assert_equal 3, (@chars =~ //u)
end
def test_match_should_return_boolean_for_regexp_match
assert_not @chars.match?(/wrong/u)
assert @chars.match?(/こに/u)
assert @chars.match?(//u)
end
def test_should_use_character_offsets_for_insert_offsets
assert_equal "", (+"").mb_chars.insert(0, "")
assert_equal "こわにちわ", @chars.insert(1, "")