rgen 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CHANGELOG +20 -1
  2. data/MIT-LICENSE +1 -1
  3. data/README +12 -9
  4. data/lib/instantiators/ea_instantiator.rb +36 -0
  5. data/lib/metamodels/uml13_metamodel.rb +559 -0
  6. data/lib/metamodels/uml13_metamodel_ext.rb +26 -0
  7. data/lib/mmgen/metamodel_generator.rb +5 -5
  8. data/lib/mmgen/mm_ext/ecore_ext.rb +95 -0
  9. data/lib/mmgen/mmgen.rb +6 -4
  10. data/lib/mmgen/templates/annotations.tpl +37 -0
  11. data/lib/mmgen/templates/metamodel_generator.tpl +171 -0
  12. data/lib/rgen/ecore/ecore.rb +190 -0
  13. data/lib/rgen/ecore/ecore_instantiator.rb +25 -0
  14. data/lib/rgen/ecore/ecore_transformer.rb +85 -0
  15. data/lib/rgen/environment.rb +9 -24
  16. data/lib/rgen/find_helper.rb +68 -0
  17. data/lib/rgen/{instantiator.rb → instantiator/abstract_instantiator.rb} +6 -2
  18. data/lib/rgen/instantiator/abstract_xml_instantiator.rb +59 -0
  19. data/lib/rgen/instantiator/default_xml_instantiator.rb +117 -0
  20. data/lib/rgen/instantiator/ecore_xml_instantiator.rb +144 -0
  21. data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +157 -0
  22. data/lib/rgen/instantiator/xmi11_instantiator.rb +164 -0
  23. data/lib/rgen/metamodel_builder.rb +103 -9
  24. data/lib/rgen/metamodel_builder/build_helper.rb +26 -4
  25. data/lib/rgen/metamodel_builder/builder_extensions.rb +285 -88
  26. data/lib/rgen/metamodel_builder/builder_runtime.rb +7 -1
  27. data/lib/rgen/metamodel_builder/data_types.rb +67 -0
  28. data/lib/rgen/metamodel_builder/intermediate/annotation.rb +30 -0
  29. data/lib/rgen/metamodel_builder/metamodel_description.rb +232 -0
  30. data/lib/rgen/metamodel_builder/mm_multiple.rb +23 -0
  31. data/lib/rgen/metamodel_builder/module_extension.rb +33 -0
  32. data/lib/rgen/model_comparator.rb +56 -0
  33. data/lib/rgen/model_dumper.rb +5 -5
  34. data/lib/rgen/name_helper.rb +17 -1
  35. data/lib/rgen/template_language.rb +148 -28
  36. data/lib/rgen/template_language/directory_template_container.rb +56 -38
  37. data/lib/rgen/template_language/output_handler.rb +93 -77
  38. data/lib/rgen/template_language/template_container.rb +186 -143
  39. data/lib/rgen/transformer.rb +19 -14
  40. data/lib/transformers/uml13_to_ecore.rb +75 -0
  41. data/redist/xmlscan/ChangeLog +1301 -0
  42. data/redist/xmlscan/README +34 -0
  43. data/redist/xmlscan/THANKS +11 -0
  44. data/redist/xmlscan/doc/changes.html +74 -0
  45. data/redist/xmlscan/doc/changes.rd +80 -0
  46. data/redist/xmlscan/doc/en/conformance.html +136 -0
  47. data/redist/xmlscan/doc/en/conformance.rd +152 -0
  48. data/redist/xmlscan/doc/en/manual.html +356 -0
  49. data/redist/xmlscan/doc/en/manual.rd +402 -0
  50. data/redist/xmlscan/doc/ja/conformance.ja.html +118 -0
  51. data/redist/xmlscan/doc/ja/conformance.ja.rd +134 -0
  52. data/redist/xmlscan/doc/ja/manual.ja.html +325 -0
  53. data/redist/xmlscan/doc/ja/manual.ja.rd +370 -0
  54. data/redist/xmlscan/doc/src/Makefile +41 -0
  55. data/redist/xmlscan/doc/src/conformance.rd.src +256 -0
  56. data/redist/xmlscan/doc/src/langsplit.rb +110 -0
  57. data/redist/xmlscan/doc/src/manual.rd.src +614 -0
  58. data/redist/xmlscan/install.rb +41 -0
  59. data/redist/xmlscan/lib/xmlscan/encoding.rb +311 -0
  60. data/redist/xmlscan/lib/xmlscan/htmlscan.rb +289 -0
  61. data/redist/xmlscan/lib/xmlscan/namespace.rb +352 -0
  62. data/redist/xmlscan/lib/xmlscan/parser.rb +299 -0
  63. data/redist/xmlscan/lib/xmlscan/scanner.rb +1109 -0
  64. data/redist/xmlscan/lib/xmlscan/version.rb +22 -0
  65. data/redist/xmlscan/lib/xmlscan/visitor.rb +158 -0
  66. data/redist/xmlscan/lib/xmlscan/xmlchar.rb +441 -0
  67. data/redist/xmlscan/memo/CONFORMANCE +1249 -0
  68. data/redist/xmlscan/memo/PRODUCTIONS +195 -0
  69. data/redist/xmlscan/memo/contentspec.ry +335 -0
  70. data/redist/xmlscan/samples/chibixml.rb +105 -0
  71. data/redist/xmlscan/samples/getxmlchar.rb +122 -0
  72. data/redist/xmlscan/samples/rexml.rb +159 -0
  73. data/redist/xmlscan/samples/xmlbench.rb +88 -0
  74. data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +22 -0
  75. data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +29 -0
  76. data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +62 -0
  77. data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +22 -0
  78. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +62 -0
  79. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +22 -0
  80. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +22 -0
  81. data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +99 -0
  82. data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +116 -0
  83. data/redist/xmlscan/samples/xmlconftest.rb +200 -0
  84. data/redist/xmlscan/test.rb +7 -0
  85. data/redist/xmlscan/tests/deftestcase.rb +73 -0
  86. data/redist/xmlscan/tests/runtest.rb +47 -0
  87. data/redist/xmlscan/tests/testall.rb +14 -0
  88. data/redist/xmlscan/tests/testencoding.rb +438 -0
  89. data/redist/xmlscan/tests/testhtmlscan.rb +752 -0
  90. data/redist/xmlscan/tests/testnamespace.rb +457 -0
  91. data/redist/xmlscan/tests/testparser.rb +591 -0
  92. data/redist/xmlscan/tests/testscanner.rb +1749 -0
  93. data/redist/xmlscan/tests/testxmlchar.rb +143 -0
  94. data/redist/xmlscan/tests/visitor.rb +34 -0
  95. data/test/array_extensions_test.rb +2 -2
  96. data/test/ea_instantiator_test.rb +41 -0
  97. data/test/ecore_self_test.rb +53 -0
  98. data/test/environment_test.rb +11 -6
  99. data/test/metamodel_builder_test.rb +404 -245
  100. data/test/metamodel_roundtrip_test.rb +52 -0
  101. data/test/metamodel_roundtrip_test/TestModel.rb +65 -0
  102. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +64 -0
  103. data/test/metamodel_roundtrip_test/houseMetamodel.ecore +32 -0
  104. data/test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb +39 -0
  105. data/test/rgen_test.rb +3 -3
  106. data/test/template_language_test.rb +65 -39
  107. data/test/template_language_test/expected_result.txt +24 -3
  108. data/test/template_language_test/templates/code/array.tpl +11 -0
  109. data/test/template_language_test/templates/content/author.tpl +7 -0
  110. data/test/template_language_test/templates/content/chapter.tpl +1 -1
  111. data/test/template_language_test/templates/root.tpl +17 -8
  112. data/test/template_language_test/testout.txt +24 -3
  113. data/test/testmodel/class_model_checker.rb +119 -0
  114. data/test/{xmi_instantiator_test/testmodel.eap → testmodel/ea_testmodel.eap} +0 -0
  115. data/test/{xmi_instantiator_test/testmodel.xml → testmodel/ea_testmodel.xml} +81 -14
  116. data/test/testmodel/ea_testmodel_partial.xml +317 -0
  117. data/test/testmodel/ecore_model_checker.rb +101 -0
  118. data/test/testmodel/manual_testmodel.xml +22 -0
  119. data/test/testmodel/object_model_checker.rb +67 -0
  120. data/test/transformer_test.rb +18 -10
  121. data/test/xml_instantiator_test.rb +81 -8
  122. data/test/xml_instantiator_test/simple_ecore_model_checker.rb +94 -0
  123. data/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb +53 -0
  124. data/test/xml_instantiator_test/simple_xmi_metamodel.rb +49 -0
  125. data/test/xml_instantiator_test/simple_xmi_to_ecore.rb +75 -0
  126. metadata +126 -28
  127. data/lib/ea/xmi_class_instantiator.rb +0 -46
  128. data/lib/ea/xmi_helper.rb +0 -26
  129. data/lib/ea/xmi_metamodel.rb +0 -34
  130. data/lib/ea/xmi_object_instantiator.rb +0 -46
  131. data/lib/ea/xmi_to_classmodel.rb +0 -78
  132. data/lib/ea/xmi_to_objectmodel.rb +0 -92
  133. data/lib/mmgen/mm_ext/uml_classmodel_ext.rb +0 -71
  134. data/lib/mmgen/templates/uml_classmodel.tpl +0 -63
  135. data/lib/rgen/xml_instantiator.rb +0 -132
  136. data/lib/uml/objectmodel_instantiator.rb +0 -53
  137. data/lib/uml/uml_classmodel.rb +0 -92
  138. data/lib/uml/uml_objectmodel.rb +0 -65
  139. data/test/metamodel_generator_test.rb +0 -44
  140. data/test/metamodel_generator_test/TestModel.rb +0 -40
  141. data/test/metamodel_generator_test/expected_result.txt +0 -40
  142. data/test/xmi_class_instantiator_test.rb +0 -24
  143. data/test/xmi_instantiator_test/class_model_checker.rb +0 -97
  144. data/test/xmi_object_instantiator_test.rb +0 -65
  145. data/test/xml_instantiator_test/testmodel.xml +0 -7
