summaryrefslogtreecommitdiff
path: root/test/psych/test_stream.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/psych/test_stream.rb')
-rw-r--r--test/psych/test_stream.rb49
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 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