summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-02-11 10:26:09 +0900
committerGitHub <[email protected]>2017-02-11 10:26:09 +0900
commitb36495bcb5a4f30144bc27c38167d02907ca8dc7 (patch)
tree9a97ca0f35e20c5cc7109c16601f89c44a2a7c69 /mrbgems/mruby-string-ext/test
parentc802cd07baf7132c5053defac883f0ee6b7967b7 (diff)
parentd1bc7caecaf337976351934d5910726106601bd9 (diff)
downloadmruby-b36495bcb5a4f30144bc27c38167d02907ca8dc7.tar.gz
mruby-b36495bcb5a4f30144bc27c38167d02907ca8dc7.zip
Merge pull request #3449 from dabroz/fix-ljust-ruby
String#ljust and String#rjust reimplemented with optimized Ruby
Diffstat (limited to 'mrbgems/mruby-string-ext/test')
-rw-r--r--mrbgems/mruby-string-ext/test/string.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb
index 2b2c02b8b..996ad2669 100644
--- a/mrbgems/mruby-string-ext/test/string.rb
+++ b/mrbgems/mruby-string-ext/test/string.rb
@@ -433,6 +433,7 @@ end
assert('String#ljust') do
assert_equal "hello", "hello".ljust(4)
assert_equal "hello ", "hello".ljust(20)
+ assert_equal 20, "hello".ljust(20).length
assert_equal "hello123412341234123", "hello".ljust(20, '1234')
assert_equal "hello", "hello".ljust(-3)
end
@@ -440,10 +441,39 @@ end
assert('String#rjust') do
assert_equal "hello", "hello".rjust(4)
assert_equal " hello", "hello".rjust(20)
+ assert_equal 20, "hello".rjust(20).length
assert_equal "123412341234123hello", "hello".rjust(20, '1234')
assert_equal "hello", "hello".rjust(-3)
end
+if UTF8STRING
+ assert('String#ljust with UTF8') do
+ assert_equal "helloん ", "helloん".ljust(20)
+ assert_equal "helloó ", "helloó".ljust(34)
+ assert_equal 34, "helloó".ljust(34).length
+ assert_equal "helloんんんんんんんんんんんんんん", "hello".ljust(19, 'ん')
+ assert_equal "helloんんんんんんんんんんんんんんん", "hello".ljust(20, 'ん')
+ end
+
+ assert('String#rjust with UTF8') do
+ assert_equal " helloん", "helloん".rjust(20)
+ assert_equal " helloó", "helloó".rjust(34)
+ # assert_equal 34, "helloó".rjust(34).length
+ assert_equal "んんんんんんんんんんんんんんhello", "hello".rjust(19, 'ん')
+ assert_equal "んんんんんんんんんんんんんんんhello", "hello".rjust(20, 'ん')
+ end
+
+ assert('UTF8 byte counting') do
+ skip('string length is broken after []=')
+
+ # based on assert_equal 34, "helloó".rjust(34).length
+ ret = ' '
+ ret[-6..-1] = "helloó"
+
+ assert_equal 34, ret.length
+ end
+end
+
assert('String#ljust should not change string') do
a = "hello"
a.ljust(20)