summaryrefslogtreecommitdiff
path: root/test/visitors/test_emitter.rb
blob: 3c93cc7b20450ffe3606e72539b8d1864b1495e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'minitest/autorun'
require 'psych'

module Psych
  module Visitors
    class TestEmitter < MiniTest::Unit::TestCase
      def setup
        @io = StringIO.new
        @visitor = Visitors::Emitter.new @io
      end

      def test_stream
        s = Nodes::Stream.new
        @visitor.accept s
        assert_equal '', @io.string
      end

      def test_document
        s = Nodes::Stream.new
        s.children << Nodes::Document.new([1,1])
        @visitor.accept s
        assert_equal '', @io.string
      end

      def test_scalar
        s       = Nodes::Stream.new
        doc     = Nodes::Document.new
        scalar  = Nodes::Scalar.new 'hello'

        doc.children << scalar
        s.children << doc

        @visitor.accept s

        assert_match(/hello/, @io.string)
      end
    end
  end
end