From 5256d1026505b01f75669c1087c74c04dacd05ba Mon Sep 17 00:00:00 2001 From: tenderlove Date: Thu, 20 May 2010 04:03:47 +0000 Subject: * ext/psych/lib/psych/stream.rb: adding YAML streaming API for infinite length streams. * ext/psych/lib/psych.rb: refactoring for streaming API * ext/psych/lib/psych/{handler, stream, tree_builder}.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/psych/test_stream.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/psych/test_stream.rb (limited to 'test/psych/test_stream.rb') diff --git a/test/psych/test_stream.rb b/test/psych/test_stream.rb new file mode 100644 index 0000000000..7e2f996708 --- /dev/null +++ b/test/psych/test_stream.rb @@ -0,0 +1,49 @@ +require_relative 'helper' + +module Psych + class TestStream < TestCase + def test_explicit_documents + io = StringIO.new + stream = Psych::Stream.new(io) + stream.start + stream.push({ 'foo' => 'bar' }) + + assert !stream.finished?, 'stream not finished' + stream.finish + assert stream.finished?, 'stream finished' + + assert_match(/^---/, io.string) + assert_match(/\.\.\.$/, io.string) + end + + def test_start_takes_block + io = StringIO.new + stream = Psych::Stream.new(io) + stream.start do |emitter| + emitter.push({ 'foo' => 'bar' }) + end + + assert stream.finished?, 'stream finished' + assert_match(/^---/, io.string) + assert_match(/\.\.\.$/, io.string) + end + + def test_no_backreferences + io = StringIO.new + stream = Psych::Stream.new(io) + stream.start do |emitter| + x = { 'foo' => 'bar' } + emitter.push x + emitter.push x + end + + assert stream.finished?, 'stream finished' + assert_match(/^---/, io.string) + assert_match(/\.\.\.$/, io.string) + assert_equal 2, io.string.scan('---').length + assert_equal 2, io.string.scan('...').length + assert_equal 2, io.string.scan('foo').length + assert_equal 2, io.string.scan('bar').length + end + end +end -- cgit v1.2.3