From 6f83a57ac7bf77565380b26b506972cfe751b717 Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Thu, 8 Jul 2010 17:42:14 -0300 Subject: Improve bang method defs, make slice! operate in-place. [#5028 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/multibyte_chars_test.rb | 41 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'activesupport/test/multibyte_chars_test.rb') diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 610295fa89..78232d8eb5 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -123,22 +123,30 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase assert_equal 'こに わ', @chars end - def test_overridden_bang_methods_return_self - [:rstrip!, :lstrip!, :strip!, :reverse!, :upcase!, :downcase!, :capitalize!].each do |method| - assert_equal @chars.object_id, @chars.send(method).object_id - end + %w{capitalize downcase lstrip reverse rstrip strip upcase}.each do |method| + class_eval(<<-EOTESTS) + def test_#{method}_bang_should_return_self + assert_equal @chars.object_id, @chars.send("#{method}!").object_id + end + + def test_#{method}_bang_should_change_wrapped_string + original = ' él piDió Un bUen café ' + proxy = chars(original.dup) + proxy.send("#{method}!") + assert_not_equal original, proxy.to_s + end + EOTESTS end - def test_overridden_bang_methods_change_wrapped_string - [:rstrip!, :lstrip!, :strip!, :reverse!, :upcase!, :downcase!].each do |method| - original = ' Café ' - proxy = chars(original.dup) - proxy.send(method) - assert_not_equal original, proxy.to_s - end - proxy = chars('òu') - proxy.capitalize! - assert_equal 'Òu', proxy.to_s + def test_tidy_bytes_bang_should_return_self + assert_equal @chars.object_id, @chars.tidy_bytes!.object_id + end + + def test_tidy_bytes_bang_should_change_wrapped_string + original = " Un bUen café \x92" + proxy = chars(original.dup) + proxy.tidy_bytes! + assert_not_equal original, proxy.to_s end if RUBY_VERSION >= '1.9' @@ -417,8 +425,9 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase end def test_slice_bang_removes_the_slice_from_the_receiver - @chars.slice!(1..2) - assert_equal 'こわ', @chars + chars = 'úüù'.mb_chars + chars.slice!(0,2) + assert_equal 'úü', chars end def test_slice_should_throw_exceptions_on_invalid_arguments -- cgit v1.2.3