aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/multibyte_chars_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-10-20 16:05:26 -0600
committerSean Griffin <sean@seantheprogrammer.com>2015-10-20 16:05:26 -0600
commit61e65f606035778367cc52d7d0be190ff00e27ab (patch)
tree4651bcff93af8b47c56f25509125f1a6d5cbbeb3 /activesupport/test/multibyte_chars_test.rb
parent1193824994887fb37ca492d7c5eb1f381f2fc220 (diff)
parentb945de3662105abe330cad6e18962ccf7438150b (diff)
downloadrails-61e65f606035778367cc52d7d0be190ff00e27ab.tar.gz
rails-61e65f606035778367cc52d7d0be190ff00e27ab.tar.bz2
rails-61e65f606035778367cc52d7d0be190ff00e27ab.zip
Merge pull request #20737 from gouravtiwari/multibyte_chars_slice_fix
Fixed multibyte-chars slice! behavior to return nil for out-of-bound parameters
Diffstat (limited to 'activesupport/test/multibyte_chars_test.rb')
-rw-r--r--activesupport/test/multibyte_chars_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index e1c4b705f8..8d4d9d736c 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -413,12 +413,24 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase
assert_equal 'にち', @chars.slice!(1..2)
end
+ def test_slice_bang_returns_nil_on_out_of_bound_arguments
+ assert_equal nil, @chars.mb_chars.slice!(9..10)
+ end
+
def test_slice_bang_removes_the_slice_from_the_receiver
chars = 'úüù'.mb_chars
chars.slice!(0,2)
assert_equal 'ù', chars
end
+ def test_slice_bang_returns_nil_and_does_not_modify_receiver_if_out_of_bounds
+ string = 'úüù'
+ chars = string.mb_chars
+ assert_nil chars.slice!(4, 5)
+ assert_equal 'úüù', chars
+ assert_equal 'úüù', string
+ end
+
def test_slice_should_throw_exceptions_on_invalid_arguments
assert_raise(TypeError) { @chars.slice(2..3, 1) }
assert_raise(TypeError) { @chars.slice(1, 2..3) }