summaryrefslogtreecommitdiff
path: root/test/psych/test_tree_builder.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/test_tree_builder.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/test_tree_builder.rb')
-rw-r--r--test/psych/test_tree_builder.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/psych/test_tree_builder.rb b/test/psych/test_tree_builder.rb
new file mode 100644
index 0000000..f03adc5
--- /dev/null
+++ b/test/psych/test_tree_builder.rb
@@ -0,0 +1,79 @@
+require 'test/psych/helper'
+
+module Psych
+ class TestTreeBuilder < TestCase
+ def setup
+ super
+ @parser = Psych::Parser.new TreeBuilder.new
+ @parser.parse(<<-eoyml)
+%YAML 1.1
+---
+- foo
+- {
+ bar : &A !!str baz,
+ boo : *A
+}
+- *A
+ eoyml
+ @tree = @parser.handler.root
+ end
+
+ def test_stream
+ assert_instance_of Nodes::Stream, @tree
+ end
+
+ def test_documents
+ assert_equal 1, @tree.children.length
+ assert_instance_of Nodes::Document, @tree.children.first
+ doc = @tree.children.first
+
+ assert_equal [1,1], doc.version
+ assert_equal [], doc.tag_directives
+ assert_equal false, doc.implicit
+ end
+
+ def test_sequence
+ doc = @tree.children.first
+ assert_equal 1, doc.children.length
+
+ seq = doc.children.first
+ assert_instance_of Nodes::Sequence, seq
+ assert_nil seq.anchor
+ assert_nil seq.tag
+ assert_equal true, seq.implicit
+ assert_equal Nodes::Sequence::BLOCK, seq.style
+ end
+
+ def test_scalar
+ doc = @tree.children.first
+ seq = doc.children.first
+
+ assert_equal 3, seq.children.length
+ scalar = seq.children.first
+ assert_instance_of Nodes::Scalar, scalar
+ assert_equal 'foo', scalar.value
+ assert_nil scalar.anchor
+ assert_nil scalar.tag
+ assert_equal true, scalar.plain
+ assert_equal false, scalar.quoted
+ assert_equal Nodes::Scalar::PLAIN, scalar.style
+ end
+
+ def test_mapping
+ doc = @tree.children.first
+ seq = doc.children.first
+ map = seq.children[1]
+
+ assert_instance_of Nodes::Mapping, map
+ end
+
+ def test_alias
+ doc = @tree.children.first
+ seq = doc.children.first
+ assert_equal 3, seq.children.length
+ al = seq.children[2]
+ assert_instance_of Nodes::Alias, al
+ assert_equal 'A', al.anchor
+ end
+ end
+end