diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-06 17:13:27 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-06 17:13:27 -0800 |
commit | 8c60e9fa2a5e4932d8762469000b232d57c696b5 (patch) | |
tree | 29ba5ec4de61ecb966f68e11146de6cb6ca266f3 /test/psych/visitors | |
parent | e008a513f5e33031c5e9341cb4da09a225693840 (diff) | |
download | psych-8c60e9fa2a5e4932d8762469000b232d57c696b5.tar.gz |
merging from ruby
Diffstat (limited to 'test/psych/visitors')
-rw-r--r-- | test/psych/visitors/test_depth_first.rb | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/test/psych/visitors/test_depth_first.rb b/test/psych/visitors/test_depth_first.rb index a783960..a84f5b6 100644 --- a/test/psych/visitors/test_depth_first.rb +++ b/test/psych/visitors/test_depth_first.rb @@ -3,21 +3,47 @@ require_relative '../helper' module Psych module Visitors class TestDepthFirst < TestCase + class Collector < Struct.new(:calls) + def initialize(calls = []) + super + end + + def call obj + calls << obj + end + end + def test_scalar - collector = Class.new(Struct.new(:calls)) { - def initialize(calls = []) - super - end - - def call obj - calls << obj - end - }.new - visitor = Visitors::DepthFirst.new collector - visitor.accept Psych.parse '--- hello' + collector = Collector.new + visitor = Visitors::DepthFirst.new collector + visitor.accept Psych.parse_stream '--- hello' assert_equal 3, collector.calls.length end + + def test_sequence + collector = Collector.new + visitor = Visitors::DepthFirst.new collector + visitor.accept Psych.parse_stream "---\n- hello" + + assert_equal 4, collector.calls.length + end + + def test_mapping + collector = Collector.new + visitor = Visitors::DepthFirst.new collector + visitor.accept Psych.parse_stream "---\nhello: world" + + assert_equal 5, collector.calls.length + end + + def test_alias + collector = Collector.new + visitor = Visitors::DepthFirst.new collector + visitor.accept Psych.parse_stream "--- &yay\n- foo\n- *yay\n" + + assert_equal 5, collector.calls.length + end end end end |