aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/multibyte_chars_test.rb
diff options
context:
space:
mode:
authorNorman Clarke <norman@njclarke.com>2010-07-08 17:42:14 -0300
committerJosé Valim <jose.valim@gmail.com>2010-07-08 22:59:24 +0200
commit6f83a57ac7bf77565380b26b506972cfe751b717 (patch)
treeed2b4779d2c1d4c0895c060fd265c8da3e7cb22a /activesupport/test/multibyte_chars_test.rb
parent01629d180468049d17a8be6900e27a4f0d2b18c4 (diff)
downloadrails-6f83a57ac7bf77565380b26b506972cfe751b717.tar.gz
rails-6f83a57ac7bf77565380b26b506972cfe751b717.tar.bz2
rails-6f83a57ac7bf77565380b26b506972cfe751b717.zip
Improve bang method defs, make slice! operate in-place. [#5028 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/test/multibyte_chars_test.rb')
-rw-r--r--activesupport/test/multibyte_chars_test.rb41
1 files changed, 25 insertions, 16 deletions
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