summaryrefslogtreecommitdiff
path: root/test/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-23 23:12:57 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-23 23:12:57 +0000
commit774cf315e838216aa8b4c138173484aa2388c380 (patch)
tree9be3c41dd133ab1a383fac0fbca9161ebf4051b3 /test/psych
parent0e0286404ff2a3b4298d1ebab65d0f351caf098e (diff)
* ext/psych/parser.c: set parser encoding based on the YAML input
rather than user configuration. * test/psych/test_encoding.rb: corresponding tests. * test/psych/test_parser.rb: ditto * test/psych/test_tainted.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/psych')
-rw-r--r--test/psych/test_encoding.rb73
-rw-r--r--test/psych/test_parser.rb1
-rw-r--r--test/psych/test_tainted.rb4
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