aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_econv.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-12 22:43:17 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-12 22:43:17 +0000
commit9d4bb3b969799e314197c70b3e33223564258bc8 (patch)
tree519edd4816a66a773e785303b5cf8858fe6f7db4 /test/ruby/test_econv.rb
parent85c41f4fbcd58d3515a02d639f6e18b658c09034 (diff)
downloadruby-9d4bb3b969799e314197c70b3e33223564258bc8.tar.gz
* transcode.c (rb_trans_conv): report last transcode_obuf_full.
(econv_max_output): new method Encoding::Converter#max_output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_econv.rb')
-rw-r--r--test/ruby/test_econv.rb53
1 files changed, 41 insertions, 12 deletions
diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb
index 045a4a0e00..4bae60a877 100644
--- a/test/ruby/test_econv.rb
+++ b/test/ruby/test_econv.rb
@@ -1,24 +1,53 @@
require 'test/unit'
class TestEncodingConverter < Test::Unit::TestCase
- def assert_econv(ret_expected, src_expected, dst_expected, from, to, src, dst, flags=0)
+ def assert_econv(ret_expected, dst_expected, src_expected, to, from, src, opt={})
+ opt[:obuf_len] ||= 100
+ src = src.dup
ec = Encoding::Converter.new(from, to)
- ret = ec.primitive_convert(src, dst, flags)
- assert_equal(ret_expected, ret)
- assert_equal(src_expected, src)
- assert_equal(dst_expected, dst)
+ dst = ''
+ while true
+ ret = ec.primitive_convert(src, dst2=" "*opt[:obuf_len], 0)
+ dst << dst2
+ #p [ret, dst, src]
+ break if ret != :obuf_full
+ end
+ assert_equal([ret_expected, dst_expected, src_expected], [ret, dst, src])
end
def test_eucjp_to_utf8
- assert_econv(:finished, "", "", "EUC-JP", "UTF-8", "", "")
- assert_econv(:ibuf_empty, "", "", "EUC-JP", "UTF-8", "", "", Encoding::Converter::PARTIAL_INPUT)
- assert_econv(:finished, "", "", "EUC-JP", "UTF-8", "", " "*10)
- assert_econv(:obuf_full, "", "", "EUC-JP", "UTF-8", "a", "")
+ assert_econv(:finished, "", "", "EUC-JP", "UTF-8", "")
+ assert_econv(:finished, "a", "", "EUC-JP", "UTF-8", "a")
+ end
+
+ def test_iso2022jp
+ assert_econv(:finished, "", "", "ISO-2022-JP", "Shift_JIS", "")
end
def test_invalid
- assert_econv(:invalid_input, "", "", "EUC-JP", "UTF-8", "\x80", " "*10)
- assert_econv(:invalid_input, "", "a", "EUC-JP", "UTF-8", "a\x80", " "*10)
- assert_econv(:invalid_input, "\x80", "a", "EUC-JP", "UTF-8", "a\x80\x80", " "*10)
+ assert_econv(:invalid_input, "", "", "EUC-JP", "UTF-8", "\x80")
+ assert_econv(:invalid_input, "a", "", "EUC-JP", "UTF-8", "a\x80")
+ assert_econv(:invalid_input, "a", "\x80", "EUC-JP", "UTF-8", "a\x80\x80")
+ assert_econv(:invalid_input, "abc", "def", "EUC-JP", "UTF-8", "abc\xFFdef")
+ assert_econv(:invalid_input, "abc", "def", "EUC-JP", "Shift_JIS", "abc\xFFdef")
+ assert_econv(:invalid_input, "abc", "def", "EUC-JP", "Shift_JIS", "abc\xFFdef", :obuf_len=>1)
+ assert_econv(:invalid_input, "abc", "def", "Shift_JIS", "ISO-2022-JP", "abc\xFFdef")
+ end
+
+ def test_errors
+ ec = Encoding::Converter.new("UTF-16BE", "EUC-JP")
+ src = "\xFF\xFE\x00A\xDC\x00"
+ ret = ec.primitive_convert(src, dst=" "*10, 0)
+ assert_equal("", src)
+ assert_equal("", dst)
+ assert_equal(:undefined_conversion, ret)
+ ret = ec.primitive_convert(src, dst=" "*10, 0)
+ assert_equal("", src)
+ assert_equal("A", dst)
+ assert_equal(:invalid_input, ret)
+ ret = ec.primitive_convert(src, dst=" "*10, 0)
+ assert_equal("", src)
+ assert_equal("", dst)
+ assert_equal(:finished, ret)
end
end