@@ -0,0 +1,1749 @@
1
+ #
2
+ # tests/testscanner.rb
3
+ #
4
+ # Copyright (C) UENO Katsuhiro 2002
5
+ #
6
+ # $Id: testscanner.rb,v 1.35 2003/03/17 02:15:43 katsu Exp $
7
+ #
8
+
9
+ require 'test/unit'
10
+ require 'deftestcase'
11
+ require 'xmlscan/scanner'
12
+ require 'visitor'
13
+
14
+
15
+ class TestVisitor < Test::Unit::TestCase
16
+
17
+ def test_method_defined
18
+ expect = XMLScan::XMLScanner.private_instance_methods.select { |i|
19
+ i == 'parse_error' or i == 'wellformed_error' or
20
+ i == 'valid_error' or i == 'warning' or /\Aon_/ =~ i
21
+ }.sort
22
+ actual = XMLScan::Visitor.instance_methods.sort
23
+ assert_equal expect, actual
24
+ end
25
+
26
+ end
27
+
28
+
29
+
30
+
31
+ class TestXMLScanner < Test::Unit::TestCase
32
+
33
+ include DefTestCase
34
+
35
+ Visitor = RecordingVisitor.new_class(XMLScan::Visitor)
36
+
37
+
38
+ private
39
+
40
+ def setup
41
+ @v = Visitor.new
42
+ @s = XMLScan::XMLScanner.new(@v)
43
+ end
44
+
45
+ def parse(src)
46
+ @s.parse src
47
+ @v.result
48
+ end
49
+
50
+
51
+ public
52
+
53
+ def test_kcode_e
54
+ @s.kcode = 'E'
55
+ assert_equal 'euc', @s.kcode
56
+ end
57
+
58
+ def test_kcode_s
59
+ @s.kcode = 'S'
60
+ assert_equal 'sjis', @s.kcode
61
+ end
62
+
63
+ def test_kcode_u
64
+ @s.kcode = 'U'
65
+ assert_equal 'utf8', @s.kcode
66
+ end
67
+
68
+ def test_kcode_n
69
+ @s.kcode = 'N'
70
+ assert_equal 'none', @s.kcode
71
+ end
72
+
73
+ def test_kcode_nil
74
+ @s.kcode = nil
75
+ assert_equal nil, @s.kcode
76
+ end
77
+
78
+
79
+ def test_lineno_nil
80
+ assert_nil @s.lineno
81
+ end
82
+
83
+ def test_lineno_1
84
+ proc{|i|@v.instance_eval{@s=i}}.call(@s)
85
+ def @v.on_chardata(*)
86
+ @l = @s.lineno
87
+ end
88
+ @s.parse "hoge"
89
+ assert_equal 0, @v.instance_eval{@l}
90
+ assert_equal nil, @s.lineno
91
+ end
92
+
93
+ def test_lineno_2
94
+ s = "hoge"
95
+ def s.lineno
96
+ 123
97
+ end
98
+ proc{|i|@v.instance_eval{@s=i}}.call(@s)
99
+ def @v.on_chardata(*)
100
+ @l = @s.lineno
101
+ end
102
+ @s.parse s
103
+ assert_equal 123, @v.instance_eval{@l}
104
+ assert_equal nil, @s.lineno
105
+ end
106
+
107
+
108
+ def test_path_nil
109
+ assert_nil @s.path
110
+ end
111
+
112
+ def test_path_1
113
+ proc{|i|@v.instance_eval{@s=i}}.call(@s)
114
+ def @v.on_chardata(*)
115
+ @p = @s.path
116
+ end
117
+ @s.parse "hoge"
118
+ assert_equal '-', @v.instance_eval{@p}
119
+ assert_equal nil, @s.path
120
+ end
121
+
122
+ def test_path_2
123
+ s = "hoge"
124
+ def s.path
125
+ 'fuga'
126
+ end
127
+ proc{|i|@v.instance_eval{@s=i}}.call(@s)
128
+ def @v.on_chardata(*)
129
+ @p = @s.path
130
+ end
131
+ @s.parse s
132
+ assert_equal 'fuga', @v.instance_eval{@p}
133
+ assert_equal nil, @s.path
134
+ end
135
+
136
+
137
+ deftestcase 'chardata', <<-'TESTCASEEND'
138
+
139
+ 'hogefuga'
140
+ [ :on_chardata, 'hogefuga' ]
141
+
142
+ 'hoge>fuga'
143
+ [ :on_chardata, 'hoge' ]
144
+ [ :on_chardata, '>fuga' ]
145
+
146
+ '>>hoge>>fuga>>'
147
+ [ :on_chardata, '>' ]
148
+ [ :on_chardata, '>hoge' ]
149
+ [ :on_chardata, '>' ]
150
+ [ :on_chardata, '>fuga' ]
151
+ [ :on_chardata, '>' ]
152
+ [ :on_chardata, '>' ]
153
+
154
+ '>hoge>fuga>'
155
+ [ :on_chardata, '>hoge' ]
156
+ [ :on_chardata, '>fuga' ]
157
+ [ :on_chardata, '>' ]
158
+
159
+ '>'
160
+ [ :on_chardata, '>' ]
161
+
162
+ ''
163
+
164
+ 'hoge&fuga;hoge'
165
+ [ :on_chardata, 'hoge' ]
166
+ [ :on_entityref, 'fuga' ]
167
+ [ :on_chardata, 'hoge' ]
168
+
169
+ '&hoge;fuga&hoge;'
170
+ [ :on_entityref, 'hoge' ]
171
+ [ :on_chardata, 'fuga' ]
172
+ [ :on_entityref, 'hoge' ]
173
+
174
+ 'hoge&#1234;fuga'
175
+ [ :on_chardata, 'hoge' ]
176
+ [ :on_charref, 1234 ]
177
+ [ :on_chardata, 'fuga' ]
178
+
179
+ 'hoge&#x1234;fuga'
180
+ [ :on_chardata, 'hoge' ]
181
+ [ :on_charref_hex, 0x1234 ]
182
+ [ :on_chardata, 'fuga' ]
183
+
184
+ 'hoge&#xasdf;fuga'
185
+ [ :on_chardata, 'hoge' ]
186
+ [ :parse_error, "invalid character reference `#xasdf'" ]
187
+ [ :on_chardata, 'fuga' ]
188
+
189
+ 'hoge&#12ad;fuga'
190
+ [ :on_chardata, 'hoge' ]
191
+ [ :parse_error, "invalid character reference `#12ad'" ]
192
+ [ :on_chardata, 'fuga' ]
193
+
194
+ 'hoge&fuga hoge'
195
+ [ :on_chardata, 'hoge' ]
196
+ [ :parse_error, "reference to `fuga' doesn't end with `;'" ]
197
+ [ :on_entityref, 'fuga' ]
198
+ [ :on_chardata, ' hoge' ]
199
+
200
+ 'hoge&#1234 hoge'
201
+ [ :on_chardata, 'hoge' ]
202
+ [ :parse_error, "reference to `#1234' doesn't end with `;'" ]
203
+ [ :on_charref, 1234 ]
204
+ [ :on_chardata, ' hoge' ]
205
+
206
+ 'hoge&#x1234 hoge'
207
+ [ :on_chardata, 'hoge' ]
208
+ [ :parse_error, "reference to `#x1234' doesn't end with `;'" ]
209
+ [ :on_charref_hex, 0x1234 ]
210
+ [ :on_chardata, ' hoge' ]
211
+
212
+ 'hoge&#fuga hoge'
213
+ [ :on_chardata, 'hoge' ]
214
+ [ :parse_error, "reference to `#fuga' doesn't end with `;'" ]
215
+ [ :parse_error, "invalid character reference `#fuga'" ]
216
+ [ :on_chardata, ' hoge' ]
217
+
218
+ 'hoge&fu ga;hoge'
219
+ [ :on_chardata, 'hoge' ]
220
+ [ :parse_error, "reference to `fu' doesn't end with `;'" ]
221
+ [ :on_entityref, 'fu' ]
222
+ [ :on_chardata, ' ga;hoge' ]
223
+
224
+ 'hoge &#### fuga'
225
+ [ :on_chardata, 'hoge ' ]
226
+ [ :parse_error, "reference to `####' doesn't end with `;'" ]
227
+ [ :parse_error, "invalid character reference `####'" ]
228
+ [ :on_chardata, ' fuga' ]
229
+
230
+ 'hoge & fuga'
231
+ [ :on_chardata, 'hoge ' ]
232
+ [ :parse_error, "`&' is not used for entity/character references" ]
233
+ [ :on_chardata, '& fuga' ]
234
+
235
+ 'hoge &; fuga'
236
+ [ :on_chardata, 'hoge ' ]
237
+ [ :parse_error, "`&' is not used for entity/character references" ]
238
+ [ :on_chardata, '&; fuga' ]
239
+
240
+ 'hoge &! fuga'
241
+ [ :on_chardata, 'hoge ' ]
242
+ [ :parse_error, "`&' is not used for entity/character references" ]
243
+ [ :on_chardata, '&! fuga' ]
244
+
245
+ 'hoge&fu>ga;hoge'
246
+ [ :on_chardata, 'hoge' ]
247
+ [ :parse_error, "reference to `fu' doesn't end with `;'" ]
248
+ [ :on_entityref, 'fu' ]
249
+ [ :on_chardata, '>ga;hoge' ]
250
+
251
+ 'hoge&#12>34;hoge'
252
+ [ :on_chardata, 'hoge' ]
253
+ [ :parse_error, "reference to `#12' doesn't end with `;'" ]
254
+ [ :on_charref, 12 ]
255
+ [ :on_chardata, '>34;hoge' ]
256
+
257
+ TESTCASEEND
258
+
259
+
260
+
261
+ deftestcase 'comment', <<-'TESTCASEEND'
262
+
263
+ '<!-- hogefuga -->'
264
+ [ :on_comment, ' hogefuga ' ]
265
+
266
+ '<!-- hoge<a>fuga -->'
267
+ [ :on_comment, ' hoge<a>fuga ' ]
268
+
269
+ '<!-- hoge<<<>>><<<a>>>fuga -->'
270
+ [ :on_comment, ' hoge<<<>>><<<a>>>fuga ' ]
271
+
272
+ '<!-- hoge-fuga -->'
273
+ [ :on_comment, ' hoge-fuga ' ]
274
+
275
+ '<!-- hogefuga'
276
+ [ :parse_error, 'unterminated comment meets EOF' ]
277
+ [ :on_comment, ' hogefuga' ]
278
+
279
+ '<!-- hoge-fuga -- >'
280
+ [ :parse_error, "comment includes `--'" ]
281
+ [ :parse_error, 'unterminated comment meets EOF' ]
282
+ [ :on_comment, ' hoge-fuga -- >' ]
283
+
284
+ '<!-- hoge--fuga -- >'
285
+ [ :parse_error, "comment includes `--'" ]
286
+ [ :parse_error, "comment includes `--'" ]
287
+ [ :parse_error, 'unterminated comment meets EOF' ]
288
+ [ :on_comment, ' hoge--fuga -- >' ]
289
+
290
+ '<!-- hoge--fuga -->'
291
+ [ :parse_error, "comment includes `--'" ]
292
+ [ :on_comment, ' hoge--fuga ' ]
293
+
294
+ '<!-- hoge--<a>fuga -->'
295
+ [ :parse_error, "comment includes `--'" ]
296
+ [ :on_comment, ' hoge--<a>fuga ' ]
297
+
298
+ '<!-- hoge<--a>fuga -->'
299
+ [ :parse_error, "comment includes `--'" ]
300
+ [ :on_comment, ' hoge<--a>fuga ' ]
301
+
302
+ '<!-- hoge<a>--fuga -->'
303
+ [ :parse_error, "comment includes `--'" ]
304
+ [ :on_comment, ' hoge<a>--fuga ' ]
305
+
306
+ '<!-- hoge--fuga'
307
+ [ :parse_error, "comment includes `--'" ]
308
+ [ :parse_error, 'unterminated comment meets EOF' ]
309
+ [ :on_comment, ' hoge--fuga' ]
310
+
311
+ '<!--- hogefuga --->'
312
+ [ :parse_error, "comment ending in `--->' is not allowed" ]
313
+ [ :on_comment, '- hogefuga -' ]
314
+
315
+ '<!-------->'
316
+ [ :parse_error, "comment includes `--'" ]
317
+ [ :parse_error, "comment includes `--'" ]
318
+ [ :on_comment, '----' ]
319
+
320
+ '<!------->'
321
+ [ :parse_error, "comment includes `--'" ]
322
+ [ :parse_error, "comment ending in `--->' is not allowed" ]
323
+ [ :on_comment, '---' ]
324
+
325
+ '<!------>'
326
+ [ :parse_error, "comment includes `--'" ]
327
+ [ :on_comment, '--' ]
328
+
329
+ '<!----->'
330
+ [ :parse_error, "comment ending in `--->' is not allowed" ]
331
+ [ :on_comment, '-' ]
332
+
333
+ '<!---->'
334
+ [ :on_comment, '' ]
335
+
336
+ '<!--->'
337
+ [ :parse_error, 'unterminated comment meets EOF' ]
338
+ [ :on_comment, '->' ]
339
+
340
+ '<!-->'
341
+ [ :parse_error, 'unterminated comment meets EOF' ]
342
+ [ :on_comment, '>' ]
343
+
344
+ '<!--hoge-->fuga'
345
+ [ :on_comment, 'hoge' ]
346
+ [ :on_chardata, 'fuga' ]
347
+
348
+ '<!--hoge-->>'
349
+ [ :on_comment, 'hoge' ]
350
+ [ :on_chardata, '>' ]
351
+
352
+ '<!--hoge-fuga--->hoge'
353
+ [ :parse_error, "comment ending in `--->' is not allowed" ]
354
+ [ :on_comment, 'hoge-fuga-' ]
355
+ [ :on_chardata, 'hoge' ]
356
+
357
+ '<!--hoge--fuga-->hoge'
358
+ [ :parse_error, "comment includes `--'" ]
359
+ [ :on_comment, 'hoge--fuga' ]
360
+ [ :on_chardata, 'hoge' ]
361
+
362
+ TESTCASEEND
363
+
364
+
365
+
366
+ deftestcase 'pi', <<-'TESTCASEEND'
367
+
368
+ '<?hoge fuga?>'
369
+ [ :on_pi, 'hoge', 'fuga' ]
370
+
371
+ '<?hoge ?>'
372
+ [ :on_pi, 'hoge', '' ]
373
+
374
+ "<?hoge\r?>"
375
+ [ :on_pi, 'hoge', '' ]
376
+
377
+ "<?hoge\f?>"
378
+ [ :on_pi, "hoge\f", '' ]
379
+
380
+ "<?hoge\rfuga?>"
381
+ [ :on_pi, 'hoge', 'fuga' ]
382
+
383
+ "<?hoge\ffuga?>"
384
+ [ :on_pi, "hoge\ffuga", '' ]
385
+
386
+ "<?hoge\f fuga?>"
387
+ [ :on_pi, "hoge\f", 'fuga' ]
388
+
389
+ "<?hoge \ffuga?>"
390
+ [ :on_pi, 'hoge', "\ffuga" ]
391
+
392
+ '<?hoge?>'
393
+ [ :on_pi, 'hoge', '' ]
394
+
395
+ '<?hoge <<>><<<>><<a>> ?>'
396
+ [ :on_pi, 'hoge', '<<>><<<>><<a>> ' ]
397
+
398
+ '<?hoge<?>'
399
+ [ :parse_error, "parse error at `<?'" ]
400
+ [ :on_chardata, '<?hoge' ]
401
+ [ :parse_error, "parse error at `<?'" ]
402
+ [ :on_chardata, '<?>' ]
403
+
404
+ '<?hoge>'
405
+ [ :parse_error, "parse error at `<?'" ]
406
+ [ :on_chardata, '<?hoge>' ]
407
+
408
+ '<? ?>'
409
+ [ :parse_error, "parse error at `<?'" ]
410
+ [ :on_chardata, '<? ?>' ]
411
+
412
+ '<??>'
413
+ [ :parse_error, "parse error at `<?'" ]
414
+ [ :on_chardata, '<??>' ]
415
+
416
+ '<??'
417
+ [ :parse_error, "parse error at `<?'" ]
418
+ [ :on_chardata, '<??' ]
419
+
420
+ '<?'
421
+ [ :parse_error, "parse error at `<?'" ]
422
+ [ :on_chardata, '<?' ]
423
+
424
+ '<?hoge?>fuga'
425
+ [ :on_pi, 'hoge', '' ]
426
+ [ :on_chardata, 'fuga' ]
427
+
428
+ '<?hoge?>>'
429
+ [ :on_pi, 'hoge', '' ]
430
+ [ :on_chardata, '>' ]
431
+
432
+ TESTCASEEND
433
+
434
+
435
+
436
+ deftestcase 'cdata', <<-'TESTCASEEND'
437
+
438
+ '<![CDATA[hogefuga]]>'
439
+ [ :on_cdata, 'hogefuga' ]
440
+
441
+ '<![CDATA[ ]]>'
442
+ [ :on_cdata, ' ' ]
443
+
444
+ '<![CDATA[]]>'
445
+ [ :on_cdata, '' ]
446
+
447
+ '<![CDATA[<<<>>><<<>>><<<a>>>]]>'
448
+ [ :on_cdata, '<<<>>><<<>>><<<a>>>' ]
449
+
450
+ '<![CDATA[< > < > <a>]]>'
451
+ [ :on_cdata, '< > < > <a>' ]
452
+
453
+ '<![CDATA[]]'
454
+ [ :parse_error, "unterminated CDATA section meets EOF" ]
455
+ [ :on_cdata, ']]' ]
456
+
457
+ '<![CDATA[]>'
458
+ [ :parse_error, "unterminated CDATA section meets EOF" ]
459
+ [ :on_cdata, ']>' ]
460
+
461
+ '<![CDATA[>'
462
+ [ :parse_error, "unterminated CDATA section meets EOF" ]
463
+ [ :on_cdata, '>' ]
464
+
465
+ '<![CDATA['
466
+ [ :parse_error, "unterminated CDATA section meets EOF" ]
467
+ [ :on_cdata, '' ]
468
+
469
+ '<![CDATA[hoge]]>fuga'
470
+ [ :on_cdata, 'hoge' ]
471
+ [ :on_chardata, 'fuga' ]
472
+
473
+ '<![CDATA[hoge]]>>'
474
+ [ :on_cdata, 'hoge' ]
475
+ [ :on_chardata, '>' ]
476
+
477
+ TESTCASEEND
478
+
479
+
480
+
481
+ deftestcase 'etag', <<-'TESTCASEEND'
482
+
483
+ '</hoge>'
484
+ [ :on_etag, 'hoge' ]
485
+
486
+ '</hoge >'
487
+ [ :on_etag, 'hoge' ]
488
+
489
+ "</hoge\r>"
490
+ [ :on_etag, 'hoge' ]
491
+
492
+ "</hoge\f>"
493
+ [ :on_etag, "hoge\f" ]
494
+
495
+ '</ hoge>'
496
+ [ :parse_error, "parse error at `</'" ]
497
+ [ :on_chardata, '</ hoge>' ]
498
+
499
+ '</hoge fuga>'
500
+ [ :parse_error, "illegal whitespace is found within end tag `hoge'" ]
501
+ [ :on_etag, 'hoge' ]
502
+
503
+ '</hoge'
504
+ [ :parse_error, "unclosed end tag `hoge' meets EOF" ]
505
+ [ :on_etag, 'hoge' ]
506
+
507
+ '</hoge</fuga>'
508
+ [ :parse_error, "unclosed end tag `hoge' meets another tag" ]
509
+ [ :on_etag, 'hoge' ]
510
+ [ :on_etag, 'fuga' ]
511
+
512
+ '</>'
513
+ [ :parse_error, "parse error at `</'" ]
514
+ [ :on_chardata, '</>' ]
515
+
516
+ '</</'
517
+ [ :parse_error, "parse error at `</'" ]
518
+ [ :on_chardata, '</' ]
519
+ [ :parse_error, "parse error at `</'" ]
520
+ [ :on_chardata, '</' ]
521
+
522
+ '</'
523
+ [ :parse_error, "parse error at `</'" ]
524
+ [ :on_chardata, '</' ]
525
+
526
+ '</hoge>fuga'
527
+ [ :on_etag, 'hoge' ]
528
+ [ :on_chardata, 'fuga' ]
529
+
530
+ '</hoge>>'
531
+ [ :on_etag, 'hoge' ]
532
+ [ :on_chardata, '>' ]
533
+
534
+ '</hoge fuga>hoge'
535
+ [ :parse_error, "illegal whitespace is found within end tag `hoge'" ]
536
+ [ :on_etag, 'hoge' ]
537
+ [ :on_chardata, 'hoge' ]
538
+
539
+ '</hoge</fuga>hoge'
540
+ [ :parse_error, "unclosed end tag `hoge' meets another tag" ]
541
+ [ :on_etag, 'hoge' ]
542
+ [ :on_etag, 'fuga' ]
543
+ [ :on_chardata, 'hoge' ]
544
+
545
+ '</hoge</fuga>>'
546
+ [ :parse_error, "unclosed end tag `hoge' meets another tag" ]
547
+ [ :on_etag, 'hoge' ]
548
+ [ :on_etag, 'fuga' ]
549
+ [ :on_chardata, '>' ]
550
+
551
+ '</>hoge'
552
+ [ :parse_error, "parse error at `</'" ]
553
+ [ :on_chardata, '</>' ]
554
+ [ :on_chardata, 'hoge' ]
555
+
556
+ TESTCASEEND
557
+
558
+
559
+
560
+ deftestcase 'stag', <<-'TESTCASEEND'
561
+
562
+ '<hoge>'
563
+ [ :on_stag, 'hoge' ]
564
+ [ :on_stag_end, 'hoge' ]
565
+
566
+ '<hoge >'
567
+ [ :on_stag, 'hoge' ]
568
+ [ :on_stag_end, 'hoge' ]
569
+
570
+ "<hoge\r >"
571
+ [ :on_stag, 'hoge' ]
572
+ [ :on_stag_end, 'hoge' ]
573
+
574
+ "<hoge\f >"
575
+ [ :on_stag, "hoge\f" ]
576
+ [ :on_stag_end, "hoge\f" ]
577
+
578
+ '<hoge'
579
+ [ :on_stag, 'hoge' ]
580
+ [ :parse_error, "unclosed start tag `hoge' meets EOF" ]
581
+ [ :on_stag_end, 'hoge' ]
582
+
583
+ '<hoge<fuga>'
584
+ [ :on_stag, 'hoge' ]
585
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
586
+ [ :on_stag_end, 'hoge' ]
587
+ [ :on_stag, 'fuga' ]
588
+ [ :on_stag_end, 'fuga' ]
589
+
590
+ '<hoge <fuga>'
591
+ [ :on_stag, 'hoge' ]
592
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
593
+ [ :on_stag_end, 'hoge' ]
594
+ [ :on_stag, 'fuga' ]
595
+ [ :on_stag_end, 'fuga' ]
596
+
597
+ '< hoge>'
598
+ [ :parse_error, "parse error at `<'" ]
599
+ [ :on_chardata, '< hoge>' ]
600
+
601
+ '<hoge/>'
602
+ [ :on_stag, 'hoge' ]
603
+ [ :on_stag_end_empty, 'hoge' ]
604
+
605
+ '<hoge />'
606
+ [ :on_stag, 'hoge' ]
607
+ [ :on_stag_end_empty, 'hoge' ]
608
+
609
+ '<hoge/'
610
+ [ :on_stag, 'hoge' ]
611
+ [ :parse_error, "unclosed empty element tag `hoge' meets EOF" ]
612
+ [ :on_stag_end_empty, 'hoge' ]
613
+
614
+ '<hoge/<fuga/>'
615
+ [ :on_stag, 'hoge' ]
616
+ [ :parse_error, "unclosed empty element tag `hoge' meets another tag" ]
617
+ [ :on_stag_end_empty, 'hoge' ]
618
+ [ :on_stag, 'fuga' ]
619
+ [ :on_stag_end_empty, 'fuga' ]
620
+
621
+ '<hoge /<fuga>'
622
+ [ :on_stag, 'hoge' ]
623
+ [ :parse_error, "unclosed empty element tag `hoge' meets another tag" ]
624
+ [ :on_stag_end_empty, 'hoge' ]
625
+ [ :on_stag, 'fuga' ]
626
+ [ :on_stag_end, 'fuga' ]
627
+
628
+ '< hoge />'
629
+ [ :parse_error, "parse error at `<'" ]
630
+ [ :on_chardata, '< hoge />' ]
631
+
632
+ '<hoge/ >'
633
+ [ :on_stag, 'hoge' ]
634
+ [ :parse_error, "parse error at `/'" ]
635
+ [ :on_stag_end, 'hoge' ]
636
+
637
+ '<hoge= >'
638
+ [ :on_stag, 'hoge' ]
639
+ [ :parse_error, "parse error at `='" ]
640
+ [ :on_stag_end, 'hoge' ]
641
+
642
+ '<=hoge >'
643
+ [ :parse_error, "parse error at `<'" ]
644
+ [ :on_chardata, '<=hoge >' ]
645
+
646
+ '< =hoge >'
647
+ [ :parse_error, "parse error at `<'" ]
648
+ [ :on_chardata, '< =hoge >' ]
649
+
650
+ '<hoge>fuga'
651
+ [ :on_stag, 'hoge' ]
652
+ [ :on_stag_end, 'hoge' ]
653
+ [ :on_chardata, 'fuga' ]
654
+
655
+ '<hoge>>'
656
+ [ :on_stag, 'hoge' ]
657
+ [ :on_stag_end, 'hoge' ]
658
+ [ :on_chardata, '>' ]
659
+
660
+ '<hoge/>fuga'
661
+ [ :on_stag, 'hoge' ]
662
+ [ :on_stag_end_empty, 'hoge' ]
663
+ [ :on_chardata, 'fuga' ]
664
+
665
+ '<hoge/>>'
666
+ [ :on_stag, 'hoge' ]
667
+ [ :on_stag_end_empty, 'hoge' ]
668
+ [ :on_chardata, '>' ]
669
+
670
+ '< hoge>fuga'
671
+ [ :parse_error, "parse error at `<'" ]
672
+ [ :on_chardata, '< hoge>' ]
673
+ [ :on_chardata, 'fuga' ]
674
+
675
+ '< hoge>>'
676
+ [ :parse_error, "parse error at `<'" ]
677
+ [ :on_chardata, '< hoge>' ]
678
+ [ :on_chardata, '>' ]
679
+
680
+ '<hoge/ >fuga'
681
+ [ :on_stag, 'hoge' ]
682
+ [ :parse_error, "parse error at `/'" ]
683
+ [ :on_stag_end, 'hoge' ]
684
+ [ :on_chardata, 'fuga' ]
685
+
686
+ '<hoge/ >>'
687
+ [ :on_stag, 'hoge' ]
688
+ [ :parse_error, "parse error at `/'" ]
689
+ [ :on_stag_end, 'hoge' ]
690
+ [ :on_chardata, '>' ]
691
+
692
+ '<>'
693
+ [ :parse_error, "parse error at `<'" ]
694
+ [ :on_chardata, '<>' ]
695
+
696
+ '<'
697
+ [ :parse_error, "parse error at `<'" ]
698
+ [ :on_chardata, '<' ]
699
+
700
+
701
+ TESTCASEEND
702
+
703
+
704
+
705
+ deftestcase 'attribute', <<-'TESTCASEEND'
706
+
707
+ '<hoge foo="bar">'
708
+ [ :on_stag, 'hoge' ]
709
+ [ :on_attribute, 'foo' ]
710
+ [ :on_attr_value, 'bar' ]
711
+ [ :on_attribute_end, 'foo' ]
712
+ [ :on_stag_end, 'hoge' ]
713
+
714
+ '<hoge foo="">'
715
+ [ :on_stag, 'hoge' ]
716
+ [ :on_attribute, 'foo' ]
717
+ [ :on_attribute_end, 'foo' ]
718
+ [ :on_stag_end, 'hoge' ]
719
+
720
+ "<hoge foo = 'bar' HOGE = 'FUGA' >"
721
+ [ :on_stag, 'hoge' ]
722
+ [ :on_attribute, 'foo' ]
723
+ [ :on_attr_value, 'bar' ]
724
+ [ :on_attribute_end, 'foo' ]
725
+ [ :on_attribute, 'HOGE' ]
726
+ [ :on_attr_value, 'FUGA' ]
727
+ [ :on_attribute_end, 'HOGE' ]
728
+ [ :on_stag_end, 'hoge' ]
729
+
730
+ '<hoge foo="bar"/>'
731
+ [ :on_stag, 'hoge' ]
732
+ [ :on_attribute, 'foo' ]
733
+ [ :on_attr_value, 'bar' ]
734
+ [ :on_attribute_end, 'foo' ]
735
+ [ :on_stag_end_empty, 'hoge' ]
736
+
737
+ "<hoge foo = ' bar ' />"
738
+ [ :on_stag, 'hoge' ]
739
+ [ :on_attribute, 'foo' ]
740
+ [ :on_attr_value, ' bar ' ]
741
+ [ :on_attribute_end, 'foo' ]
742
+ [ :on_stag_end_empty, 'hoge' ]
743
+
744
+ "<hoge foo\r=\r'bar'/>"
745
+ [ :on_stag, 'hoge' ]
746
+ [ :on_attribute, 'foo' ]
747
+ [ :on_attr_value, 'bar' ]
748
+ [ :on_attribute_end, 'foo' ]
749
+ [ :on_stag_end_empty, 'hoge' ]
750
+
751
+ "<hoge foo\f=\f'bar'/>"
752
+ [ :on_stag, 'hoge' ]
753
+ [ :parse_error, "parse error at `foo\f'" ]
754
+ [ :parse_error, "parse error at `='" ]
755
+ [ :parse_error, "parse error at `\f'" ]
756
+ [ :parse_error, "parse error at `''" ]
757
+ [ :parse_error, "parse error at `bar'" ]
758
+ [ :parse_error, "parse error at `''" ]
759
+ [ :on_stag_end_empty, 'hoge' ]
760
+
761
+ "<hoge\ffoo='bar'/>"
762
+ [ :on_stag, "hoge\ffoo" ]
763
+ [ :parse_error, "parse error at `='" ]
764
+ [ :parse_error, "parse error at `''" ]
765
+ [ :parse_error, "parse error at `bar'" ]
766
+ [ :parse_error, "parse error at `''" ]
767
+ [ :on_stag_end_empty, "hoge\ffoo" ]
768
+
769
+ '<hoge foo="bar" / >'
770
+ [ :on_stag, 'hoge' ]
771
+ [ :on_attribute, 'foo' ]
772
+ [ :on_attr_value, 'bar' ]
773
+ [ :on_attribute_end, 'foo' ]
774
+ [ :parse_error, "parse error at `/'" ]
775
+ [ :on_stag_end, 'hoge' ]
776
+
777
+ '<hoge foo="b>a>b>c>ar">'
778
+ [ :on_stag, 'hoge' ]
779
+ [ :on_attribute, 'foo' ]
780
+ [ :on_attr_value, 'b' ]
781
+ [ :on_attr_value, '>' ]
782
+ [ :on_attr_value, 'a' ]
783
+ [ :on_attr_value, '>' ]
784
+ [ :on_attr_value, 'b' ]
785
+ [ :on_attr_value, '>' ]
786
+ [ :on_attr_value, 'c' ]
787
+ [ :on_attr_value, '>' ]
788
+ [ :on_attr_value, 'ar' ]
789
+ [ :on_attribute_end, 'foo' ]
790
+ [ :on_stag_end, 'hoge' ]
791
+
792
+ '<hoge foo="b>>a>>b>>c>>ar" HOGE="FUGA">'
793
+ [ :on_stag, 'hoge' ]
794
+ [ :on_attribute, 'foo' ]
795
+ [ :on_attr_value, 'b' ]
796
+ [ :on_attr_value, '>' ]
797
+ [ :on_attr_value, '>' ]
798
+ [ :on_attr_value, 'a' ]
799
+ [ :on_attr_value, '>' ]
800
+ [ :on_attr_value, '>' ]
801
+ [ :on_attr_value, 'b' ]
802
+ [ :on_attr_value, '>' ]
803
+ [ :on_attr_value, '>' ]
804
+ [ :on_attr_value, 'c' ]
805
+ [ :on_attr_value, '>' ]
806
+ [ :on_attr_value, '>' ]
807
+ [ :on_attr_value, 'ar' ]
808
+ [ :on_attribute_end, 'foo' ]
809
+ [ :on_attribute, 'HOGE' ]
810
+ [ :on_attr_value, 'FUGA' ]
811
+ [ :on_attribute_end, 'HOGE' ]
812
+ [ :on_stag_end, 'hoge' ]
813
+
814
+ '<hoge foo="b<a>b<c>ar">'
815
+ [ :on_stag, 'hoge' ]
816
+ [ :on_attribute, 'foo' ]
817
+ [ :on_attr_value, 'b' ]
818
+ [ :wellformed_error, "`<' is found in attribute `foo'" ]
819
+ [ :on_attr_value, '<a' ]
820
+ [ :on_attr_value, '>' ]
821
+ [ :on_attr_value, 'b' ]
822
+ [ :wellformed_error, "`<' is found in attribute `foo'" ]
823
+ [ :on_attr_value, '<c' ]
824
+ [ :on_attr_value, '>' ]
825
+ [ :on_attr_value, 'ar' ]
826
+ [ :on_attribute_end, 'foo' ]
827
+ [ :on_stag_end, 'hoge' ]
828
+
829
+ '<hoge foo="bar"<fuga>'
830
+ [ :on_stag, 'hoge' ]
831
+ [ :on_attribute, 'foo' ]
832
+ [ :on_attr_value, 'bar' ]
833
+ [ :on_attribute_end, 'foo' ]
834
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
835
+ [ :on_stag_end, 'hoge' ]
836
+ [ :on_stag, 'fuga' ]
837
+ [ :on_stag_end, 'fuga' ]
838
+
839
+ '<hoge foo="bar"'
840
+ [ :on_stag, 'hoge' ]
841
+ [ :on_attribute, 'foo' ]
842
+ [ :on_attr_value, 'bar' ]
843
+ [ :on_attribute_end, 'foo' ]
844
+ [ :parse_error, "unclosed start tag `hoge' meets EOF" ]
845
+ [ :on_stag_end, 'hoge' ]
846
+
847
+ '<hoge foo=bar>'
848
+ [ :on_stag, 'hoge' ]
849
+ [ :parse_error, "parse error at `foo'" ]
850
+ [ :parse_error, "parse error at `='" ]
851
+ [ :parse_error, "parse error at `bar'" ]
852
+ [ :on_stag_end, 'hoge' ]
853
+
854
+ '<hoge foo = bar >'
855
+ [ :on_stag, 'hoge' ]
856
+ [ :parse_error, "parse error at `foo'" ]
857
+ [ :parse_error, "parse error at `='" ]
858
+ [ :parse_error, "parse error at `bar'" ]
859
+ [ :on_stag_end, 'hoge' ]
860
+
861
+ '<hoge foo = bar&fuga;bar >'
862
+ [ :on_stag, 'hoge' ]
863
+ [ :parse_error, "parse error at `foo'" ]
864
+ [ :parse_error, "parse error at `='" ]
865
+ [ :parse_error, "parse error at `bar&fuga;bar'" ]
866
+ [ :on_stag_end, 'hoge' ]
867
+
868
+ '<hoge foo = bar<fuga >'
869
+ [ :on_stag, 'hoge' ]
870
+ [ :parse_error, "parse error at `foo'" ]
871
+ [ :parse_error, "parse error at `='" ]
872
+ [ :parse_error, "parse error at `bar'" ]
873
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
874
+ [ :on_stag_end, 'hoge' ]
875
+ [ :on_stag, 'fuga' ]
876
+ [ :on_stag_end, 'fuga' ]
877
+
878
+ '<hoge foo= >'
879
+ [ :on_stag, 'hoge' ]
880
+ [ :parse_error, "parse error at `foo'" ]
881
+ [ :parse_error, "parse error at `='" ]
882
+ [ :on_stag_end, 'hoge' ]
883
+
884
+ '<hoge foo>'
885
+ [ :on_stag, 'hoge' ]
886
+ [ :parse_error, "parse error at `foo'" ]
887
+ [ :on_stag_end, 'hoge' ]
888
+
889
+ '<hoge foo="bar"HOGE ="FUGA">'
890
+ [ :on_stag, 'hoge' ]
891
+ [ :on_attribute, 'foo' ]
892
+ [ :on_attr_value, 'bar' ]
893
+ [ :on_attribute_end, 'foo' ]
894
+ [ :parse_error, "parse error at `HOGE'" ]
895
+ [ :parse_error, "parse error at `='" ]
896
+ [ :parse_error, "parse error at `\"'" ]
897
+ [ :parse_error, "parse error at `FUGA'" ]
898
+ [ :parse_error, "parse error at `\"'" ]
899
+ [ :on_stag_end, 'hoge' ]
900
+
901
+ '<hoge foo="bar"=fuga >'
902
+ [ :on_stag, 'hoge' ]
903
+ [ :on_attribute, 'foo' ]
904
+ [ :on_attr_value, 'bar' ]
905
+ [ :on_attribute_end, 'foo' ]
906
+ [ :parse_error, "parse error at `='" ]
907
+ [ :parse_error, "parse error at `fuga'" ]
908
+ [ :on_stag_end, 'hoge' ]
909
+
910
+ '<hoge foo="bar>'
911
+ [ :on_stag, 'hoge' ]
912
+ [ :on_attribute, 'foo' ]
913
+ [ :on_attr_value, 'bar' ]
914
+ [ :on_attr_value, '>' ]
915
+ [ :parse_error, "unterminated attribute `foo' meets EOF" ]
916
+ [ :on_attribute_end, 'foo' ]
917
+ [ :parse_error, "unclosed start tag `hoge' meets EOF" ]
918
+ [ :on_stag_end, 'hoge' ]
919
+
920
+ '<hoge="fuga">'
921
+ [ :on_stag, 'hoge' ]
922
+ [ :parse_error, "parse error at `='" ]
923
+ [ :parse_error, "parse error at `\"'" ]
924
+ [ :parse_error, "parse error at `fuga'" ]
925
+ [ :parse_error, "parse error at `\"'" ]
926
+ [ :on_stag_end, 'hoge' ]
927
+
928
+ '<hoge"fuga">'
929
+ [ :on_stag, 'hoge' ]
930
+ [ :parse_error, "parse error at `\"'" ]
931
+ [ :parse_error, "parse error at `fuga'" ]
932
+ [ :parse_error, "parse error at `\"'" ]
933
+ [ :on_stag_end, 'hoge' ]
934
+
935
+ "<hoge foo\r\n\r\nbar='fuga'>"
936
+ [ :on_stag, 'hoge' ]
937
+ [ :parse_error, "parse error at `foo'" ]
938
+ [ :on_attribute, 'bar' ]
939
+ [ :on_attr_value, 'fuga' ]
940
+ [ :on_attribute_end, 'bar' ]
941
+ [ :on_stag_end, 'hoge' ]
942
+
943
+
944
+ '<hoge foo="hoge&fuga;hoge">'
945
+ [ :on_stag, 'hoge' ]
946
+ [ :on_attribute, 'foo' ]
947
+ [ :on_attr_value, 'hoge' ]
948
+ [ :on_attr_entityref, 'fuga' ]
949
+ [ :on_attr_value, 'hoge' ]
950
+ [ :on_attribute_end, 'foo' ]
951
+ [ :on_stag_end, 'hoge' ]
952
+
953
+ '<hoge foo="&hoge;fuga&hoge;">'
954
+ [ :on_stag, 'hoge' ]
955
+ [ :on_attribute, 'foo' ]
956
+ [ :on_attr_entityref, 'hoge' ]
957
+ [ :on_attr_value, 'fuga' ]
958
+ [ :on_attr_entityref, 'hoge' ]
959
+ [ :on_attribute_end, 'foo' ]
960
+ [ :on_stag_end, 'hoge' ]
961
+
962
+ '<hoge foo="hoge&#1234;fuga">'
963
+ [ :on_stag, 'hoge' ]
964
+ [ :on_attribute, 'foo' ]
965
+ [ :on_attr_value, 'hoge' ]
966
+ [ :on_attr_charref, 1234 ]
967
+ [ :on_attr_value, 'fuga' ]
968
+ [ :on_attribute_end, 'foo' ]
969
+ [ :on_stag_end, 'hoge' ]
970
+
971
+ '<hoge foo="hoge&#x1234;fuga">'
972
+ [ :on_stag, 'hoge' ]
973
+ [ :on_attribute, 'foo' ]
974
+ [ :on_attr_value, 'hoge' ]
975
+ [ :on_attr_charref_hex, 0x1234 ]
976
+ [ :on_attr_value, 'fuga' ]
977
+ [ :on_attribute_end, 'foo' ]
978
+ [ :on_stag_end, 'hoge' ]
979
+
980
+ '<hoge foo="hoge&#xasdf;fuga">'
981
+ [ :on_stag, 'hoge' ]
982
+ [ :on_attribute, 'foo' ]
983
+ [ :on_attr_value, 'hoge' ]
984
+ [ :parse_error, "invalid character reference `#xasdf'" ]
985
+ [ :on_attr_value, 'fuga' ]
986
+ [ :on_attribute_end, 'foo' ]
987
+ [ :on_stag_end, 'hoge' ]
988
+
989
+ '<hoge foo="hoge&#12ad;fuga">'
990
+ [ :on_stag, 'hoge' ]
991
+ [ :on_attribute, 'foo' ]
992
+ [ :on_attr_value, 'hoge' ]
993
+ [ :parse_error, "invalid character reference `#12ad'" ]
994
+ [ :on_attr_value, 'fuga' ]
995
+ [ :on_attribute_end, 'foo' ]
996
+ [ :on_stag_end, 'hoge' ]
997
+
998
+ '<hoge foo="hoge&fuga hoge">'
999
+ [ :on_stag, 'hoge' ]
1000
+ [ :on_attribute, 'foo' ]
1001
+ [ :on_attr_value, 'hoge' ]
1002
+ [ :parse_error, "reference to `fuga' doesn't end with `;'" ]
1003
+ [ :on_attr_entityref, 'fuga' ]
1004
+ [ :on_attr_value, ' hoge' ]
1005
+ [ :on_attribute_end, 'foo' ]
1006
+ [ :on_stag_end, 'hoge' ]
1007
+
1008
+ '<hoge foo="hoge&fu ga;hoge">'
1009
+ [ :on_stag, 'hoge' ]
1010
+ [ :on_attribute, 'foo' ]
1011
+ [ :on_attr_value, 'hoge' ]
1012
+ [ :parse_error, "reference to `fu' doesn't end with `;'" ]
1013
+ [ :on_attr_entityref, 'fu' ]
1014
+ [ :on_attr_value, ' ga;hoge' ]
1015
+ [ :on_attribute_end, 'foo' ]
1016
+ [ :on_stag_end, 'hoge' ]
1017
+
1018
+ '<hoge foo="hoge&#1234 hoge">'
1019
+ [ :on_stag, 'hoge' ]
1020
+ [ :on_attribute, 'foo' ]
1021
+ [ :on_attr_value, 'hoge' ]
1022
+ [ :parse_error, "reference to `#1234' doesn't end with `;'" ]
1023
+ [ :on_attr_charref, 1234 ]
1024
+ [ :on_attr_value, ' hoge' ]
1025
+ [ :on_attribute_end, 'foo' ]
1026
+ [ :on_stag_end, 'hoge' ]
1027
+
1028
+ '<hoge foo="hoge&#x1234 hoge">'
1029
+ [ :on_stag, 'hoge' ]
1030
+ [ :on_attribute, 'foo' ]
1031
+ [ :on_attr_value, 'hoge' ]
1032
+ [ :parse_error, "reference to `#x1234' doesn't end with `;'" ]
1033
+ [ :on_attr_charref_hex, 0x1234 ]
1034
+ [ :on_attr_value, ' hoge' ]
1035
+ [ :on_attribute_end, 'foo' ]
1036
+ [ :on_stag_end, 'hoge' ]
1037
+
1038
+ '<hoge foo="hoge&#fuga hoge">'
1039
+ [ :on_stag, 'hoge' ]
1040
+ [ :on_attribute, 'foo' ]
1041
+ [ :on_attr_value, 'hoge' ]
1042
+ [ :parse_error, "reference to `#fuga' doesn't end with `;'" ]
1043
+ [ :parse_error, "invalid character reference `#fuga'" ]
1044
+ [ :on_attr_value, ' hoge' ]
1045
+ [ :on_attribute_end, 'foo' ]
1046
+ [ :on_stag_end, 'hoge' ]
1047
+
1048
+ '<hoge foo="hoge &#### fuga">'
1049
+ [ :on_stag, 'hoge' ]
1050
+ [ :on_attribute, 'foo' ]
1051
+ [ :on_attr_value, 'hoge ' ]
1052
+ [ :parse_error, "reference to `####' doesn't end with `;'" ]
1053
+ [ :parse_error, "invalid character reference `####'" ]
1054
+ [ :on_attr_value, ' fuga' ]
1055
+ [ :on_attribute_end, 'foo' ]
1056
+ [ :on_stag_end, 'hoge' ]
1057
+
1058
+ '<hoge foo="hoge & fuga">'
1059
+ [ :on_stag, 'hoge' ]
1060
+ [ :on_attribute, 'foo' ]
1061
+ [ :on_attr_value, 'hoge ' ]
1062
+ [ :parse_error, "`&' is not used for entity/character references" ]
1063
+ [ :on_attr_value, '& fuga' ]
1064
+ [ :on_attribute_end, 'foo' ]
1065
+ [ :on_stag_end, 'hoge' ]
1066
+
1067
+ '<hoge foo="hoge &; fuga">'
1068
+ [ :on_stag, 'hoge' ]
1069
+ [ :on_attribute, 'foo' ]
1070
+ [ :on_attr_value, 'hoge ' ]
1071
+ [ :parse_error, "`&' is not used for entity/character references" ]
1072
+ [ :on_attr_value, '&; fuga' ]
1073
+ [ :on_attribute_end, 'foo' ]
1074
+ [ :on_stag_end, 'hoge' ]
1075
+
1076
+ '<hoge foo="hoge &! fuga">'
1077
+ [ :on_stag, 'hoge' ]
1078
+ [ :on_attribute, 'foo' ]
1079
+ [ :on_attr_value, 'hoge ' ]
1080
+ [ :parse_error, "`&' is not used for entity/character references" ]
1081
+ [ :on_attr_value, '&! fuga' ]
1082
+ [ :on_attribute_end, 'foo' ]
1083
+ [ :on_stag_end, 'hoge' ]
1084
+
1085
+ '<hoge foo="hoge&fu>ga;hoge">'
1086
+ [ :on_stag, 'hoge' ]
1087
+ [ :on_attribute, 'foo' ]
1088
+ [ :on_attr_value, 'hoge' ]
1089
+ [ :parse_error, "reference to `fu' doesn't end with `;'" ]
1090
+ [ :on_attr_entityref, 'fu' ]
1091
+ [ :on_attr_value, '>' ]
1092
+ [ :on_attr_value, 'ga;hoge' ]
1093
+ [ :on_attribute_end, 'foo' ]
1094
+ [ :on_stag_end, 'hoge' ]
1095
+
1096
+ '<hoge foo="hoge&#12>34;hoge">'
1097
+ [ :on_stag, 'hoge' ]
1098
+ [ :on_attribute, 'foo' ]
1099
+ [ :on_attr_value, 'hoge' ]
1100
+ [ :parse_error, "reference to `#12' doesn't end with `;'" ]
1101
+ [ :on_attr_charref, 12 ]
1102
+ [ :on_attr_value, '>' ]
1103
+ [ :on_attr_value, '34;hoge' ]
1104
+ [ :on_attribute_end, 'foo' ]
1105
+ [ :on_stag_end, 'hoge' ]
1106
+
1107
+ TESTCASEEND
1108
+
1109
+
1110
+
1111
+ deftestcase 'bang_tag', <<-'TESTCASEEND'
1112
+
1113
+ '<!hoge>'
1114
+ [ :parse_error, "parse error at `<!'" ]
1115
+ [ :on_chardata, '<!hoge>' ]
1116
+
1117
+ '<!hoge fuga>'
1118
+ [ :parse_error, "parse error at `<!'" ]
1119
+ [ :on_chardata, '<!hoge fuga>' ]
1120
+
1121
+ '<!hoge'
1122
+ [ :parse_error, "parse error at `<!'" ]
1123
+ [ :on_chardata, '<!hoge' ]
1124
+
1125
+ '<!>'
1126
+ [ :parse_error, "parse error at `<!'" ]
1127
+ [ :on_chardata, '<!>' ]
1128
+
1129
+ '<!'
1130
+ [ :parse_error, "parse error at `<!'" ]
1131
+ [ :on_chardata, '<!' ]
1132
+
1133
+ '<!hoge>fuga'
1134
+ [ :parse_error, "parse error at `<!'" ]
1135
+ [ :on_chardata, '<!hoge>' ]
1136
+ [ :on_chardata, 'fuga' ]
1137
+
1138
+ '<!hoge>>'
1139
+ [ :parse_error, "parse error at `<!'" ]
1140
+ [ :on_chardata, '<!hoge>' ]
1141
+ [ :on_chardata, '>' ]
1142
+
1143
+ TESTCASEEND
1144
+
1145
+
1146
+
1147
+ deftestcase 'xmldecl', <<-'TESTCASEEND'
1148
+
1149
+ '<?xml version="1.0"?>'
1150
+ [ :on_xmldecl ]
1151
+ [ :on_xmldecl_version, '1.0' ]
1152
+ [ :on_xmldecl_end ]
1153
+
1154
+ "<?xml version='1.0'?>"
1155
+ [ :on_xmldecl ]
1156
+ [ :on_xmldecl_version, '1.0' ]
1157
+ [ :on_xmldecl_end ]
1158
+
1159
+ '<?xml version = "1.0" ?>'
1160
+ [ :on_xmldecl ]
1161
+ [ :on_xmldecl_version, '1.0' ]
1162
+ [ :on_xmldecl_end ]
1163
+
1164
+ "<?xml version\f=\f'1.0' ?>"
1165
+ [ :on_xmldecl ]
1166
+ [ :parse_error, "parse error at `version'" ]
1167
+ [ :parse_error, "parse error at `\f'" ]
1168
+ [ :parse_error, "parse error at `='" ]
1169
+ [ :parse_error, "parse error at `\f'" ]
1170
+ [ :parse_error, "parse error at `''" ]
1171
+ [ :parse_error, "parse error at `1.0'" ]
1172
+ [ :parse_error, "parse error at `''" ]
1173
+ [ :parse_error, "no declaration found in XML declaration" ]
1174
+ [ :on_xmldecl_end ]
1175
+
1176
+ '<?xml version="" ?>'
1177
+ [ :on_xmldecl ]
1178
+ [ :on_xmldecl_version, '' ]
1179
+ [ :on_xmldecl_end ]
1180
+
1181
+ '<?xml version="1<0" ?>'
1182
+ [ :on_xmldecl ]
1183
+ [ :on_xmldecl_version, '1<0' ]
1184
+ [ :on_xmldecl_end ]
1185
+
1186
+ '<?xml version="1>0" ?>'
1187
+ [ :on_xmldecl ]
1188
+ [ :on_xmldecl_version, '1>0' ]
1189
+ [ :on_xmldecl_end ]
1190
+
1191
+ '<?xml version="1<<>><<a>>0" ?>'
1192
+ [ :on_xmldecl ]
1193
+ [ :on_xmldecl_version, '1<<>><<a>>0' ]
1194
+ [ :on_xmldecl_end ]
1195
+
1196
+ '<?xml version="1.0" encoding="euc-jp"?>'
1197
+ [ :on_xmldecl ]
1198
+ [ :on_xmldecl_version, '1.0' ]
1199
+ [ :on_xmldecl_encoding, 'euc-jp' ]
1200
+ [ :on_xmldecl_end ]
1201
+
1202
+ '<?xml version="1.0" standalone="yes" ?>'
1203
+ [ :on_xmldecl ]
1204
+ [ :on_xmldecl_version, '1.0' ]
1205
+ [ :on_xmldecl_standalone, 'yes' ]
1206
+ [ :on_xmldecl_end ]
1207
+
1208
+ '<?xml version="1.0" encoding="euc-jp" standalone="yes" ?>'
1209
+ [ :on_xmldecl ]
1210
+ [ :on_xmldecl_version, '1.0' ]
1211
+ [ :on_xmldecl_encoding, 'euc-jp' ]
1212
+ [ :on_xmldecl_standalone, 'yes' ]
1213
+ [ :on_xmldecl_end ]
1214
+
1215
+ '<?xml version="1.0" encoding="euc-jp"?>'
1216
+ [ :on_xmldecl ]
1217
+ [ :on_xmldecl_version, '1.0' ]
1218
+ [ :on_xmldecl_encoding, 'euc-jp' ]
1219
+ [ :on_xmldecl_end ]
1220
+
1221
+ '<?xml version="1.0" standalone="yes" encoding="euc-jp"?>'
1222
+ [ :on_xmldecl ]
1223
+ [ :on_xmldecl_version, '1.0' ]
1224
+ [ :on_xmldecl_standalone, 'yes' ]
1225
+ [ :parse_error, "encoding declaration must not be here" ]
1226
+ [ :on_xmldecl_encoding, 'euc-jp' ]
1227
+ [ :on_xmldecl_end ]
1228
+
1229
+ '<?xml version="1.0" standalone="yes" ?>'
1230
+ [ :on_xmldecl ]
1231
+ [ :on_xmldecl_version, '1.0' ]
1232
+ [ :on_xmldecl_standalone, 'yes' ]
1233
+ [ :on_xmldecl_end ]
1234
+
1235
+ '<?xml version="1.0" version="1.0" ?>'
1236
+ [ :on_xmldecl ]
1237
+ [ :on_xmldecl_version, '1.0' ]
1238
+ [ :parse_error, "version declaration must not be here" ]
1239
+ [ :on_xmldecl_version, '1.0' ]
1240
+ [ :on_xmldecl_end ]
1241
+
1242
+ '<?xml encoding="euc-jp" version="1.0" ?>'
1243
+ [ :on_xmldecl ]
1244
+ [ :parse_error, "encoding declaration must not be here" ]
1245
+ [ :on_xmldecl_encoding, 'euc-jp' ]
1246
+ [ :parse_error, "version declaration must not be here" ]
1247
+ [ :on_xmldecl_version, '1.0' ]
1248
+ [ :on_xmldecl_end ]
1249
+
1250
+ '<?xml encoding="euc-jp" standalone="yes" ?>'
1251
+ [ :on_xmldecl ]
1252
+ [ :parse_error, "encoding declaration must not be here" ]
1253
+ [ :on_xmldecl_encoding, 'euc-jp' ]
1254
+ [ :on_xmldecl_standalone, 'yes' ]
1255
+ [ :on_xmldecl_end ]
1256
+
1257
+ '<?xml standalone="yes" version="1.0" ?>'
1258
+ [ :on_xmldecl ]
1259
+ [ :parse_error, "standalone declaration must not be here" ]
1260
+ [ :on_xmldecl_standalone, 'yes' ]
1261
+ [ :parse_error, "version declaration must not be here" ]
1262
+ [ :on_xmldecl_version, '1.0' ]
1263
+ [ :on_xmldecl_end ]
1264
+
1265
+ '<?xml standalone="yes" encoding="euc-jp" ?>'
1266
+ [ :on_xmldecl ]
1267
+ [ :parse_error, "standalone declaration must not be here" ]
1268
+ [ :on_xmldecl_standalone, 'yes' ]
1269
+ [ :parse_error, "encoding declaration must not be here" ]
1270
+ [ :on_xmldecl_encoding, 'euc-jp' ]
1271
+ [ :on_xmldecl_end ]
1272
+
1273
+ '<?xml version="1.0"encoding="euc-jp" standalone="yes" ?>'
1274
+ [ :on_xmldecl ]
1275
+ [ :on_xmldecl_version, '1.0' ]
1276
+ [ :parse_error, "parse error at `encoding'" ]
1277
+ [ :parse_error, "parse error at `='" ]
1278
+ [ :parse_error, "parse error at `\"'" ]
1279
+ [ :parse_error, "parse error at `euc-jp'" ]
1280
+ [ :parse_error, "parse error at `\"'" ]
1281
+ [ :on_xmldecl_standalone, 'yes' ]
1282
+ [ :on_xmldecl_end ]
1283
+
1284
+ "<?xml hoge='fuga' ?>"
1285
+ [ :on_xmldecl ]
1286
+ [ :parse_error, "unknown declaration `hoge' in XML declaration" ]
1287
+ [ :on_xmldecl_other, 'hoge', 'fuga' ]
1288
+ [ :on_xmldecl_end ]
1289
+
1290
+ '<?xml ?>'
1291
+ [ :on_xmldecl ]
1292
+ [ :parse_error, "no declaration found in XML declaration" ]
1293
+ [ :on_xmldecl_end ]
1294
+
1295
+ '<?xml version="1.0">'
1296
+ [ :on_xmldecl ]
1297
+ [ :on_xmldecl_version, '1.0' ]
1298
+ [ :parse_error, "parse error at `>'" ]
1299
+ [ :parse_error, "unterminated XML declaration meets EOF" ]
1300
+ [ :on_xmldecl_end ]
1301
+
1302
+ '<?xml >'
1303
+ [ :on_xmldecl ]
1304
+ [ :parse_error, "parse error at `>'" ]
1305
+ [ :parse_error, "unterminated XML declaration meets EOF" ]
1306
+ [ :parse_error, "no declaration found in XML declaration" ]
1307
+ [ :on_xmldecl_end ]
1308
+
1309
+ '<?xml '
1310
+ [ :on_xmldecl ]
1311
+ [ :parse_error, "unterminated XML declaration meets EOF" ]
1312
+ [ :parse_error, "no declaration found in XML declaration" ]
1313
+ [ :on_xmldecl_end ]
1314
+
1315
+ '<?xml >><<a>> b'
1316
+ [ :on_xmldecl ]
1317
+ [ :parse_error, "parse error at `>'" ]
1318
+ [ :parse_error, "parse error at `>'" ]
1319
+ [ :parse_error, "parse error at `<'" ]
1320
+ [ :parse_error, "parse error at `<'" ]
1321
+ [ :parse_error, "parse error at `a'" ]
1322
+ [ :parse_error, "parse error at `>'" ]
1323
+ [ :parse_error, "parse error at `>'" ]
1324
+ [ :parse_error, "parse error at `b'" ]
1325
+ [ :parse_error, "unterminated XML declaration meets EOF" ]
1326
+ [ :parse_error, "no declaration found in XML declaration" ]
1327
+ [ :on_xmldecl_end ]
1328
+
1329
+ '<?xml version= ?>'
1330
+ [ :on_xmldecl ]
1331
+ [ :parse_error, "parse error at `version'" ]
1332
+ [ :parse_error, "parse error at `='" ]
1333
+ [ :parse_error, "no declaration found in XML declaration" ]
1334
+ [ :on_xmldecl_end ]
1335
+
1336
+ '<?xml version=1.0 ?>'
1337
+ [ :on_xmldecl ]
1338
+ [ :parse_error, "parse error at `version'" ]
1339
+ [ :parse_error, "parse error at `='" ]
1340
+ [ :parse_error, "parse error at `1.0'" ]
1341
+ [ :parse_error, "no declaration found in XML declaration" ]
1342
+ [ :on_xmldecl_end ]
1343
+
1344
+ '<?xml version!="1.0" ?>'
1345
+ [ :on_xmldecl ]
1346
+ [ :parse_error, "parse error at `version'" ]
1347
+ [ :parse_error, "parse error at `!'" ]
1348
+ [ :parse_error, "parse error at `='" ]
1349
+ [ :parse_error, "parse error at `\"'" ]
1350
+ [ :parse_error, "parse error at `1.0'" ]
1351
+ [ :parse_error, "parse error at `\"'" ]
1352
+ [ :parse_error, "no declaration found in XML declaration" ]
1353
+ [ :on_xmldecl_end ]
1354
+
1355
+ "<?xml version != '1.0' ?>"
1356
+ [ :on_xmldecl ]
1357
+ [ :parse_error, "parse error at `version'" ]
1358
+ [ :parse_error, "parse error at `!'" ]
1359
+ [ :parse_error, "parse error at `='" ]
1360
+ [ :parse_error, "parse error at `''" ]
1361
+ [ :parse_error, "parse error at `1.0'" ]
1362
+ [ :parse_error, "parse error at `''" ]
1363
+ [ :parse_error, "no declaration found in XML declaration" ]
1364
+ [ :on_xmldecl_end ]
1365
+
1366
+ "<?xml version = '1.0 ?>"
1367
+ [ :on_xmldecl ]
1368
+ [ :parse_error, "unterminated XML declaration meets EOF" ]
1369
+ [ :on_xmldecl_version, '1.0 ?>' ]
1370
+ [ :on_xmldecl_end ]
1371
+
1372
+ "<?xml version='1.0' ?>hoge"
1373
+ [ :on_xmldecl ]
1374
+ [ :on_xmldecl_version, '1.0' ]
1375
+ [ :on_xmldecl_end ]
1376
+ [ :on_chardata, 'hoge' ]
1377
+
1378
+ "<?xml version='1.0' ?>>"
1379
+ [ :on_xmldecl ]
1380
+ [ :on_xmldecl_version, '1.0' ]
1381
+ [ :on_xmldecl_end ]
1382
+ [ :on_chardata, '>' ]
1383
+
1384
+ TESTCASEEND
1385
+
1386
+
1387
+
1388
+ deftestcase 'doctype', <<-'TESTCASEEND'
1389
+
1390
+ '<!DOCTYPE hoge >'
1391
+ [ :on_doctype, 'hoge', nil, nil ]
1392
+
1393
+ '<!DOCTYPE hoge SYSTEM "fuga">'
1394
+ [ :on_doctype, 'hoge', nil, 'fuga' ]
1395
+
1396
+ "<!DOCTYPE hoge PUBLIC 'fuga' >"
1397
+ [ :on_doctype, 'hoge', 'fuga', nil ]
1398
+
1399
+ "<!DOCTYPE hoge PUBLIC 'fuga' 'muga'>"
1400
+ [ :on_doctype, 'hoge', 'fuga', 'muga' ]
1401
+
1402
+ "<!DOCTYPE hoge PUBLIC 'fu<<a>><<>>ga' 'mu<<>><<>><<a>>ga'>"
1403
+ [ :on_doctype, 'hoge', 'fu<<a>><<>>ga', 'mu<<>><<>><<a>>ga' ]
1404
+
1405
+ "<!DOCTYPE hoge SYSTEM 'fuga' 'muga' >"
1406
+ [ :parse_error, 'too many external ID literals in DOCTYPE' ]
1407
+ [ :on_doctype, 'hoge', nil, 'fuga' ]
1408
+
1409
+ "<!DOCTYPE hoge PUBLIC 'fuga' 'muga' 'foo'>"
1410
+ [ :parse_error, 'too many external ID literals in DOCTYPE' ]
1411
+ [ :on_doctype, 'hoge', 'fuga', 'muga' ]
1412
+
1413
+ "<!DOCTYPE hoge SYSTEM>"
1414
+ [ :parse_error, 'too few external ID literals in DOCTYPE' ]
1415
+ [ :on_doctype, 'hoge', nil, nil ]
1416
+
1417
+ "<!DOCTYPE hoge PUBLIC>"
1418
+ [ :parse_error, 'too few external ID literals in DOCTYPE' ]
1419
+ [ :on_doctype, 'hoge', nil, nil ]
1420
+
1421
+ "<!DOCTYPE hoge public 'fuga' >"
1422
+ [ :parse_error, "`PUBLIC' or `SYSTEM' should be here" ]
1423
+ [ :on_doctype, 'hoge', nil, 'fuga' ]
1424
+
1425
+ '<!DOCTYPE SYSTEM "hoge">'
1426
+ [ :parse_error, "parse error at `\"'" ]
1427
+ [ :parse_error, "parse error at `hoge'" ]
1428
+ [ :parse_error, "parse error at `\"'" ]
1429
+ [ :on_doctype, 'SYSTEM', nil, nil ]
1430
+
1431
+ '<!DOCTYPE "hoge">'
1432
+ [ :parse_error, "parse error at `\"'" ]
1433
+ [ :parse_error, "parse error at `hoge'" ]
1434
+ [ :parse_error, "parse error at `\"'" ]
1435
+ [ :parse_error, "no root element is specified in DOCTYPE" ]
1436
+ [ :on_doctype, nil, nil, nil ]
1437
+
1438
+ '<!DOCTYPE hoge <<a<<b<<c<<>'
1439
+ [ :parse_error, "parse error at `<'" ]
1440
+ [ :parse_error, "parse error at `<'" ]
1441
+ [ :parse_error, "parse error at `a'" ]
1442
+ [ :parse_error, "parse error at `<'" ]
1443
+ [ :parse_error, "parse error at `<'" ]
1444
+ [ :parse_error, "parse error at `b'" ]
1445
+ [ :parse_error, "parse error at `<'" ]
1446
+ [ :parse_error, "parse error at `<'" ]
1447
+ [ :parse_error, "parse error at `c'" ]
1448
+ [ :parse_error, "parse error at `<'" ]
1449
+ [ :parse_error, "parse error at `<'" ]
1450
+ [ :on_doctype, 'hoge', nil, nil ]
1451
+
1452
+ '<!DOCTYPE hoge PUBLIC "fuga" "muga" '
1453
+ [ :parse_error, "unterminated DOCTYPE declaration meets EOF" ]
1454
+ [ :on_doctype, 'hoge', 'fuga', 'muga' ]
1455
+
1456
+ '<!DOCTYPE hoge SYSTEM "fuga" '
1457
+ [ :parse_error, "unterminated DOCTYPE declaration meets EOF" ]
1458
+ [ :on_doctype, 'hoge', nil, 'fuga' ]
1459
+
1460
+ '<!DOCTYPE hoge SYSTEM "fuga>'
1461
+ [ :parse_error, "unterminated DOCTYPE declaration meets EOF" ]
1462
+ [ :on_doctype, 'hoge', nil, 'fuga>' ]
1463
+
1464
+ '<!DOCTYPE hoge '
1465
+ [ :parse_error, "unterminated DOCTYPE declaration meets EOF" ]
1466
+ [ :on_doctype, 'hoge', nil, nil ]
1467
+
1468
+ '<!DOCTYPE '
1469
+ [ :parse_error, "unterminated DOCTYPE declaration meets EOF" ]
1470
+ [ :parse_error, "no root element is specified in DOCTYPE" ]
1471
+ [ :on_doctype, nil, nil, nil ]
1472
+
1473
+ '<!DOCTYPE hoge []>'
1474
+ [ :on_doctype, 'hoge', nil, nil ]
1475
+ [ :warning, "internal DTD subset is not supported" ]
1476
+
1477
+ '<!DOCTYPE hoge[]>'
1478
+ [ :on_doctype, 'hoge', nil, nil ]
1479
+ [ :warning, "internal DTD subset is not supported" ]
1480
+
1481
+ '<!DOCTYPE hoge SYSTEM "fuga"[ ]>'
1482
+ [ :on_doctype, 'hoge', nil, 'fuga' ]
1483
+ [ :warning, "internal DTD subset is not supported" ]
1484
+
1485
+ "<!DOCTYPE hoge PUBLIC 'fuga' []>"
1486
+ [ :on_doctype, 'hoge', 'fuga', nil ]
1487
+ [ :warning, "internal DTD subset is not supported" ]
1488
+
1489
+ "<!DOCTYPE hoge PUBLIC 'fuga' 'muga'[]>"
1490
+ [ :on_doctype, 'hoge', 'fuga', 'muga' ]
1491
+ [ :warning, "internal DTD subset is not supported" ]
1492
+
1493
+ '<!DOCTYPE hoge >fuga'
1494
+ [ :on_doctype, 'hoge', nil, nil ]
1495
+ [ :on_chardata, 'fuga' ]
1496
+
1497
+ '<!DOCTYPE hoge >>'
1498
+ [ :on_doctype, 'hoge', nil, nil ]
1499
+ [ :on_chardata, '>' ]
1500
+
1501
+ "<!DOCTYPE hoge PUBLIC 'fuga' 'muga' 'foo'>fuga"
1502
+ [ :parse_error, 'too many external ID literals in DOCTYPE' ]
1503
+ [ :on_doctype, 'hoge', 'fuga', 'muga' ]
1504
+ [ :on_chardata, 'fuga' ]
1505
+
1506
+ '<!DOCTYPE "hoge">fuga'
1507
+ [ :parse_error, "parse error at `\"'" ]
1508
+ [ :parse_error, "parse error at `hoge'" ]
1509
+ [ :parse_error, "parse error at `\"'" ]
1510
+ [ :parse_error, "no root element is specified in DOCTYPE" ]
1511
+ [ :on_doctype, nil, nil, nil ]
1512
+ [ :on_chardata, 'fuga' ]
1513
+
1514
+ "<!DOCTYPE hoge\fSYSTEM\f'fuga'>fuga"
1515
+ [ :parse_error, "parse error at `''" ]
1516
+ [ :parse_error, "parse error at `fuga'" ]
1517
+ [ :parse_error, "parse error at `''" ]
1518
+ [ :on_doctype, "hoge\fSYSTEM\f", nil, nil ]
1519
+ [ :on_chardata, 'fuga' ]
1520
+
1521
+ TESTCASEEND
1522
+
1523
+
1524
+
1525
+ deftestcase 'internal_dtd', <<-'TESTCASEEND'
1526
+
1527
+ '<!DOCTYPE hoge[ <!ENTITY fuga "hoge"> ]>'
1528
+ [ :on_doctype, 'hoge', nil, nil ]
1529
+ [ :warning, "internal DTD subset is not supported" ]
1530
+
1531
+ "<!DOCTYPE hoge[ <!-- ]> --> ]>"
1532
+ [ :on_doctype, 'hoge', nil, nil ]
1533
+ [ :warning, "internal DTD subset is not supported" ]
1534
+
1535
+ "<!DOCTYPE hoge[ <!-- ]> -> ]>"
1536
+ [ :on_doctype, 'hoge', nil, nil ]
1537
+ [ :warning, "internal DTD subset is not supported" ]
1538
+ [ :parse_error, "unterminated internal DTD subset meets EOF" ]
1539
+
1540
+ "<!DOCTYPE hoge[ <? ]> ?> ]>"
1541
+ [ :on_doctype, 'hoge', nil, nil ]
1542
+ [ :warning, "internal DTD subset is not supported" ]
1543
+
1544
+ "<!DOCTYPE hoge[ <? ]> > ]>"
1545
+ [ :on_doctype, 'hoge', nil, nil ]
1546
+ [ :warning, "internal DTD subset is not supported" ]
1547
+ [ :parse_error, "unterminated internal DTD subset meets EOF" ]
1548
+
1549
+ '<!DOCTYPE hoge[ <fugaufgaufugaufguafugaf>'
1550
+ [ :on_doctype, 'hoge', nil, nil ]
1551
+ [ :warning, "internal DTD subset is not supported" ]
1552
+ [ :parse_error, "unterminated internal DTD subset meets EOF" ]
1553
+
1554
+ "<!DOCTYPE hoge[ <!ENTITY fuga ']>' >>><<>><<a>> ]>"
1555
+ [ :on_doctype, 'hoge', nil, nil ]
1556
+ [ :warning, "internal DTD subset is not supported" ]
1557
+
1558
+ "<!DOCTYPE hoge[ <!ENTITY fuga ']>' \">>><<>><<a>>\" ]>"
1559
+ [ :on_doctype, 'hoge', nil, nil ]
1560
+ [ :warning, "internal DTD subset is not supported" ]
1561
+
1562
+ '<!DOCTYPE hoge[ \"<!-- a \" --> ]>'
1563
+ [ :on_doctype, 'hoge', nil, nil ]
1564
+ [ :warning, "internal DTD subset is not supported" ]
1565
+
1566
+ '<!DOCTYPE hoge[ "<!? a " ?> ]>'
1567
+ [ :on_doctype, 'hoge', nil, nil ]
1568
+ [ :warning, "internal DTD subset is not supported" ]
1569
+
1570
+ '<!DOCTYPE hoge[ <!ENTITY hoge "fuga" -- ]> -- > ]>'
1571
+ [ :on_doctype, 'hoge', nil, nil ]
1572
+ [ :warning, "internal DTD subset is not supported" ]
1573
+ [ :on_chardata, ' -- ' ]
1574
+ [ :on_chardata, '> ]' ]
1575
+ [ :on_chardata, '>' ]
1576
+
1577
+ '<!DOCTYPE hoge[ fuga ]>hoge'
1578
+ [ :on_doctype, 'hoge', nil, nil ]
1579
+ [ :warning, "internal DTD subset is not supported" ]
1580
+ [ :on_chardata, 'hoge' ]
1581
+
1582
+ '<!DOCTYPE hoge[ fuga ]>>'
1583
+ [ :on_doctype, 'hoge', nil, nil ]
1584
+ [ :warning, "internal DTD subset is not supported" ]
1585
+ [ :on_chardata, '>' ]
1586
+
1587
+ TESTCASEEND
1588
+
1589
+
1590
+
1591
+ deftestcase 'prolog', <<-'TESTCASEEND'
1592
+
1593
+ '<?xml version="1.0"?><!DOCTYPE hoge><hoge>'
1594
+ [ :on_xmldecl ]
1595
+ [ :on_xmldecl_version, '1.0' ]
1596
+ [ :on_xmldecl_end ]
1597
+ [ :on_doctype, 'hoge', nil, nil ]
1598
+ [ :on_stag, 'hoge' ]
1599
+ [ :on_stag_end, 'hoge' ]
1600
+
1601
+ '<?xml version="1.0"?><hoge><!DOCTYPE hoge>'
1602
+ [ :on_xmldecl ]
1603
+ [ :on_xmldecl_version, '1.0' ]
1604
+ [ :on_xmldecl_end ]
1605
+ [ :on_stag, 'hoge' ]
1606
+ [ :on_stag_end, 'hoge' ]
1607
+ [ :parse_error, "parse error at `<!'" ]
1608
+ [ :on_chardata, "<!DOCTYPE hoge>" ]
1609
+
1610
+ '<!DOCTYPE hoge><hoge><?xml version="1.0"?>'
1611
+ [ :on_doctype, 'hoge', nil, nil ]
1612
+ [ :on_stag, 'hoge' ]
1613
+ [ :on_stag_end, 'hoge' ]
1614
+ [ :on_pi, 'xml', 'version="1.0"' ]
1615
+
1616
+ '<!DOCTYPE hoge><?xml version="1.0"?><hoge>'
1617
+ [ :on_doctype, 'hoge', nil, nil ]
1618
+ [ :on_pi, 'xml', 'version="1.0"' ]
1619
+ [ :on_stag, 'hoge' ]
1620
+ [ :on_stag_end, 'hoge' ]
1621
+
1622
+ '<?xml version="1.0"?> <!DOCTYPE hoge> <hoge>'
1623
+ [ :on_xmldecl ]
1624
+ [ :on_xmldecl_version, '1.0' ]
1625
+ [ :on_xmldecl_end ]
1626
+ [ :on_prolog_space, ' ' ]
1627
+ [ :on_doctype, 'hoge', nil, nil ]
1628
+ [ :on_prolog_space, ' ' ]
1629
+ [ :on_stag, 'hoge' ]
1630
+ [ :on_stag_end, 'hoge' ]
1631
+
1632
+ ' <?xml version="1.0"?> <!DOCTYPE hoge> <hoge>'
1633
+ [ :on_prolog_space, ' ' ]
1634
+ [ :on_pi, 'xml', 'version="1.0"' ]
1635
+ [ :on_prolog_space, ' ' ]
1636
+ [ :on_doctype, 'hoge', nil, nil ]
1637
+ [ :on_prolog_space, ' ' ]
1638
+ [ :on_stag, 'hoge' ]
1639
+ [ :on_stag_end, 'hoge' ]
1640
+
1641
+ '<?xml version="1.0"?><!--hoge--><!DOCTYPE hoge><?fuga?><hoge>'
1642
+ [ :on_xmldecl ]
1643
+ [ :on_xmldecl_version, '1.0' ]
1644
+ [ :on_xmldecl_end ]
1645
+ [ :on_comment, 'hoge' ]
1646
+ [ :on_doctype, 'hoge', nil, nil ]
1647
+ [ :on_pi, 'fuga', '' ]
1648
+ [ :on_stag, 'hoge' ]
1649
+ [ :on_stag_end, 'hoge' ]
1650
+
1651
+ '<?xml version="1.0"?><!--hoge--><!DOCTYPE hoge><!--fuga--><hoge>'
1652
+ [ :on_xmldecl ]
1653
+ [ :on_xmldecl_version, '1.0' ]
1654
+ [ :on_xmldecl_end ]
1655
+ [ :on_comment, 'hoge' ]
1656
+ [ :on_doctype, 'hoge', nil, nil ]
1657
+ [ :on_comment, 'fuga' ]
1658
+ [ :on_stag, 'hoge' ]
1659
+ [ :on_stag_end, 'hoge' ]
1660
+
1661
+ '<!--hoge--><?xml version="1.0"?><hoge>'
1662
+ [ :on_comment, 'hoge' ]
1663
+ [ :on_pi, 'xml', 'version="1.0"' ]
1664
+ [ :on_stag, 'hoge' ]
1665
+ [ :on_stag_end, 'hoge' ]
1666
+
1667
+ '<?hoge?><?xml version="1.0"?><hoge>'
1668
+ [ :on_pi, 'hoge', '' ]
1669
+ [ :on_pi, 'xml', 'version="1.0"' ]
1670
+ [ :on_stag, 'hoge' ]
1671
+ [ :on_stag_end, 'hoge' ]
1672
+
1673
+ '<?fuga?> <hoge>'
1674
+ [ :on_pi, 'fuga', '' ]
1675
+ [ :on_prolog_space, ' ' ]
1676
+ [ :on_stag, 'hoge' ]
1677
+ [ :on_stag_end, 'hoge' ]
1678
+
1679
+ '<!--fuga--> <hoge>'
1680
+ [ :on_comment, 'fuga' ]
1681
+ [ :on_prolog_space, ' ' ]
1682
+ [ :on_stag, 'hoge' ]
1683
+ [ :on_stag_end, 'hoge' ]
1684
+
1685
+ 'hoge<?xml version="1.0"?><!DOCTYPE hoge>'
1686
+ [ :on_chardata, 'hoge' ]
1687
+ [ :on_pi, 'xml', 'version="1.0"' ]
1688
+ [ :parse_error, "parse error at `<!'" ]
1689
+ [ :on_chardata, "<!DOCTYPE hoge>" ]
1690
+
1691
+ '>hoge<?xml version="1.0"?><!DOCTYPE hoge>'
1692
+ [ :on_chardata, '>hoge' ]
1693
+ [ :on_pi, 'xml', 'version="1.0"' ]
1694
+ [ :parse_error, "parse error at `<!'" ]
1695
+ [ :on_chardata, "<!DOCTYPE hoge>" ]
1696
+
1697
+ '><?xml version="1.0"?><!DOCTYPE hoge>'
1698
+ [ :on_chardata, '>' ]
1699
+ [ :on_pi, 'xml', 'version="1.0"' ]
1700
+ [ :parse_error, "parse error at `<!'" ]
1701
+ [ :on_chardata, "<!DOCTYPE hoge>" ]
1702
+
1703
+ '<?xml version="1.0"?> fuga <!DOCTYPE hoge>'
1704
+ [ :on_xmldecl ]
1705
+ [ :on_xmldecl_version, '1.0' ]
1706
+ [ :on_xmldecl_end ]
1707
+ [ :on_chardata, ' fuga ' ]
1708
+ [ :parse_error, "parse error at `<!'" ]
1709
+ [ :on_chardata, "<!DOCTYPE hoge>" ]
1710
+
1711
+ '<?xml version="1.0"?><!DOCTYPE hoge><!DOCTYPE fuga><hoge>'
1712
+ [ :on_xmldecl ]
1713
+ [ :on_xmldecl_version, '1.0' ]
1714
+ [ :on_xmldecl_end ]
1715
+ [ :on_doctype, 'hoge', nil, nil ]
1716
+ [ :parse_error, "parse error at `<!'" ]
1717
+ [ :on_chardata, "<!DOCTYPE fuga>" ]
1718
+ [ :on_stag, 'hoge' ]
1719
+ [ :on_stag_end, 'hoge' ]
1720
+
1721
+ "<!DOCTYPE\fhoge>"
1722
+ [ :parse_error, "parse error at `<!'" ]
1723
+ [ :on_chardata, "<!DOCTYPE\fhoge>" ]
1724
+
1725
+ "<?xml\fversion='1.0'?>"
1726
+ [ :on_pi, "xml\fversion='1.0'", '' ]
1727
+
1728
+ " > <hoge>"
1729
+ [ :on_prolog_space, ' ' ]
1730
+ [ :on_chardata, '> ' ]
1731
+ [ :on_stag, 'hoge' ]
1732
+ [ :on_stag_end, 'hoge' ]
1733
+
1734
+ TESTCASEEND
1735
+
1736
+ def test_emptystring
1737
+ parse ""
1738
+ end
1739
+
1740
+ def test_nil
1741
+ parse nil
1742
+ end
1743
+
1744
+ end
1745
+
1746
+
1747
+
1748
+
1749
+ load "#{File.dirname($0)}/runtest.rb" if __FILE__ == $0