diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-05-19 21:47:43 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-05-19 21:47:43 -0700 |
commit | 01b3d734cd685516ae4cba5bd4dbb7daab4931ee (patch) | |
tree | 577f044a119597140a826fb94a9d0416e05f6971 /test | |
parent | aa5e67a7dc7ba9e0d798d914f104f350f4d1969a (diff) | |
download | psych-01b3d734cd685516ae4cba5bd4dbb7daab4931ee.zip |
adding yaml streaming api
Diffstat (limited to 'test')
-rw-r--r-- | test/psych/test_stream.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/psych/test_stream.rb b/test/psych/test_stream.rb new file mode 100644 index 0000000..7e2f996 --- /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 |