summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-26 12:55:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-26 12:55:14 +0000
commit19ab08653eb18b18507a9c4de09327c904387d7f (patch)
treefd6b1d4390aed665e22e0ba62661700d665a1be6 /test
parent18b097b73b49965bed5e37c6f53b2043e50103c8 (diff)
* transcode.c (rb_econv_open): disable newline conversion for ASCII
incompatible encodings. (str_transcode0): don't need disable newline conversion here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_io_m17n.rb49
1 files changed, 47 insertions, 2 deletions
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 47d04a18d5..2caa2cb2b8 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -1154,8 +1154,18 @@ EOT
}
end
+ SYSTEM_NEWLINE = []
def system_newline
- File::BINARY == 0 ? "\n" : "\r\n"
+ return SYSTEM_NEWLINE.first if !SYSTEM_NEWLINE.empty?
+ with_tmpdir {
+ open("newline", "wt") {|f|
+ f.print "\n"
+ }
+ open("newline", "rb") {|f|
+ SYSTEM_NEWLINE << f.read
+ }
+ }
+ SYSTEM_NEWLINE.first
end
def test_textmode_encode_newline
@@ -1170,6 +1180,41 @@ EOT
}
end
+ def test_textmode_encode_newline_enc
+ with_tmpdir {
+ open("t.txt", "wt:euc-jp") {|f|
+ f.puts "abc\u3042"
+ f.puts "def\u3044"
+ }
+ content = File.read("t.txt", :mode=>"rb:ascii-8bit")
+ nl = system_newline
+ assert_equal("abc\xA4\xA2#{nl}def\xA4\xA4#{nl}", content)
+ }
+ end
+
+ def test_textmode_read_ascii_incompat_internal
+ with_tmpdir {
+ generate_file("t.utf8.crlf", "a\r\nb\r\n")
+ open("t.utf8.crlf", "rt:utf-8:utf-16be") {|f|
+ content = f.read
+ # textmode doesn't affect for ascii incompatible internal encoding.
+ assert_equal("\0a\0\r\0\n\0b\0\r\0\n".force_encoding("UTF-16BE"),
+ content)
+ }
+ }
+ end
+
+ def test_textmode_write_ascii_incompat_internal
+ with_tmpdir {
+ open("t.utf8.lf", "wt:utf-8:utf-16be") {|f|
+ f.print "\0a\0\n\0b\0\n".force_encoding("UTF-16BE")
+ }
+ content = File.read("t.utf8.lf", :mode=>"rb:ascii-8bit")
+ # textmode doesn't affect for ascii incompatible internal encoding.
+ assert_equal("a\nb\n", content)
+ }
+ end
+
def test_binary
with_tmpdir {
src = "a\nb\rc\r\nd\n"
@@ -1180,7 +1225,7 @@ EOT
open("t.txt", "r", :binmode=>true) {|f|
assert_equal(src, f.read)
}
- if File::BINARY == 0
+ if system_newline == "\n"
open("t.txt", "r") {|f|
assert_equal(src, f.read)
}