summaryrefslogtreecommitdiff
path: root/test/visitors
diff options
context:
space:
mode:
Diffstat (limited to 'test/visitors')
-rw-r--r--test/visitors/test_emitter.rb46
-rw-r--r--test/visitors/test_yast_builder.rb43
2 files changed, 89 insertions, 0 deletions
diff --git a/test/visitors/test_emitter.rb b/test/visitors/test_emitter.rb
index b7b9110..e79a7b5 100644
--- a/test/visitors/test_emitter.rb
+++ b/test/visitors/test_emitter.rb
@@ -29,6 +29,22 @@ module Psych
assert_equal @io.string, s.to_yaml
end
+ def test_document_implicit_end
+ s = Nodes::Stream.new
+ doc = Nodes::Document.new
+ mapping = Nodes::Mapping.new
+ mapping.children << Nodes::Scalar.new('key')
+ mapping.children << Nodes::Scalar.new('value')
+ doc.children << mapping
+ s.children << doc
+
+ @visitor.accept s
+
+ assert_match(/key: value/, @io.string)
+ assert_equal @io.string, s.to_yaml
+ assert(/\.\.\./ !~ s.to_yaml)
+ end
+
def test_scalar
s = Nodes::Stream.new
doc = Nodes::Document.new
@@ -58,6 +74,36 @@ module Psych
assert_match(/- hello/, @io.string)
assert_equal @io.string, s.to_yaml
end
+
+ def test_mapping
+ s = Nodes::Stream.new
+ doc = Nodes::Document.new
+ mapping = Nodes::Mapping.new
+ mapping.children << Nodes::Scalar.new('key')
+ mapping.children << Nodes::Scalar.new('value')
+ doc.children << mapping
+ s.children << doc
+
+ @visitor.accept s
+
+ assert_match(/key: value/, @io.string)
+ assert_equal @io.string, s.to_yaml
+ end
+
+ def test_alias
+ s = Nodes::Stream.new
+ doc = Nodes::Document.new
+ mapping = Nodes::Mapping.new
+ mapping.children << Nodes::Scalar.new('key', 'A')
+ mapping.children << Nodes::Alias.new('A')
+ doc.children << mapping
+ s.children << doc
+
+ @visitor.accept s
+
+ assert_match(/&A key: \*A/, @io.string)
+ assert_equal @io.string, s.to_yaml
+ end
end
end
end
diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb
new file mode 100644
index 0000000..027764a
--- /dev/null
+++ b/test/visitors/test_yast_builder.rb
@@ -0,0 +1,43 @@
+require 'minitest/autorun'
+require 'psych'
+
+module Psych
+ module Visitors
+ class TestYASTBuilder < MiniTest::Unit::TestCase
+ def setup
+ @v = Visitors::YASTBuilder.new
+ end
+ def test_scalar
+ @v.accept 'foo'
+
+ assert_equal 'foo', Psych.load(@v.tree.to_yaml)
+ assert_equal 'foo', Psych.load('foo'.to_yaml)
+ end
+
+ def test_binary
+ string = [0, 123,22, 44, 9, 32, 34, 39].pack('C*')
+ assert_equal string, Psych.load(string.to_yaml)
+ end
+
+ def test_anon_class
+ assert_raises(TypeError) do
+ @v.accept Class.new
+ end
+
+ assert_raises(TypeError) do
+ Class.new.to_yaml
+ end
+ end
+
+ def test_hash
+ assert_round_trip('a' => 'b')
+ end
+
+ def assert_round_trip obj
+ @v.accept(obj)
+ assert_equal(obj, Psych.load(@v.tree.to_yaml))
+ assert_equal(obj, Psych.load(obj.to_yaml))
+ end
+ end
+ end
+end