Skip to content

Commit

Permalink
Fix AS::MB::Chars#+ to not alter self [#4646 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
jamesmacaulay authored and josevalim committed Jun 30, 2010
1 parent 13a3690 commit 16cef77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/multibyte/chars.rb
Expand Up @@ -105,7 +105,7 @@ def self.wants?(string)
# Example:
# ('Café'.mb_chars + ' périferôl').to_s #=> "Café périferôl"
def +(other)
self << other
chars(@wrapped_string + other)
end

# Like <tt>String#=~</tt> only it returns the character offset (in codepoints) instead of the byte offset.
Expand Down
16 changes: 9 additions & 7 deletions activesupport/test/multibyte_chars_test.rb
Expand Up @@ -49,13 +49,15 @@ def test_forwarded_method_with_non_string_result_should_be_returned_vertabim
end

def test_should_concatenate
assert_equal 'ab', 'a'.mb_chars + 'b'
assert_equal 'ab', 'a' + 'b'.mb_chars
assert_equal 'ab', 'a'.mb_chars + 'b'.mb_chars

assert_equal 'ab', 'a'.mb_chars << 'b'
assert_equal 'ab', 'a' << 'b'.mb_chars
assert_equal 'ab', 'a'.mb_chars << 'b'.mb_chars
mb_a = 'a'.mb_chars
mb_b = 'b'.mb_chars
assert_equal 'ab', mb_a + 'b'
assert_equal 'ab', 'a' + mb_b
assert_equal 'ab', mb_a + mb_b

assert_equal 'ab', mb_a << 'b'
assert_equal 'ab', 'a' << mb_b
assert_equal 'abb', mb_a << mb_b
end

def test_consumes_utf8_strings
Expand Down

0 comments on commit 16cef77

Please sign in to comment.