summaryrefslogtreecommitdiff
path: root/test/ruby/test_m17n.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_m17n.rb')
-rw-r--r--test/ruby/test_m17n.rb36
1 files changed, 32 insertions, 4 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index e5f9f8585f6..a09dcc8f3b7 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -877,6 +877,9 @@ class TestM17N < Test::Unit::TestCase
}
assert_equal(e("\xA1\xA1"), a("a").tr(a("a"), e("\xA1\xA1")))
+
+ assert_equal("X\u3042\u3044X", "A\u3042\u3044\u3046".tr("^\u3042\u3044", "X"))
+ assert_equal("\u3042\u3046" * 100, ("\u3042\u3044" * 100).tr("\u3044", "\u3046"))
end
def test_tr_s
@@ -968,6 +971,12 @@ class TestM17N < Test::Unit::TestCase
assert_equal(u("\xf0jihgfedcba"), u("abcdefghij\xf0").reverse)
end
+ def test_reverse_bang
+ s = u("abcdefghij\xf0")
+ s.reverse!
+ assert_equal(u("\xf0jihgfedcba"), s)
+ end
+
def test_plus
assert_raise(ArgumentError){u("\xe3\x81\x82") + a("\xa1")}
end
@@ -1201,8 +1210,27 @@ class TestM17N < Test::Unit::TestCase
assert_equal(true, (s.dup << s).valid_encoding?)
assert_equal(true, "".center(2, s).valid_encoding?)
- s = "\xa1\xa1\x8f".force_encoding("euc-jp")
- assert_equal(false, s.valid_encoding?)
- assert_equal(true, s.reverse.valid_encoding?)
- end
+ s = "\xa1\xa1\x8f".force_encoding("euc-jp")
+ assert_equal(false, s.valid_encoding?)
+ assert_equal(true, s.reverse.valid_encoding?)
+ end
+
+ def test_getbyte
+ assert_equal(0x82, u("\xE3\x81\x82\xE3\x81\x84").getbyte(2))
+ assert_equal(0x82, u("\xE3\x81\x82\xE3\x81\x84").getbyte(-4))
+ assert_nil(u("\xE3\x81\x82\xE3\x81\x84").getbyte(100))
+ end
+
+ def test_setbyte
+ s = u("\xE3\x81\x82\xE3\x81\x84")
+ s.setbyte(2, 0x84)
+ assert_equal(u("\xE3\x81\x84\xE3\x81\x84"), s)
+
+ s = u("\xE3\x81\x82\xE3\x81\x84")
+ assert_raise(IndexError) { s.setbyte(100, 0) }
+
+ s = u("\xE3\x81\x82\xE3\x81\x84")
+ s.setbyte(-4, 0x84)
+ assert_equal(u("\xE3\x81\x84\xE3\x81\x84"), s)
+ end
end