summaryrefslogtreecommitdiff
path: root/test/psych/test_stream.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-08 13:23:08 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-03-08 13:23:08 -0800
commit34d3b22d2b94e58b0e51ac922ea48d686fcbb901 (patch)
tree7b9599abf65a350c7a680f15f4ccf0614674c2f9 /test/psych/test_stream.rb
parent90acf338b14a31498e8888493b31a90f13978918 (diff)
downloadpsych-34d3b22d2b94e58b0e51ac922ea48d686fcbb901.zip
* ext/psych/lib/psych.rb (parse_stream, load_stream): if a block is
given, documents will be yielded to the block as they are parsed. [ruby-core:42404] [Bug #5978] * ext/psych/lib/psych/handlers/document_stream.rb: add a handler that yields documents as they are parsed * test/psych/test_stream.rb: corresponding tests.
Diffstat (limited to 'test/psych/test_stream.rb')
-rw-r--r--test/psych/test_stream.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/psych/test_stream.rb b/test/psych/test_stream.rb
index 4d8f137..9807207 100644
--- a/test/psych/test_stream.rb
+++ b/test/psych/test_stream.rb
@@ -2,6 +2,40 @@ require 'psych/helper'
module Psych
class TestStream < TestCase
+ def test_parse_stream_yields_documents
+ list = []
+ Psych.parse_stream("--- foo\n...\n--- bar") do |doc|
+ list << doc.to_ruby
+ end
+ assert_equal %w{ foo bar }, list
+ end
+
+ def test_parse_stream_break
+ list = []
+ Psych.parse_stream("--- foo\n...\n--- `") do |doc|
+ list << doc.to_ruby
+ break
+ end
+ assert_equal %w{ foo }, list
+ end
+
+ def test_load_stream_yields_documents
+ list = []
+ Psych.load_stream("--- foo\n...\n--- bar") do |ruby|
+ list << ruby
+ end
+ assert_equal %w{ foo bar }, list
+ end
+
+ def test_load_stream_break
+ list = []
+ Psych.load_stream("--- foo\n...\n--- `") do |ruby|
+ list << ruby
+ break
+ end
+ assert_equal %w{ foo }, list
+ end
+
def test_explicit_documents
io = StringIO.new
stream = Psych::Stream.new(io)