diff options
Diffstat (limited to 'test/psych')
-rw-r--r-- | test/psych/test_encoding.rb | 73 | ||||
-rw-r--r-- | test/psych/test_parser.rb | 1 | ||||
-rw-r--r-- | test/psych/test_tainted.rb | 4 |
3 files changed, 77 insertions, 1 deletions
diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb index a341c47859..8efb676d9a 100644 --- a/test/psych/test_encoding.rb +++ b/test/psych/test_encoding.rb @@ -31,6 +31,79 @@ module Psych @emitter = Psych::Emitter.new @buffer end + def test_transcode_shiftjis + str = "こんにちは!" + loaded = Psych.load("--- こんにちは!".encode('SHIFT_JIS')) + assert_equal str, loaded + end + + def test_transcode_utf16le + str = "こんにちは!" + loaded = Psych.load("--- こんにちは!".encode('UTF-16LE')) + assert_equal str, loaded + end + + def test_transcode_utf16be + str = "こんにちは!" + loaded = Psych.load("--- こんにちは!".encode('UTF-16BE')) + assert_equal str, loaded + end + + def test_io_shiftjis + t = Tempfile.new(['shiftjis', 'yml'], :encoding => 'SHIFT_JIS') + t.write '--- こんにちは!' + t.close + + # If the external encoding isn't utf8, utf16le, or utf16be, we cannot + # process the file. + File.open(t.path, 'r', :encoding => 'SHIFT_JIS') do |f| + assert_raises ArgumentError do + Psych.load(f) + end + end + + t.close(true) + end + + def test_io_utf16le + t = Tempfile.new(['utf16le', 'yml']) + t.binmode + t.write '--- こんにちは!'.encode('UTF-16LE') + t.close + + File.open(t.path, 'rb', :encoding => 'UTF-16LE') do |f| + assert_equal "こんにちは!", Psych.load(f) + end + + t.close(true) + end + + def test_io_utf16be + t = Tempfile.new(['utf16be', 'yml']) + t.binmode + t.write '--- こんにちは!'.encode('UTF-16BE') + t.close + + File.open(t.path, 'rb', :encoding => 'UTF-16BE') do |f| + assert_equal "こんにちは!", Psych.load(f) + end + + t.close(true) + end + + def test_io_utf8 + t = Tempfile.new(['utf8', 'yml']) + t.binmode + t.write '--- こんにちは!'.encode('UTF-8') + t.close + + File.open(t.path, 'rb', :encoding => 'UTF-8') do |f| + assert_equal "こんにちは!", Psych.load(f) + end + + t.close(true) + end + def test_emit_alias @emitter.start_stream Psych::Parser::UTF8 @emitter.start_document [], [], true diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index a491d7fdd6..cfbfb61693 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -112,6 +112,7 @@ module Psych def test_bogus_io o = Object.new + def o.external_encoding; nil end def o.read len; self end assert_raises(TypeError) do diff --git a/test/psych/test_tainted.rb b/test/psych/test_tainted.rb index bf55d3b30e..00d220e825 100644 --- a/test/psych/test_tainted.rb +++ b/test/psych/test_tainted.rb @@ -121,7 +121,9 @@ module Psych t.binmode t.write string t.close - File.open(t.path) { |f| @parser.parse f } + File.open(t.path) { |f| + @parser.parse f + } t.close(true) end end |