File: test_notation_declaration.rb

package info (click to toggle)
ruby2.3 2.3.3-1%2Bdeb9u8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 65,344 kB
  • sloc: ruby: 639,947; ansic: 317,772; xml: 25,445; yacc: 9,068; javascript: 6,648; lisp: 2,568; tcl: 949; makefile: 623; sh: 533; perl: 62; sed: 53; python: 47; awk: 36; asm: 35
file content (100 lines) | stat: -rw-r--r-- 3,064 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: false
require 'test/unit'
require 'rexml/document'

module REXMLTests
  class TestParseNotationDeclaration < 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

      class TestMixed < self
        def test_system_public
          doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION system-name SYSTEM "system-literal">
<!NOTATION public-name PUBLIC "public-id-literal" 'system-literal'>
          INTERNAL_SUBSET
          assert_equal(["system-name", "public-name"],
                       doctype.notations.collect(&:name))
        end

        def test_public_system
          doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION public-name PUBLIC "public-id-literal" 'system-literal'>
<!NOTATION system-name SYSTEM "system-literal">
          INTERNAL_SUBSET
          assert_equal(["public-name", "system-name"],
                       doctype.notations.collect(&:name))
        end
      end
    end
  end
end