1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/psych/test_stream.rb
tenderlove 5256d10265 * 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
2010-05-20 04:03:47 +00:00

49 lines
1.3 KiB
Ruby

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