diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-01-09 12:03:01 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-01-09 12:03:01 -0800 |
commit | db443b52843b05e47a2f803725ee19bfb1190fa9 (patch) | |
tree | 22db9422dcc6b43a37942f518be72a8e1c285cf4 /test/psych/test_encoding.rb | |
parent | 3c1be5322fbf775ac4e807e510f7bc50fcd5e305 (diff) | |
download | psych-db443b52843b05e47a2f803725ee19bfb1190fa9.zip |
anchors and aliases have an encoding
Diffstat (limited to 'test/psych/test_encoding.rb')
-rw-r--r-- | test/psych/test_encoding.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb new file mode 100644 index 0000000..d97856f --- /dev/null +++ b/test/psych/test_encoding.rb @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +require 'minitest/autorun' +require 'psych' + +module Psych + class TestEncoding < MiniTest::Unit::TestCase + class EncodingCatcher < Handler + attr_reader :strings + def initialize + @strings = [] + end + + (Handler.instance_methods(true) - + Object.instance_methods).each do |m| + class_eval %{ + def #{m} *args + @strings += args.flatten.find_all { |a| + String === a + } + end + } + end + end + + def setup + super + @handler = EncodingCatcher.new + @parser = Psych::Parser.new @handler + @utf8 = Encoding.find('UTF-8') + end + + def test_scalar + @parser.parse("--- a") + assert_encodings @utf8, @handler.strings + end + + def test_alias + @parser.parse(<<-eoyml) +%YAML 1.1 +--- +!!seq [ + !!str "Without properties", + &A !!str "Anchored", + !!str "Tagged", + *A, + !!str "", +] + eoyml + assert_encodings @utf8, @handler.strings + end + + private + def assert_encodings encoding, strings + strings.each do |str| + assert_equal encoding, str.encoding, str + end + end + end +end |