summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-19 17:15:27 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-19 17:15:27 +0000
commit383769068d83604f28fa56a094785a2e199ed4ca (patch)
treef3d28eb5560b767439866a916c9dde7c42368828 /test
parent28f9376f3ac9fc51a7ccfa6fddfe40f9c2a3f446 (diff)
* ext/psych/emitter.c: output strings are automatically transcoded
* test/psych/test_emitter.rb: supporting tests * test/psych/test_encoding.rb: more supporting tests git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/psych/test_emitter.rb1
-rw-r--r--test/psych/test_encoding.rb72
2 files changed, 73 insertions, 0 deletions
diff --git a/test/psych/test_emitter.rb b/test/psych/test_emitter.rb
index 3738c1ac04..d7c6fff4ec 100644
--- a/test/psych/test_emitter.rb
+++ b/test/psych/test_emitter.rb
@@ -64,6 +64,7 @@ module Psych
['foo', Object.new, nil, false, true, 1],
['foo', nil, Object.new, false, true, 1],
['foo', nil, nil, false, true, :foo],
+ [nil, nil, nil, false, true, 1],
].each do |args|
assert_raises(TypeError) do
@emitter.scalar(*args)
diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb
index bf8318a774..8e9766329d 100644
--- a/test/psych/test_encoding.rb
+++ b/test/psych/test_encoding.rb
@@ -24,9 +24,81 @@ module Psych
def setup
super
+ @buffer = StringIO.new
@handler = EncodingCatcher.new
@parser = Psych::Parser.new @handler
@utf8 = Encoding.find('UTF-8')
+ @emitter = Psych::Emitter.new @buffer
+ end
+
+ def test_emit_alias
+ @emitter.start_stream Psych::Parser::UTF8
+ @emitter.start_document [], [], true
+ e = assert_raises(RuntimeError) do
+ @emitter.alias 'ドラえもん'.encode('EUC-JP')
+ end
+ assert_match(/alias value/, e.message)
+ end
+
+ def test_start_mapping
+ foo = 'foo'
+ bar = 'バー'
+
+ @emitter.start_stream Psych::Parser::UTF8
+ @emitter.start_document [], [], true
+ @emitter.start_mapping(
+ foo.encode('Shift_JIS'),
+ bar.encode('UTF-16LE'),
+ false, Nodes::Sequence::ANY)
+ @emitter.end_mapping
+ @emitter.end_document false
+ @emitter.end_stream
+
+ @parser.parse @buffer.string
+ assert_encodings @utf8, @handler.strings
+ assert_equal [foo, bar], @handler.strings
+ end
+
+ def test_start_sequence
+ foo = 'foo'
+ bar = 'バー'
+
+ @emitter.start_stream Psych::Parser::UTF8
+ @emitter.start_document [], [], true
+ @emitter.start_sequence(
+ foo.encode('Shift_JIS'),
+ bar.encode('UTF-16LE'),
+ false, Nodes::Sequence::ANY)
+ @emitter.end_sequence
+ @emitter.end_document false
+ @emitter.end_stream
+
+ @parser.parse @buffer.string
+ assert_encodings @utf8, @handler.strings
+ assert_equal [foo, bar], @handler.strings
+ end
+
+ def test_doc_tag_encoding
+ key = '鍵'
+ @emitter.start_stream Psych::Parser::UTF8
+ @emitter.start_document(
+ [1, 1],
+ [['!'.encode('EUC-JP'), key.encode('EUC-JP')]],
+ true
+ )
+ @emitter.scalar 'foo', nil, nil, true, false, Nodes::Scalar::ANY
+ @emitter.end_document false
+ @emitter.end_stream
+
+ @parser.parse @buffer.string
+ assert_encodings @utf8, @handler.strings
+ assert_equal key, @handler.strings[1]
+ end
+
+ def test_emitter_encoding
+ str = "壁に耳あり、障子に目あり"
+ thing = Psych.load Psych.dump str.encode('EUC-JP')
+ assert_equal str, thing
end
def test_default_internal