Skip to content

Commit

Permalink
Tests for UTF-8 String#ljust and String#rjust
Browse files Browse the repository at this point in the history
  • Loading branch information
dabroz committed Feb 10, 2017
1 parent c802cd0 commit 24048cd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mrbgems/mruby-string-ext/test/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,47 @@ def o.to_str
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

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)
Expand Down

0 comments on commit 24048cd

Please sign in to comment.