summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-19 09:56:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-19 09:56:14 +0000
commite7e4d03a6eec1d25ccbfb5a72cc5e4049f89961d (patch)
treec460b0592f7b6eac720d9e163e963d4a20a7c25f /test
parent4aa72e7fe370d1832c52b43d56e147b3e9f64b99 (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_m17n.rb63
1 files changed, 62 insertions, 1 deletions
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)