summaryrefslogtreecommitdiff
path: root/test/rexml/test_notationdecl_parsetest.rb
blob: cd3576708def6f095ad51380dbf969d3ab645ea0 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'test/unit'
require 'rexml/document'

class TestNotationDecl < Test::Unit::TestCase
  private
  def xml(internal_subset)
    <<-XML
<!DOCTYPE r SYSTEM "urn:x-henrikmartensson:test" [
#{internal_subset}
]>
<r/>
    XML
  end

  def parse(internal_subset)
    REXML::Document.new(xml(internal_subset)).doctype
  end

  class TestCommon < self
    def test_name
      doctype = parse("<!NOTATION name PUBLIC 'urn:public-id'>")
      assert_equal("name", doctype.notation("name").name)
    end
  end

  class TestExternalID < self
    class TestSystem < self
      def test_single_quote
        doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name SYSTEM 'system-literal'>
        INTERNAL_SUBSET
        assert_equal("system-literal", doctype.notation("name").system)
      end

      def test_double_quote
        doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name SYSTEM "system-literal">
        INTERNAL_SUBSET
        assert_equal("system-literal", doctype.notation("name").system)
      end
    end

    class TestPublic < self
      class TestPublicIDLiteral < self
        def test_single_quote
          doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC 'public-id-literal' "system-literal">
          INTERNAL_SUBSET
          assert_equal("public-id-literal", doctype.notation("name").public)
        end

        def test_double_quote
          doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC "public-id-literal" "system-literal">
          INTERNAL_SUBSET
          assert_equal("public-id-literal", doctype.notation("name").public)
        end
      end

      class TestSystemLiteral < self
        def test_single_quote
          doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC "public-id-literal" 'system-literal'>
          INTERNAL_SUBSET
          assert_equal("system-literal", doctype.notation("name").system)
        end

        def test_double_quote
          doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC "public-id-literal" "system-literal">
          INTERNAL_SUBSET
          assert_equal("system-literal", doctype.notation("name").system)
        end
      end
    end
  end
end