diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-19 04:13:17 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-19 04:13:17 +0000 |
| commit | 9ed14337db747542cc6bbf5b0247c9f01868c7a4 (patch) | |
| tree | c7764e05c7659ffbf1627bc504176918d6cc8755 /test/ruby | |
| parent | 09091d634b53ee92a1b2d2ddf8b7a1287ad08bbf (diff) | |
| download | ruby-9ed14337db747542cc6bbf5b0247c9f01868c7a4.tar.gz ruby-9ed14337db747542cc6bbf5b0247c9f01868c7a4.tar.xz ruby-9ed14337db747542cc6bbf5b0247c9f01868c7a4.zip | |
add test for center, ljust, rjust, chomp.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_m17n.rb | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 56550e298..124584199 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -970,6 +970,79 @@ class TestM17N < Test::Unit::TestCase } end + def test_str_center + assert_encoding("EUC-JP", "a".center(5, "\xa1\xa2".force_encoding("euc-jp")).encoding) + + combination(STRINGS, [0,1,2,3,10]) {|s1, width| + t = s1.center(width) + assert(a(t).index(a(s1))) + } + combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2| + if s2.empty? + assert_raise(ArgumentError) { s1.center(width, s2) } + next + end + if !is_ascii_only?(s1) && !is_ascii_only?(s2) && s1.encoding != s2.encoding + assert_raise(ArgumentError) { s1.center(width, s2) } + next + end + t = s1.center(width, s2) + assert(a(t).index(a(s1))) + assert_str_enc_propagation(t, s1, s2) if (t != s1) + } + end + + def test_str_ljust + combination(STRINGS, [0,1,2,3,10]) {|s1, width| + t = s1.ljust(width) + assert(a(t).index(a(s1))) + } + combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2| + if s2.empty? + assert_raise(ArgumentError) { s1.ljust(width, s2) } + next + end + if !is_ascii_only?(s1) && !is_ascii_only?(s2) && s1.encoding != s2.encoding + assert_raise(ArgumentError) { s1.ljust(width, s2) } + next + end + t = s1.ljust(width, s2) + assert(a(t).index(a(s1))) + assert_str_enc_propagation(t, s1, s2) if (t != s1) + } + end + + def test_str_rjust + combination(STRINGS, [0,1,2,3,10]) {|s1, width| + t = s1.rjust(width) + assert(a(t).index(a(s1))) + } + combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2| + if s2.empty? + assert_raise(ArgumentError) { s1.rjust(width, s2) } + next + end + if !is_ascii_only?(s1) && !is_ascii_only?(s2) && s1.encoding != s2.encoding + assert_raise(ArgumentError) { s1.rjust(width, s2) } + next + end + t = s1.rjust(width, s2) + assert(a(t).index(a(s1))) + assert_str_enc_propagation(t, s1, s2) if (t != s1) + } + end + + def test_chomp + combination(STRINGS, STRINGS) {|s1, s2| + if !is_ascii_only?(s1) && !is_ascii_only?(s2) && s1.encoding != s2.encoding + assert_raise(ArgumentError) { s1.chomp(s2) } + next + end + t = s1.chomp(s2) + assert_equal(s1.encoding, t.encoding) + } + end + def test_tr s = "\x81\x41".force_encoding("shift_jis") assert_equal(s.tr("A", "B"), s) |
