summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-23 18:22:59 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-23 18:22:59 +0000
commit6604434cd6456cd8958c66ca03929f94d1fd2ffb (patch)
tree2f89d0641f0922fd6d5cf8c2960583575bc72db0 /test
parent459ca7f3f01c72f001e9da484e8883ded0beeacc (diff)
add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_io_m17n.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 7e3dc2be94..ce35b4d210 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -54,6 +54,17 @@ EOT
}
end
+ def test_terminator_conversion2
+ with_tmpdir {
+ generate_file('tmp', "before \xA1\xA2\xA2\xA3 after")
+ s = open("tmp", "r:euc-jp:utf-8") {|f|
+ f.gets("\xA2\xA2".force_encoding("euc-jp").encode("utf-8"))
+ }
+ assert_equal(Encoding.find("euc-jp"), s.encoding)
+ assert_str_equal("before \xA1\xA2\xA2\xA3 after".force_encoding("iso-8859-1"), s)
+ }
+ end
+
def test_open_ascii
with_tmpdir {
src = "abc\n"
@@ -175,6 +186,37 @@ EOT
end
def test_pipe
+ utf8 = "\u6666"
+ eucjp = "\xb3\xa2".force_encoding("EUC-JP")
+
+ with_pipe {|r,w|
+ assert_equal(Encoding.default_external, r.external_encoding)
+ assert_equal(nil, r.internal_encoding)
+ w << utf8
+ w.close
+ s = r.read
+ assert_equal(Encoding.default_external, s.encoding)
+ puts encdump(s)
+ puts encdump(utf8)
+ assert_str_equal(utf8, s)
+ }
+
+ with_pipe("EUC-JP") {|r,w|
+ assert_equal(Encoding::EUC_JP, r.external_encoding)
+ assert_equal(nil, r.internal_encoding)
+ w << eucjp
+ w.close
+ assert_equal(eucjp, r.read)
+ }
+
+ with_pipe("UTF-8:EUC-JP") {|r,w|
+ assert_equal(Encoding::UTF_8, r.external_encoding)
+ assert_equal(Encoding::EUC_JP, r.internal_encoding)
+ w << utf8
+ w.close
+ assert_equal(eucjp, r.read)
+ }
+
ENCS.each {|enc|
with_pipe(enc) {|r, w|
w << "\xc2\xa1"