summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-string-ext/test/string.rb
diff options
context:
space:
mode:
authorTomasz Dabrowski <[email protected]>2017-02-10 12:58:41 +0100
committerTomasz Dabrowski <[email protected]>2017-02-10 12:59:28 +0100
commit981105b3e6758455646e9834b1c2695bf774a401 (patch)
treed8d5fbeeecb1af277c3060074619ec9d7c4229fd /mrbgems/mruby-string-ext/test/string.rb
parentd0ecf862d9d2e7aed461bc9360686449f56c5d25 (diff)
downloadmruby-981105b3e6758455646e9834b1c2695bf774a401.tar.gz
mruby-981105b3e6758455646e9834b1c2695bf774a401.zip
String#ljust and String#rjust reimplementation (fix #3445)
- String#ljust and String#rjust are now C functions to improve performance - infinite loop because of an empty padding argument is now prevented (ArgumentError is raised) - extra tests for ljust/rjust added
Diffstat (limited to 'mrbgems/mruby-string-ext/test/string.rb')
-rw-r--r--mrbgems/mruby-string-ext/test/string.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb
index 228a236af..2b2c02b8b 100644
--- a/mrbgems/mruby-string-ext/test/string.rb
+++ b/mrbgems/mruby-string-ext/test/string.rb
@@ -444,6 +444,26 @@ assert('String#rjust') do
assert_equal "hello", "hello".rjust(-3)
end
+assert('String#ljust should not change string') do
+ a = "hello"
+ a.ljust(20)
+ assert_equal "hello", a
+end
+
+assert('String#rjust should not change string') do
+ a = "hello"
+ a.rjust(20)
+ assert_equal "hello", a
+end
+
+assert('String#ljust should raise on zero width padding') do
+ assert_raise(ArgumentError) { "foo".ljust(10, '') }
+end
+
+assert('String#rjust should raise on zero width padding') do
+ assert_raise(ArgumentError) { "foo".rjust(10, '') }
+end
+
assert('String#upto') do
a = "aa"
start = "aa"