ruby-changes:2823
From: ko1@a...
Date: 19 Dec 2007 13:15:59 +0900
Subject: [ruby-changes:2823] akr - Ruby:r14314 (trunk): add test for center, ljust, rjust, chomp.
akr 2007-12-19 13:13:17 +0900 (Wed, 19 Dec 2007) New Revision: 14314 Modified files: trunk/test/ruby/test_m17n.rb Log: add test for center, ljust, rjust, chomp. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_m17n.rb?r1=14314&r2=14313 Index: test/ruby/test_m17n.rb =================================================================== --- test/ruby/test_m17n.rb (revision 14313) +++ test/ruby/test_m17n.rb (revision 14314) @@ -970,6 +970,79 @@ } 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml