|
4 | 4 | require "rexml/sax2listener" |
5 | 5 |
|
6 | 6 | module REXMLTests |
7 | | -class TestSAX2Parser < Test::Unit::TestCase |
8 | | - class TestDocumentTypeDeclaration < self |
9 | | - private |
10 | | - def xml(internal_subset) |
11 | | - <<-XML |
| 7 | + class TestSAX2Parser < Test::Unit::TestCase |
| 8 | + class TestDocumentTypeDeclaration < self |
| 9 | + private |
| 10 | + def xml(internal_subset) |
| 11 | + <<-XML |
12 | 12 | <!DOCTYPE r SYSTEM "urn:x-henrikmartensson:test" [ |
13 | 13 | #{internal_subset} |
14 | 14 | ]> |
15 | 15 | <r/> |
16 | | - XML |
17 | | - end |
| 16 | + XML |
| 17 | + end |
18 | 18 |
|
19 | | - class TestEntityDeclaration < self |
20 | | - class Listener |
21 | | - include REXML::SAX2Listener |
22 | | - attr_reader :entity_declarations |
23 | | - def initialize |
24 | | - @entity_declarations = [] |
25 | | - end |
| 19 | + class TestEntityDeclaration < self |
| 20 | + class Listener |
| 21 | + include REXML::SAX2Listener |
| 22 | + attr_reader :entity_declarations |
| 23 | + def initialize |
| 24 | + @entity_declarations = [] |
| 25 | + end |
26 | 26 |
|
27 | | - def entitydecl(declaration) |
28 | | - super |
29 | | - @entity_declarations << declaration |
| 27 | + def entitydecl(declaration) |
| 28 | + super |
| 29 | + @entity_declarations << declaration |
| 30 | + end |
30 | 31 | end |
31 | | - end |
32 | 32 |
|
33 | | - private |
34 | | - def parse(internal_subset) |
35 | | - listener = Listener.new |
36 | | - parser = REXML::Parsers::SAX2Parser.new(xml(internal_subset)) |
37 | | - parser.listen(listener) |
38 | | - parser.parse |
39 | | - listener.entity_declarations |
40 | | - end |
| 33 | + private |
| 34 | + def parse(internal_subset) |
| 35 | + listener = Listener.new |
| 36 | + parser = REXML::Parsers::SAX2Parser.new(xml(internal_subset)) |
| 37 | + parser.listen(listener) |
| 38 | + parser.parse |
| 39 | + listener.entity_declarations |
| 40 | + end |
41 | 41 |
|
42 | | - class TestGeneralEntity < self |
43 | | - class TestValue < self |
44 | | - def test_double_quote |
45 | | - assert_equal([["name", "value"]], parse(<<-INTERNAL_SUBSET)) |
| 42 | + class TestGeneralEntity < self |
| 43 | + class TestValue < self |
| 44 | + def test_double_quote |
| 45 | + assert_equal([["name", "value"]], parse(<<-INTERNAL_SUBSET)) |
46 | 46 | <!ENTITY name "value"> |
47 | | - INTERNAL_SUBSET |
48 | | - end |
| 47 | + INTERNAL_SUBSET |
| 48 | + end |
49 | 49 |
|
50 | | - def test_single_quote |
51 | | - assert_equal([["name", "value"]], parse(<<-INTERNAL_SUBSET)) |
| 50 | + def test_single_quote |
| 51 | + assert_equal([["name", "value"]], parse(<<-INTERNAL_SUBSET)) |
52 | 52 | <!ENTITY name 'value'> |
53 | | - INTERNAL_SUBSET |
| 53 | + INTERNAL_SUBSET |
| 54 | + end |
54 | 55 | end |
55 | | - end |
56 | 56 |
|
57 | | - class TestExternlID < self |
58 | | - class TestSystem < self |
59 | | - def test_with_ndata |
60 | | - declaration = [ |
61 | | - "name", |
62 | | - "SYSTEM", "system-literal", |
63 | | - "NDATA", "ndata-name", |
64 | | - ] |
65 | | - assert_equal([declaration], |
66 | | - parse(<<-INTERNAL_SUBSET)) |
| 57 | + class TestExternlID < self |
| 58 | + class TestSystem < self |
| 59 | + def test_with_ndata |
| 60 | + declaration = [ |
| 61 | + "name", |
| 62 | + "SYSTEM", "system-literal", |
| 63 | + "NDATA", "ndata-name", |
| 64 | + ] |
| 65 | + assert_equal([declaration], |
| 66 | + parse(<<-INTERNAL_SUBSET)) |
67 | 67 | <!ENTITY name SYSTEM "system-literal" NDATA ndata-name> |
| 68 | + INTERNAL_SUBSET |
| 69 | + end |
| 70 | + |
| 71 | + def test_without_ndata |
| 72 | + declaration = [ |
| 73 | + "name", |
| 74 | + "SYSTEM", "system-literal", |
| 75 | + ] |
| 76 | + assert_equal([declaration], |
| 77 | + parse(<<-INTERNAL_SUBSET)) |
| 78 | +<!ENTITY name SYSTEM "system-literal"> |
| 79 | + INTERNAL_SUBSET |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + class TestPublic < self |
| 84 | + def test_with_ndata |
| 85 | + declaration = [ |
| 86 | + "name", |
| 87 | + "PUBLIC", "public-literal", "system-literal", |
| 88 | + "NDATA", "ndata-name", |
| 89 | + ] |
| 90 | + assert_equal([declaration], |
| 91 | + parse(<<-INTERNAL_SUBSET)) |
| 92 | +<!ENTITY name PUBLIC "public-literal" "system-literal" NDATA ndata-name> |
| 93 | + INTERNAL_SUBSET |
| 94 | + end |
| 95 | + |
| 96 | + def test_without_ndata |
| 97 | + declaration = [ |
| 98 | + "name", |
| 99 | + "PUBLIC", "public-literal", "system-literal", |
| 100 | + ] |
| 101 | + assert_equal([declaration], parse(<<-INTERNAL_SUBSET)) |
| 102 | +<!ENTITY name PUBLIC "public-literal" "system-literal"> |
| 103 | + INTERNAL_SUBSET |
| 104 | + end |
| 105 | + end |
| 106 | + end |
| 107 | + end |
| 108 | + |
| 109 | + class TestParameterEntity < self |
| 110 | + class TestValue < self |
| 111 | + def test_double_quote |
| 112 | + assert_equal([["%", "name", "value"]], parse(<<-INTERNAL_SUBSET)) |
| 113 | +<!ENTITY % name "value"> |
68 | 114 | INTERNAL_SUBSET |
69 | 115 | end |
70 | 116 |
|
71 | | - def test_without_ndata |
72 | | - declaration = [ |
73 | | - "name", |
74 | | - "SYSTEM", "system-literal", |
75 | | - ] |
76 | | - assert_equal([declaration], |
77 | | - parse(<<-INTERNAL_SUBSET)) |
78 | | -<!ENTITY name SYSTEM "system-literal"> |
| 117 | + def test_single_quote |
| 118 | + assert_equal([["%", "name", "value"]], parse(<<-INTERNAL_SUBSET)) |
| 119 | +<!ENTITY % name 'value'> |
79 | 120 | INTERNAL_SUBSET |
80 | 121 | end |
81 | 122 | end |
82 | 123 |
|
83 | | - class TestPublic < self |
84 | | - def test_with_ndata |
| 124 | + class TestExternlID < self |
| 125 | + def test_system |
85 | 126 | declaration = [ |
| 127 | + "%", |
86 | 128 | "name", |
87 | | - "PUBLIC", "public-literal", "system-literal", |
88 | | - "NDATA", "ndata-name", |
| 129 | + "SYSTEM", "system-literal", |
89 | 130 | ] |
90 | 131 | assert_equal([declaration], |
91 | | - parse(<<-INTERNAL_SUBSET)) |
92 | | -<!ENTITY name PUBLIC "public-literal" "system-literal" NDATA ndata-name> |
| 132 | + parse(<<-INTERNAL_SUBSET)) |
| 133 | +<!ENTITY % name SYSTEM "system-literal"> |
93 | 134 | INTERNAL_SUBSET |
94 | 135 | end |
95 | 136 |
|
96 | | - def test_without_ndata |
| 137 | + def test_public |
97 | 138 | declaration = [ |
| 139 | + "%", |
98 | 140 | "name", |
99 | 141 | "PUBLIC", "public-literal", "system-literal", |
100 | 142 | ] |
101 | 143 | assert_equal([declaration], parse(<<-INTERNAL_SUBSET)) |
102 | | -<!ENTITY name PUBLIC "public-literal" "system-literal"> |
| 144 | +<!ENTITY % name PUBLIC "public-literal" "system-literal"> |
103 | 145 | INTERNAL_SUBSET |
104 | 146 | end |
105 | 147 | end |
106 | 148 | end |
107 | 149 | end |
108 | 150 |
|
109 | | - class TestParameterEntity < self |
110 | | - class TestValue < self |
111 | | - def test_double_quote |
112 | | - assert_equal([["%", "name", "value"]], parse(<<-INTERNAL_SUBSET)) |
113 | | -<!ENTITY % name "value"> |
114 | | - INTERNAL_SUBSET |
| 151 | + class TestNotationDeclaration < self |
| 152 | + class Listener |
| 153 | + include REXML::SAX2Listener |
| 154 | + attr_reader :notation_declarations |
| 155 | + def initialize |
| 156 | + @notation_declarations = [] |
115 | 157 | end |
116 | 158 |
|
117 | | - def test_single_quote |
118 | | - assert_equal([["%", "name", "value"]], parse(<<-INTERNAL_SUBSET)) |
119 | | -<!ENTITY % name 'value'> |
120 | | - INTERNAL_SUBSET |
| 159 | + def notationdecl(*declaration) |
| 160 | + super |
| 161 | + @notation_declarations << declaration |
121 | 162 | end |
122 | 163 | end |
123 | 164 |
|
| 165 | + private |
| 166 | + def parse(internal_subset) |
| 167 | + listener = Listener.new |
| 168 | + parser = REXML::Parsers::SAX2Parser.new(xml(internal_subset)) |
| 169 | + parser.listen(listener) |
| 170 | + parser.parse |
| 171 | + listener.notation_declarations |
| 172 | + end |
| 173 | + |
124 | 174 | class TestExternlID < self |
125 | 175 | def test_system |
126 | | - declaration = [ |
127 | | - "%", |
128 | | - "name", |
129 | | - "SYSTEM", "system-literal", |
130 | | - ] |
| 176 | + declaration = ["name", "SYSTEM", nil, "system-literal"] |
131 | 177 | assert_equal([declaration], |
132 | | - parse(<<-INTERNAL_SUBSET)) |
133 | | -<!ENTITY % name SYSTEM "system-literal"> |
134 | | - INTERNAL_SUBSET |
135 | | - end |
136 | | - |
137 | | - def test_public |
138 | | - declaration = [ |
139 | | - "%", |
140 | | - "name", |
141 | | - "PUBLIC", "public-literal", "system-literal", |
142 | | - ] |
143 | | - assert_equal([declaration], parse(<<-INTERNAL_SUBSET)) |
144 | | -<!ENTITY % name PUBLIC "public-literal" "system-literal"> |
145 | | - INTERNAL_SUBSET |
146 | | - end |
147 | | - end |
148 | | - end |
149 | | - end |
150 | | - |
151 | | - class TestNotationDeclaration < self |
152 | | - class Listener |
153 | | - include REXML::SAX2Listener |
154 | | - attr_reader :notation_declarations |
155 | | - def initialize |
156 | | - @notation_declarations = [] |
157 | | - end |
158 | | - |
159 | | - def notationdecl(*declaration) |
160 | | - super |
161 | | - @notation_declarations << declaration |
162 | | - end |
163 | | - end |
164 | | - |
165 | | - private |
166 | | - def parse(internal_subset) |
167 | | - listener = Listener.new |
168 | | - parser = REXML::Parsers::SAX2Parser.new(xml(internal_subset)) |
169 | | - parser.listen(listener) |
170 | | - parser.parse |
171 | | - listener.notation_declarations |
172 | | - end |
173 | | - |
174 | | - class TestExternlID < self |
175 | | - def test_system |
176 | | - declaration = ["name", "SYSTEM", nil, "system-literal"] |
177 | | - assert_equal([declaration], |
178 | | - parse(<<-INTERNAL_SUBSET)) |
| 178 | + parse(<<-INTERNAL_SUBSET)) |
179 | 179 | <!NOTATION name SYSTEM "system-literal"> |
180 | | - INTERNAL_SUBSET |
181 | | - end |
| 180 | + INTERNAL_SUBSET |
| 181 | + end |
182 | 182 |
|
183 | | - def test_public |
184 | | - declaration = ["name", "PUBLIC", "public-literal", "system-literal"] |
185 | | - assert_equal([declaration], parse(<<-INTERNAL_SUBSET)) |
| 183 | + def test_public |
| 184 | + declaration = ["name", "PUBLIC", "public-literal", "system-literal"] |
| 185 | + assert_equal([declaration], parse(<<-INTERNAL_SUBSET)) |
186 | 186 | <!NOTATION name PUBLIC "public-literal" "system-literal"> |
187 | | - INTERNAL_SUBSET |
| 187 | + INTERNAL_SUBSET |
| 188 | + end |
188 | 189 | end |
189 | | - end |
190 | 190 |
|
191 | | - class TestPublicID < self |
192 | | - def test_literal |
193 | | - declaration = ["name", "PUBLIC", "public-literal", nil] |
194 | | - assert_equal([declaration], |
195 | | - parse(<<-INTERNAL_SUBSET)) |
| 191 | + class TestPublicID < self |
| 192 | + def test_literal |
| 193 | + declaration = ["name", "PUBLIC", "public-literal", nil] |
| 194 | + assert_equal([declaration], |
| 195 | + parse(<<-INTERNAL_SUBSET)) |
196 | 196 | <!NOTATION name PUBLIC "public-literal"> |
197 | | - INTERNAL_SUBSET |
| 197 | + INTERNAL_SUBSET |
| 198 | + end |
198 | 199 | end |
199 | 200 | end |
200 | 201 | end |
201 | 202 | end |
202 | 203 | end |
203 | | -end |
0 commit comments