From e7e4d03a6eec1d25ccbfb5a72cc5e4049f89961d Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 19 Dec 2007 09:56:14 +0000 Subject: add tests for insert, intern, length, oct, replace, reverse. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_m17n.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 3d4941f47a..a838341b22 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -836,7 +836,7 @@ class TestM17N < Test::Unit::TestCase end def test_str_assign_len - combination(STRINGS, STRINGS, -2..2, 0..2) {|s1, s2, i, len| + combination(STRINGS, -2..2, 0..2, STRINGS) {|s1, i, len, s2| t = s1.dup if is_ascii_only?(s1) || is_ascii_only?(s2) || s1.encoding == s2.encoding if i < -s1.length || s1.length < i @@ -1302,6 +1302,67 @@ class TestM17N < Test::Unit::TestCase } end + def test_str_insert + combination(STRINGS, -2..2, STRINGS) {|s1, nth, s2| + t1 = s1.dup + t2 = s1.dup + begin + t1[nth, 0] = s2 + rescue ArgumentError, IndexError => e1 + end + begin + t2.insert(nth, s2) + rescue ArgumentError, IndexError => e2 + end + assert_equal(t1, t2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t") + assert_equal(e1.class, e2.class, "begin #{encdump s1}.insert(#{nth},#{encdump s2}); rescue ArgumentError, IndexError => e; e end") + } + end + + def test_str_intern + STRINGS.each {|s| + if /\0/ =~ a(s) + assert_raise(ArgumentError) { s.intern } + else + sym = s.intern + assert_equal(s, sym.to_s) + end + } + end + + def test_str_length + STRINGS.each {|s| + assert_operator(s.length, :<=, s.bytesize) + } + end + + def test_str_oct + STRINGS.each {|s| + t = s.oct + t2 = a(s)[/\A[0-9a-fA-FxXbB]*/].oct + assert_equal(t2, t) + } + end + + def test_str_replace + combination(STRINGS, STRINGS) {|s1, s2| + t = s1.dup + t.replace s2 + assert_equal(s2, t) + assert_equal(s2.encoding, t.encoding) + } + end + + def test_str_reverse + STRINGS.each {|s| + t = s.reverse + assert_equal(s.bytesize, t.bytesize) + if s.valid_encoding? + assert_equal(s, t.reverse) + end + } + end + def test_tr s = "\x81\x41".force_encoding("shift_jis") assert_equal(s.tr("A", "B"), s) -- cgit v1.2.3