@@ -23,10 +23,100 @@ def test_name
23
23
doctype = parse ( "<!NOTATION name PUBLIC 'urn:public-id'>" )
24
24
assert_equal ( "name" , doctype . notation ( "name" ) . name )
25
25
end
26
+
27
+ def test_no_name
28
+ exception = assert_raise ( REXML ::ParseException ) do
29
+ parse ( <<-INTERNAL_SUBSET )
30
+ <!NOTATION>
31
+ INTERNAL_SUBSET
32
+ end
33
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
34
+ Malformed notation declaration: name is missing
35
+ Line: 5
36
+ Position: 72
37
+ Last 80 unconsumed characters:
38
+ <!NOTATION> ]> <r/>
39
+ DETAIL
40
+ end
41
+
42
+ def test_invalid_name
43
+ exception = assert_raise ( REXML ::ParseException ) do
44
+ parse ( <<-INTERNAL_SUBSET )
45
+ <!NOTATION '>
46
+ INTERNAL_SUBSET
47
+ end
48
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
49
+ Malformed notation declaration: invalid name
50
+ Line: 5
51
+ Position: 74
52
+ Last 80 unconsumed characters:
53
+ <!NOTATION '> ]> <r/>
54
+ DETAIL
55
+ end
56
+
57
+ def test_no_id_type
58
+ exception = assert_raise ( REXML ::ParseException ) do
59
+ parse ( <<-INTERNAL_SUBSET )
60
+ <!NOTATION name>
61
+ INTERNAL_SUBSET
62
+ end
63
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
64
+ Malformed notation declaration: ID type is missing
65
+ Line: 5
66
+ Position: 77
67
+ Last 80 unconsumed characters:
68
+ <!NOTATION name> ]> <r/>
69
+ DETAIL
70
+ end
71
+
72
+ def test_invalid_id_type
73
+ exception = assert_raise ( REXML ::ParseException ) do
74
+ parse ( <<-INTERNAL_SUBSET )
75
+ <!NOTATION name INVALID>
76
+ INTERNAL_SUBSET
77
+ end
78
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
79
+ Malformed notation declaration: invalid ID type
80
+ Line: 5
81
+ Position: 85
82
+ Last 80 unconsumed characters:
83
+ <!NOTATION name INVALID> ]> <r/>
84
+ DETAIL
85
+ end
26
86
end
27
87
28
88
class TestExternalID < self
29
89
class TestSystem < self
90
+ def test_no_literal
91
+ exception = assert_raise ( REXML ::ParseException ) do
92
+ parse ( <<-INTERNAL_SUBSET )
93
+ <!NOTATION name SYSTEM>
94
+ INTERNAL_SUBSET
95
+ end
96
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
97
+ Malformed notation declaration: system literal is missing
98
+ Line: 5
99
+ Position: 84
100
+ Last 80 unconsumed characters:
101
+ <!NOTATION name SYSTEM> ]> <r/>
102
+ DETAIL
103
+ end
104
+
105
+ def test_garbage_after_literal
106
+ exception = assert_raise ( REXML ::ParseException ) do
107
+ parse ( <<-INTERNAL_SUBSET )
108
+ <!NOTATION name SYSTEM 'system-literal'x'>
109
+ INTERNAL_SUBSET
110
+ end
111
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
112
+ Malformed notation declaration: garbage after system literal
113
+ Line: 5
114
+ Position: 103
115
+ Last 80 unconsumed characters:
116
+ <!NOTATION name SYSTEM 'system-literal'x'> ]> <r/>
117
+ DETAIL
118
+ end
119
+
30
120
def test_single_quote
31
121
doctype = parse ( <<-INTERNAL_SUBSET )
32
122
<!NOTATION name SYSTEM 'system-literal'>
@@ -44,6 +134,21 @@ def test_double_quote
44
134
45
135
class TestPublic < self
46
136
class TestPublicIDLiteral < self
137
+ def test_content_double_quote
138
+ exception = assert_raise ( REXML ::ParseException ) do
139
+ parse ( <<-INTERNAL_SUBSET )
140
+ <!NOTATION name PUBLIC 'double quote " is invalid' "system-literal">
141
+ INTERNAL_SUBSET
142
+ end
143
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
144
+ Malformed notation declaration: invalid public ID literal
145
+ Line: 5
146
+ Position: 129
147
+ Last 80 unconsumed characters:
148
+ <!NOTATION name PUBLIC 'double quote " is invalid' "system-literal"> ]> <r/>
149
+ DETAIL
150
+ end
151
+
47
152
def test_single_quote
48
153
doctype = parse ( <<-INTERNAL_SUBSET )
49
154
<!NOTATION name PUBLIC 'public-id-literal' "system-literal">
@@ -60,6 +165,21 @@ def test_double_quote
60
165
end
61
166
62
167
class TestSystemLiteral < self
168
+ def test_garbage_after_literal
169
+ exception = assert_raise ( REXML ::ParseException ) do
170
+ parse ( <<-INTERNAL_SUBSET )
171
+ <!NOTATION name PUBLIC 'public-id-literal' 'system-literal'x'>
172
+ INTERNAL_SUBSET
173
+ end
174
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
175
+ Malformed notation declaration: garbage after system literal
176
+ Line: 5
177
+ Position: 123
178
+ Last 80 unconsumed characters:
179
+ <!NOTATION name PUBLIC 'public-id-literal' 'system-literal'x'> ]> <r/>
180
+ DETAIL
181
+ end
182
+
63
183
def test_single_quote
64
184
doctype = parse ( <<-INTERNAL_SUBSET )
65
185
<!NOTATION name PUBLIC "public-id-literal" 'system-literal'>
@@ -96,5 +216,66 @@ def test_public_system
96
216
end
97
217
end
98
218
end
219
+
220
+ class TestPublicID < self
221
+ def test_no_literal
222
+ exception = assert_raise ( REXML ::ParseException ) do
223
+ parse ( <<-INTERNAL_SUBSET )
224
+ <!NOTATION name PUBLIC>
225
+ INTERNAL_SUBSET
226
+ end
227
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
228
+ Malformed notation declaration: public ID literal is missing
229
+ Line: 5
230
+ Position: 84
231
+ Last 80 unconsumed characters:
232
+ <!NOTATION name PUBLIC> ]> <r/>
233
+ DETAIL
234
+ end
235
+
236
+ def test_literal_content_double_quote
237
+ exception = assert_raise ( REXML ::ParseException ) do
238
+ parse ( <<-INTERNAL_SUBSET )
239
+ <!NOTATION name PUBLIC 'double quote " is invalid in PubidLiteral'>
240
+ INTERNAL_SUBSET
241
+ end
242
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
243
+ Malformed notation declaration: invalid public ID literal
244
+ Line: 5
245
+ Position: 128
246
+ Last 80 unconsumed characters:
247
+ <!NOTATION name PUBLIC 'double quote \" is invalid in PubidLiteral'> ]> <r/>
248
+ DETAIL
249
+ end
250
+
251
+ def test_garbage_after_literal
252
+ exception = assert_raise ( REXML ::ParseException ) do
253
+ parse ( <<-INTERNAL_SUBSET )
254
+ <!NOTATION name PUBLIC 'public-id-literal'x'>
255
+ INTERNAL_SUBSET
256
+ end
257
+ assert_equal ( <<-DETAIL . chomp , exception . to_s )
258
+ Malformed notation declaration: garbage after public ID literal
259
+ Line: 5
260
+ Position: 106
261
+ Last 80 unconsumed characters:
262
+ <!NOTATION name PUBLIC 'public-id-literal'x'> ]> <r/>
263
+ DETAIL
264
+ end
265
+
266
+ def test_literal_single_quote
267
+ doctype = parse ( <<-INTERNAL_SUBSET )
268
+ <!NOTATION name PUBLIC 'public-id-literal'>
269
+ INTERNAL_SUBSET
270
+ assert_equal ( "public-id-literal" , doctype . notation ( "name" ) . public )
271
+ end
272
+
273
+ def test_literal_double_quote
274
+ doctype = parse ( <<-INTERNAL_SUBSET )
275
+ <!NOTATION name PUBLIC "public-id-literal">
276
+ INTERNAL_SUBSET
277
+ assert_equal ( "public-id-literal" , doctype . notation ( "name" ) . public )
278
+ end
279
+ end
99
280
end
100
281
end
0 commit comments