Sha256: f515f613344c3eb3769477cc2c12c94cb6272441cae36f85d9f3998725348f00

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

require 'psych/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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
psych-1.2.2 test/psych/test_stream.rb
psych-1.2.2.rc1 test/psych/test_stream.rb
psych-1.2.1 test/psych/test_stream.rb
psych-1.2.0 test/psych/test_stream.rb
psych-1.1.1 test/psych/test_stream.rb
psych-1.1.0 test/psych/test_stream.rb