Fix AS::MB::Chars#+ to not alter self [#4646 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
James MacAulay 2010-05-18 15:19:53 -04:00 committed by José Valim
parent 13a3690271
commit 16cef77d37
2 changed files with 9 additions and 7 deletions

@ -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.

@ -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
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', 'a'.mb_chars << 'b'
assert_equal 'ab', 'a' << 'b'.mb_chars
assert_equal 'ab', 'a'.mb_chars << 'b'.mb_chars
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