1require 'psych/helper'
2
3module Psych
4  class TestDocument < TestCase
5    def setup
6      super
7      @stream = Psych.parse_stream(<<-eoyml)
8%YAML 1.1
9%TAG ! tag:tenderlovemaking.com,2009:
10--- !fun
11      eoyml
12      @doc = @stream.children.first
13    end
14
15    def test_parse_tag
16      assert_equal([['!', 'tag:tenderlovemaking.com,2009:']],
17        @doc.tag_directives)
18    end
19
20    def test_emit_tag
21      assert_match('%TAG ! tag:tenderlovemaking.com,2009:', @stream.yaml)
22    end
23
24    def test_emit_multitag
25      @doc.tag_directives << ['!!', 'foo.com,2009:']
26      yaml = @stream.yaml
27      assert_match('%TAG ! tag:tenderlovemaking.com,2009:', yaml)
28      assert_match('%TAG !! foo.com,2009:', yaml)
29    end
30
31    def test_emit_bad_tag
32      assert_raises(RuntimeError) do
33        @doc.tag_directives = [['!']]
34        @stream.yaml
35      end
36    end
37
38    def test_parse_version
39      assert_equal([1,1], @doc.version)
40    end
41
42    def test_emit_version
43      assert_match('%YAML 1.1', @stream.yaml)
44    end
45  end
46end
47