summaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-18 08:24:49 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-18 08:24:49 +0000
commitacf0203fbecb3edf0e5ec2f638836a05b9ce29cc (patch)
tree0395f1dbd574c3422177d2fbdc9f045608fb77f4 /test/ruby
parentc234dd19cc7dc6cfd7b0319c65f17bc3ab39510f (diff)
downloadruby-acf0203fbecb3edf0e5ec2f638836a05b9ce29cc.tar.gz
ruby-acf0203fbecb3edf0e5ec2f638836a05b9ce29cc.tar.xz
ruby-acf0203fbecb3edf0e5ec2f638836a05b9ce29cc.zip
* io.c (clear_readconv): extracted from rb_io_fptr_finalize.
(mode_enc): call clear_readconv. (io_set_encoding): ditto. (argf_next_argv): ditto. (io_encoding_set): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_io_m17n.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 7bcd051c3..e982722cf 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -552,5 +552,54 @@ EOT
}
}
end
+
+ def test_set_encoding
+ with_pipe("utf-8:euc-jp") {|r, w|
+ s = "\u3042".force_encoding("ascii-8bit")
+ s << "\x82\xa0".force_encoding("ascii-8bit")
+ w << s
+ w.close
+ assert_equal("\xa4\xa2".force_encoding("euc-jp"), r.getc)
+ r.set_encoding("shift_jis:euc-jp")
+ assert_equal("\xa4\xa2".force_encoding("euc-jp"), r.getc)
+ }
+ end
+
+ def test_set_encoding2
+ with_pipe("utf-8:euc-jp") {|r, w|
+ s = "\u3042".force_encoding("ascii-8bit")
+ s << "\x82\xa0".force_encoding("ascii-8bit")
+ w << s
+ w.close
+ assert_equal("\xa4\xa2".force_encoding("euc-jp"), r.getc)
+ r.set_encoding("shift_jis", "euc-jp")
+ assert_equal("\xa4\xa2".force_encoding("euc-jp"), r.getc)
+ }
+ end
+
+ def test_set_encoding_nil
+ with_pipe("utf-8:euc-jp") {|r, w|
+ s = "\u3042".force_encoding("ascii-8bit")
+ s << "\x82\xa0".force_encoding("ascii-8bit")
+ w << s
+ w.close
+ assert_equal("\xa4\xa2".force_encoding("euc-jp"), r.getc)
+ r.set_encoding(nil)
+ assert_equal("\x82\xa0".force_encoding(Encoding.default_external), r.read)
+ }
+ end
+
+ def test_set_encoding_enc
+ with_pipe("utf-8:euc-jp") {|r, w|
+ s = "\u3042".force_encoding("ascii-8bit")
+ s << "\x82\xa0".force_encoding("ascii-8bit")
+ w << s
+ w.close
+ assert_equal("\xa4\xa2".force_encoding("euc-jp"), r.getc)
+ r.set_encoding(Encoding::Shift_JIS)
+ assert_equal("\x82\xa0".force_encoding(Encoding::Shift_JIS), r.getc)
+ }
+ end
+
end