summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 18:18:10 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 18:18:10 +0000
commitbe8eb4ee3c58928fd74fd3ff762ecd321823609c (patch)
tree3e678b124aaea7a5cfd319f47ff7214d8862b489 /test
parent2fa7f0784cf719030d7ac03bded06f67b4beb94d (diff)
downloadruby-be8eb4ee3c58928fd74fd3ff762ecd321823609c.tar.gz
ruby-be8eb4ee3c58928fd74fd3ff762ecd321823609c.tar.xz
ruby-be8eb4ee3c58928fd74fd3ff762ecd321823609c.zip
* include/ruby/io.h (rb_io_t): new fields: encs.ecopts and
writeconv_pre_ecopts. (MakeOpenFile): initialize them. * include/ruby/encoding.h (rb_str_transcode): take ecopts argument. (rb_econv_flags): removed. (rb_econv_prepare_opts): declared. (rb_econv_open_opts): declared. * io.c (make_writeconv): use rb_econv_open_opts. (make_readconv): ditto. (io_fwrite): follow rb_str_transcode change. (rb_io_extract_modeenc): use rb_econv_prepare_opts. (rb_file_open_generic): initialize encs.ecopts. (rb_file_open_internal): ditto. (rb_io_reopen): ditto. (argf_ecopts): defined. (argf_next_argv): set encs.ecopts. (io_encoding_set): use rb_econv_prepare_opts. (argf_set_encoding): set argf_ecopts. * gc.c (gc_mark_children): mark encs.ecopts and writeconv_pre_ecopts in T_FILE. * transcode.c (transcode_loop): take ecopts argument. use rb_econv_open_opts. (rb_econv_flags): removed. (rb_econv_prepare_opts): defined. (rb_econv_open_opts): defined. (str_transcode0): take ecopts. (str_transcode): use rb_econv_prepare_opts. (rb_str_transcode): take ecopts. (econv_init): accept hash argument. (econv_insert_output): follow rb_str_transcode change. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_econv.rb7
-rw-r--r--test/ruby/test_io_m17n.rb10
-rw-r--r--test/ruby/test_transcode.rb8
3 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb
index c898efee2..684406752 100644
--- a/test/ruby/test_econv.rb
+++ b/test/ruby/test_econv.rb
@@ -654,4 +654,11 @@ class TestEncodingConverter < Test::Unit::TestCase
ec.replacement = "<undef>"
assert_equal("a <undef> b", ec.convert("a \u3042 b"))
end
+
+ def test_econv_new_hash
+ ec = Encoding::Converter.new("utf-8", "us-ascii", :undef => :replace)
+ assert_equal("a ? b", ec.convert("a \u3042 b"))
+ ec = Encoding::Converter.new("utf-8", "us-ascii", :undef => :replace, :replace => "X")
+ assert_equal("a X b", ec.convert("a \u3042 b"))
+ end
end
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 90dd831dd..b8b532e94 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -239,6 +239,16 @@ EOT
w.close if w && !w.closed?
end
+ def test_s_pipe_undef_replace_string
+ r, w = IO.pipe("utf-8:euc-jp", :undef=>:replace, :replace=>"X")
+ w << "\ufffd"
+ w.close
+ assert_equal("X", r.read)
+ ensure
+ r.close if r && !r.closed?
+ w.close if w && !w.closed?
+ end
+
def test_dup
with_pipe("utf-8:euc-jp") {|r, w|
w << "\u3042"
diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb
index 81c58fd65..2bf8f04de 100644
--- a/test/ruby/test_transcode.rb
+++ b/test/ruby/test_transcode.rb
@@ -324,10 +324,18 @@ class TestTranscode < Test::Unit::TestCase
"\xA4\xA2\xFF\xFF\xA4\xA4".encode("ISO-2022-JP", "EUC-JP", invalid: :replace))
end
+ def test_invalid_replace_string
+ assert_equal("a<x>A", "a\x80A".encode("us-ascii", "euc-jp", :invalid=>:replace, :replace=>"<x>"))
+ end
+
def test_undef_replace
assert_equal("?", "\u20AC".encode("EUC-JP", :undef=>:replace), "[ruby-dev:35709]")
end
+ def test_undef_replace_string
+ assert_equal("a<x>A", "a\u3042A".encode("us-ascii", :undef=>:replace, :replace=>"<x>"))
+ end
+
def test_shift_jis
check_both_ways("\u3000", "\x81\x40", 'shift_jis') # full-width space
check_both_ways("\u00D7", "\x81\x7E", 'shift_jis') # ×