mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (io_extract_encoding_option): if internal encoding is not
specified, enc is external encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3f7bed0b80
commit
d34079b17a
3 changed files with 287 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Aug 21 19:05:40 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (io_extract_encoding_option): if internal encoding is not
|
||||
specified, enc is external encoding.
|
||||
|
||||
Thu Aug 21 14:22:50 2008 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* strftime.c: include ruby/config.h instead of ruby/ruby.h.
|
||||
|
|
5
io.c
5
io.c
|
@ -3782,9 +3782,12 @@ io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p)
|
|||
}
|
||||
else {
|
||||
*enc_p = intencoding;
|
||||
*enc2_p = extencoding;
|
||||
}
|
||||
}
|
||||
*enc2_p = extencoding;
|
||||
else {
|
||||
*enc_p = extencoding;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!NIL_P(intenc)) {
|
||||
|
|
|
@ -75,6 +75,26 @@ EOT
|
|||
}
|
||||
end
|
||||
|
||||
def test_open_r_enc_in_opt
|
||||
with_tmpdir {
|
||||
generate_file('tmp', "")
|
||||
open("tmp", "r", encoding: "euc-jp") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_r_enc_in_opt2
|
||||
with_tmpdir {
|
||||
generate_file('tmp', "")
|
||||
open("tmp", "r", external_encoding: "euc-jp") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_r_enc_enc
|
||||
with_tmpdir {
|
||||
generate_file('tmp', "")
|
||||
|
@ -85,6 +105,26 @@ EOT
|
|||
}
|
||||
end
|
||||
|
||||
def test_open_r_enc_enc_in_opt
|
||||
with_tmpdir {
|
||||
generate_file('tmp', "")
|
||||
open("tmp", "r", encoding: "euc-jp:utf-8") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(Encoding::UTF_8, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_r_enc_enc_in_opt2
|
||||
with_tmpdir {
|
||||
generate_file('tmp', "")
|
||||
open("tmp", "r", external_encoding: "euc-jp", internal_encoding: "utf-8") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(Encoding::UTF_8, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_w
|
||||
with_tmpdir {
|
||||
open("tmp", "w") {|f|
|
||||
|
@ -112,6 +152,24 @@ EOT
|
|||
}
|
||||
end
|
||||
|
||||
def test_open_w_enc_in_opt
|
||||
with_tmpdir {
|
||||
open("tmp", "w", encoding: "euc-jp") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_w_enc_in_opt2
|
||||
with_tmpdir {
|
||||
open("tmp", "w", external_encoding: "euc-jp") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_w_enc_enc
|
||||
with_tmpdir {
|
||||
open("tmp", "w:euc-jp:utf-8") {|f|
|
||||
|
@ -121,6 +179,24 @@ EOT
|
|||
}
|
||||
end
|
||||
|
||||
def test_open_w_enc_enc_in_opt
|
||||
with_tmpdir {
|
||||
open("tmp", "w", encoding: "euc-jp:utf-8") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(Encoding::UTF_8, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_w_enc_enc_in_opt2
|
||||
with_tmpdir {
|
||||
open("tmp", "w", external_encoding: "euc-jp", internal_encoding: "utf-8") {|f|
|
||||
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||
assert_equal(Encoding::UTF_8, f.internal_encoding)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_w_enc_enc_perm
|
||||
with_tmpdir {
|
||||
open("tmp", "w:euc-jp:utf-8", 0600) {|f|
|
||||
|
@ -512,7 +588,7 @@ EOT
|
|||
}
|
||||
end
|
||||
|
||||
def test_getc_invalid
|
||||
def test_getc_invalid2
|
||||
with_pipe("utf-8:euc-jp") {|r, w|
|
||||
before1 = "\u{3042}"
|
||||
before2 = "\u{3044}"
|
||||
|
@ -530,7 +606,7 @@ EOT
|
|||
}
|
||||
end
|
||||
|
||||
def test_getc_invalid2
|
||||
def test_getc_invalid3
|
||||
with_pipe("utf-16le:euc-jp") {|r, w|
|
||||
before1 = "\x42\x30".force_encoding("utf-16le")
|
||||
before2 = "\x44\x30".force_encoding("utf-16le")
|
||||
|
@ -690,5 +766,205 @@ EOT
|
|||
}
|
||||
end
|
||||
|
||||
def test_popen_r_enc
|
||||
IO.popen("#{EnvUtil.rubybin} -e 'putc 255'", "r:ascii-8bit") {|f|
|
||||
assert_equal(Encoding::ASCII_8BIT, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_popen_r_enc_in_opt
|
||||
IO.popen("#{EnvUtil.rubybin} -e 'putc 255'", "r", encoding: "ascii-8bit") {|f|
|
||||
assert_equal(Encoding::ASCII_8BIT, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_popen_r_enc_in_opt2
|
||||
IO.popen("#{EnvUtil.rubybin} -e 'putc 255'", "r", external_encoding: "ascii-8bit") {|f|
|
||||
assert_equal(Encoding::ASCII_8BIT, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_popen_r_enc_enc
|
||||
IO.popen("#{EnvUtil.rubybin} -e 'putc 0xa1'", "r:shift_jis:euc-jp") {|f|
|
||||
assert_equal(Encoding::Shift_JIS, f.external_encoding)
|
||||
assert_equal(Encoding::EUC_JP, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\x8e\xa1".force_encoding("euc-jp"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_popen_r_enc_enc_in_opt
|
||||
IO.popen("#{EnvUtil.rubybin} -e 'putc 0xa1'", "r", encoding: "shift_jis:euc-jp") {|f|
|
||||
assert_equal(Encoding::Shift_JIS, f.external_encoding)
|
||||
assert_equal(Encoding::EUC_JP, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\x8e\xa1".force_encoding("euc-jp"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_popen_r_enc_enc_in_opt2
|
||||
IO.popen("#{EnvUtil.rubybin} -e 'putc 0xa1'", "r", external_encoding: "shift_jis", internal_encoding: "euc-jp") {|f|
|
||||
assert_equal(Encoding::Shift_JIS, f.external_encoding)
|
||||
assert_equal(Encoding::EUC_JP, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\x8e\xa1".force_encoding("euc-jp"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_popenv_r_enc_enc_in_opt2
|
||||
IO.popen([EnvUtil.rubybin, "-e", "putc 0xa1"], "r", external_encoding: "shift_jis", internal_encoding: "euc-jp") {|f|
|
||||
assert_equal(Encoding::Shift_JIS, f.external_encoding)
|
||||
assert_equal(Encoding::EUC_JP, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\x8e\xa1".force_encoding("euc-jp"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_pipe_r_enc
|
||||
open("|#{EnvUtil.rubybin} -e 'putc 255'", "r:ascii-8bit") {|f|
|
||||
assert_equal(Encoding::ASCII_8BIT, f.external_encoding)
|
||||
assert_equal(nil, f.internal_encoding)
|
||||
s = f.read
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_enc
|
||||
with_tmpdir {
|
||||
generate_file("t", "\xff")
|
||||
IO.foreach("t", :mode => "r:ascii-8bit") {|s|
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_enc_in_opt
|
||||
with_tmpdir {
|
||||
generate_file("t", "\xff")
|
||||
IO.foreach("t", :encoding => "ascii-8bit") {|s|
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_enc_in_opt2
|
||||
with_tmpdir {
|
||||
generate_file("t", "\xff")
|
||||
IO.foreach("t", :external_encoding => "ascii-8bit") {|s|
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_enc_enc
|
||||
with_tmpdir {
|
||||
generate_file("t", "\u3042")
|
||||
IO.foreach("t", :mode => "r:utf-8:euc-jp") {|s|
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\xa4\xa2".force_encoding("euc-jp"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_enc_enc_in_opt
|
||||
with_tmpdir {
|
||||
generate_file("t", "\u3042")
|
||||
IO.foreach("t", :mode => "r", :encoding => "utf-8:euc-jp") {|s|
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\xa4\xa2".force_encoding("euc-jp"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_enc_enc_in_opt2
|
||||
with_tmpdir {
|
||||
generate_file("t", "\u3042")
|
||||
IO.foreach("t", :mode => "r", :external_encoding => "utf-8", :internal_encoding => "euc-jp") {|s|
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\xa4\xa2".force_encoding("euc-jp"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_open_args_enc
|
||||
with_tmpdir {
|
||||
generate_file("t", "\xff")
|
||||
IO.foreach("t", :open_args => ["r:ascii-8bit"]) {|s|
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_open_args_enc_in_opt
|
||||
with_tmpdir {
|
||||
generate_file("t", "\xff")
|
||||
IO.foreach("t", :open_args => ["r", encoding: "ascii-8bit"]) {|s|
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_open_args_enc_in_opt2
|
||||
with_tmpdir {
|
||||
generate_file("t", "\xff")
|
||||
IO.foreach("t", :open_args => ["r", external_encoding: "ascii-8bit"]) {|s|
|
||||
assert_equal(Encoding::ASCII_8BIT, s.encoding)
|
||||
assert_equal("\xff".force_encoding("ascii-8bit"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_open_args_enc_enc
|
||||
with_tmpdir {
|
||||
generate_file("t", "\u3042")
|
||||
IO.foreach("t", :open_args => ["r:utf-8:euc-jp"]) {|s|
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\xa4\xa2".force_encoding("euc-jp"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_open_args_enc_enc_in_opt
|
||||
with_tmpdir {
|
||||
generate_file("t", "\u3042")
|
||||
IO.foreach("t", :open_args => ["r", encoding: "utf-8:euc-jp"]) {|s|
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\xa4\xa2".force_encoding("euc-jp"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_s_foreach_open_args_enc_enc_in_opt2
|
||||
with_tmpdir {
|
||||
generate_file("t", "\u3042")
|
||||
IO.foreach("t", :open_args => ["r", external_encoding: "utf-8", internal_encoding: "euc-jp"]) {|s|
|
||||
assert_equal(Encoding::EUC_JP, s.encoding)
|
||||
assert_equal("\xa4\xa2".force_encoding("euc-jp"), s)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue