summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-15 14:17:11 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-15 14:17:11 +0000
commit3a427c61997b513939841dfa1f7b124e9facf6d3 (patch)
tree6e219f06979ebe9f8665b9d5f5cf212f3f62f27f /test
parentfe091e89b73c62fd3940ff4ca9214e3935de257c (diff)
* transcode.c (econv_just_convert): extracted from rb_econv_output.
(rb_econv_output): use econv_just_convert. (econv_primitive_output): new method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_econv.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb
index 0a797aecd6..5194983b8a 100644
--- a/test/ruby/test_econv.rb
+++ b/test/ruby/test_econv.rb
@@ -365,4 +365,38 @@ class TestEncodingConverter < Test::Unit::TestCase
assert_errinfo(:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "@\x00", nil, ec)
assert_equal("", src)
end
+
+ def test_output_region
+ ec = Encoding::Converter.new("EUC-JP", "UTF-8")
+ assert_equal(true, ec.primitive_output("abc", dst="", nil, 6))
+ assert_equal("abc", dst)
+ assert_raise(ArgumentError) { ec.primitive_output("abc", dst, 4, 6) }
+ assert_equal(true, ec.primitive_output("def", dst))
+ assert_equal("abcdef", dst)
+ assert_equal(false, ec.primitive_output("ghi", dst, nil, 1))
+ assert_equal("abcdef", dst)
+ assert_raise(ArgumentError) { ec.primitive_output("jkl", dst, -1, 6) }
+ assert_raise(ArgumentError) { ec.primitive_output("hij", dst, nil, -1) }
+ assert_equal("abcdef", dst)
+ end
+
+ def test_output_iso2022jp
+ ec = Encoding::Converter.new("EUC-JP", "ISO-2022-JP")
+ ec.primitive_convert(src="\xa1\xa1", dst="", nil, 10, Encoding::Converter::PARTIAL_INPUT)
+ assert_equal("\e$B!!".force_encoding("ISO-2022-JP"), dst)
+ assert_equal(true, ec.primitive_output("???", dst))
+ assert_equal("\e$B!!\e(B???".force_encoding("ISO-2022-JP"), dst)
+ ec.primitive_convert(src="\xa1\xa2", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
+ assert_equal("\e$B!!\e(B???\e$B!\"".force_encoding("ISO-2022-JP"), dst)
+
+ # escape sequences may be reduced in future.
+ assert_equal(true, ec.primitive_output("\xA1\xA1".force_encoding("EUC-JP"), dst))
+ assert_equal("\e$B!!\e(B???\e$B!\"\e(B\e$B!!\e(B".force_encoding("ISO-2022-JP"), dst)
+
+ ec.primitive_convert(src="\xa1\xa3", dst, nil, 10, Encoding::Converter::PARTIAL_INPUT)
+ assert_equal("\e$B!!\e(B???\e$B!\"\e(B\e$B!!\e(B\e$B!\#".force_encoding("ISO-2022-JP"), dst)
+
+ assert_equal(true, ec.primitive_output("\u3042", dst))
+ assert_equal("\e$B!!\e(B???\e$B!\"\e(B\e$B!!\e(B\e$B!\#\e(B\e$B$\"\e(B".force_encoding("ISO-2022-JP"), dst)
+ end
end