summaryrefslogtreecommitdiff
path: root/test/psych/visitors/test_emitter.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-28 21:49:37 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-28 21:49:37 +0000
commitb9b923ca942096ddb1062be2deb9e6de9a65f346 (patch)
treebc8466746efbe763c7e8a54390d9b34db1aa63c4 /test/psych/visitors/test_emitter.rb
parenta8a99a7379fa8e07f217fc7b24e3a9208a967898 (diff)
* ext/psych/*: importing Psych to trunk
* test/psych/*: ditto * lib/psych/*: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/psych/visitors/test_emitter.rb')
-rw-r--r--test/psych/visitors/test_emitter.rb124
1 files changed, 124 insertions, 0 deletions
diff --git a/test/psych/visitors/test_emitter.rb b/test/psych/visitors/test_emitter.rb
new file mode 100644
index 0000000000..42987d113c
--- /dev/null
+++ b/test/psych/visitors/test_emitter.rb
@@ -0,0 +1,124 @@
+require 'test/psych/helper'
+
+module Psych
+ module Visitors
+ class TestEmitter < TestCase
+ def setup
+ super
+ @io = StringIO.new
+ @visitor = Visitors::Emitter.new @io
+ end
+
+ def test_stream
+ s = Nodes::Stream.new
+ @visitor.accept s
+ assert_equal '', @io.string
+ end
+
+ def test_document
+ s = Nodes::Stream.new
+ doc = Nodes::Document.new [1,1]
+ scalar = Nodes::Scalar.new 'hello world'
+
+ doc.children << scalar
+ s.children << doc
+
+ @visitor.accept s
+
+ assert_match(/1.1/, @io.string)
+ 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
+ scalar = Nodes::Scalar.new 'hello world'
+
+ doc.children << scalar
+ s.children << doc
+
+ @visitor.accept s
+
+ assert_match(/hello/, @io.string)
+ assert_equal @io.string, s.to_yaml
+ end
+
+ def test_scalar_with_tag
+ s = Nodes::Stream.new
+ doc = Nodes::Document.new
+ scalar = Nodes::Scalar.new 'hello world', nil, '!str', false, false, 5
+
+ doc.children << scalar
+ s.children << doc
+
+ @visitor.accept s
+
+ assert_match(/str/, @io.string)
+ assert_match(/hello/, @io.string)
+ assert_equal @io.string, s.to_yaml
+ end
+
+ def test_sequence
+ s = Nodes::Stream.new
+ doc = Nodes::Document.new
+ scalar = Nodes::Scalar.new 'hello world'
+ seq = Nodes::Sequence.new
+
+ seq.children << scalar
+ doc.children << seq
+ s.children << doc
+
+ @visitor.accept s
+
+ 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