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,752 @@
1
+ #
2
+ # tests/testhtmlscan.rb
3
+ #
4
+ # Copyright (C) UENO Katsuhiro 2002
5
+ #
6
+ # $Id: testhtmlscan.rb,v 1.19 2003/02/28 12:31:07 katsu Exp $
7
+ #
8
+
9
+ require 'test/unit'
10
+ require 'deftestcase'
11
+ require 'xmlscan/htmlscan'
12
+ require 'visitor'
13
+
14
+
15
+ class TestHTMLScanner < Test::Unit::TestCase
16
+
17
+ include DefTestCase
18
+
19
+ Visitor = RecordingVisitor.new_class(XMLScan::Visitor)
20
+
21
+
22
+ private
23
+
24
+ def setup
25
+ @v = Visitor.new
26
+ @s = XMLScan::HTMLScanner.new(@v)
27
+ end
28
+
29
+ def parse(src)
30
+ @s.parse src
31
+ @v.result
32
+ end
33
+
34
+
35
+ public
36
+
37
+ deftestcase 'html_comment', <<-'TESTCASEEND'
38
+
39
+ '<!-- hogefuga -->'
40
+ [ :on_comment, ' hogefuga ' ]
41
+
42
+ '<!-- hoge<a>fuga -->'
43
+ [ :on_comment, ' hoge<a>fuga ' ]
44
+
45
+ '<!-- hoge<<<>>><<<a>>>fuga -->'
46
+ [ :on_comment, ' hoge<<<>>><<<a>>>fuga ' ]
47
+
48
+ '<!-- hoge-fuga -->'
49
+ [ :on_comment, ' hoge-fuga ' ]
50
+
51
+ '<!-- hogefuga'
52
+ [ :parse_error, 'unterminated comment meets EOF' ]
53
+ [ :on_comment, ' hogefuga' ]
54
+
55
+ '<!-- hoge -- -- fuga -->'
56
+ [ :on_comment, ' hoge -- -- fuga ' ]
57
+
58
+ '<!-- hoge--fuga -->'
59
+ [ :parse_error, "only whitespace can appear between two comments" ]
60
+ [ :on_comment, ' hoge--fuga ' ]
61
+
62
+ '<!-- hoge--fuga'
63
+ [ :parse_error, "only whitespace can appear between two comments" ]
64
+ [ :parse_error, 'unterminated comment meets EOF' ]
65
+ [ :on_comment, ' hoge--fuga' ]
66
+
67
+ # should be parsed as |<!--|- hogefuga |--|->|
68
+ '<!--- hogefuga --->'
69
+ [ :parse_error, "only whitespace can appear between two comments"]
70
+ [ :parse_error, "`-->' is found but comment must not end here"]
71
+ [ :on_comment, '- hogefuga -' ]
72
+
73
+ '<!--- hogefuga --- >'
74
+ [ :parse_error, "only whitespace can appear between two comments"]
75
+ [ :parse_error, "`-->' is found but comment must not end here"]
76
+ [ :on_comment, '- hogefuga -' ]
77
+
78
+ # should be parsed as |<!--|--|--|-->|
79
+ '<!-------->'
80
+ [ :on_comment, '----' ]
81
+
82
+ # should be parsed as |<!--|--|--|->|
83
+ '<!------->'
84
+ [ :parse_error, "`-->' is found but comment must not end here"]
85
+ [ :on_comment, '---' ]
86
+
87
+ # should be parsed as |<!--|--|--|>|
88
+ '<!------>'
89
+ [ :parse_error, "`-->' is found but comment must not end here"]
90
+ [ :on_comment, '--' ]
91
+
92
+ # should be parsed as |<!--|--|->|
93
+ '<!----->'
94
+ [ :parse_error, "only whitespace can appear between two comments"]
95
+ [ :parse_error, "`-->' is found but comment must not end here"]
96
+ [ :on_comment, '-' ]
97
+
98
+ '<!---->'
99
+ [ :on_comment, '' ]
100
+
101
+ '<!--->'
102
+ [ :parse_error, 'unterminated comment meets EOF' ]
103
+ [ :on_comment, '->' ]
104
+
105
+ '<!-->'
106
+ [ :parse_error, 'unterminated comment meets EOF' ]
107
+ [ :on_comment, '>' ]
108
+
109
+ '<!--hoge-->fuga'
110
+ [ :on_comment, 'hoge' ]
111
+ [ :on_chardata, 'fuga' ]
112
+
113
+ '<!--hoge-- >fuga'
114
+ [ :on_comment, 'hoge' ]
115
+ [ :on_chardata, 'fuga' ]
116
+
117
+ '<!--hoge-->>'
118
+ [ :on_comment, 'hoge' ]
119
+ [ :on_chardata, '>' ]
120
+
121
+ '<!--hoge--fuga-->hoge'
122
+ [ :parse_error, "only whitespace can appear between two comments"]
123
+ [ :on_comment, 'hoge--fuga' ]
124
+ [ :on_chardata, 'hoge' ]
125
+
126
+ TESTCASEEND
127
+
128
+
129
+
130
+ deftestcase 'pi', <<-'TESTCASEEND'
131
+
132
+ '<?hoge fuga?>'
133
+ [ :on_pi, '', 'hoge fuga?' ]
134
+
135
+ '<?xml version="1.0"?>'
136
+ [ :on_pi, '', 'xml version="1.0"?' ]
137
+
138
+ '<?hoge fuga>'
139
+ [ :on_pi, '', 'hoge fuga' ]
140
+
141
+ '<?hoge >'
142
+ [ :on_pi, '', 'hoge ' ]
143
+
144
+ '<?hoge>'
145
+ [ :on_pi, '', 'hoge' ]
146
+
147
+ '<?hoge <<a<<<a<<< >'
148
+ [ :on_pi, '', 'hoge <<a<<<a<<< ' ]
149
+
150
+ '<?hoge<>'
151
+ [ :on_pi, '', 'hoge<' ]
152
+
153
+ '<? >'
154
+ [ :on_pi, '', ' ' ]
155
+
156
+ '<?>'
157
+ [ :on_pi, '', '' ]
158
+
159
+ '<?'
160
+ [ :parse_error, "unterminated PI meets EOF" ]
161
+ [ :on_pi, '', '' ]
162
+
163
+ '<?hoge>fuga'
164
+ [ :on_pi, '', 'hoge' ]
165
+ [ :on_chardata, 'fuga' ]
166
+
167
+ '<?hoge>>'
168
+ [ :on_pi, '', 'hoge' ]
169
+ [ :on_chardata, '>' ]
170
+
171
+ TESTCASEEND
172
+
173
+
174
+
175
+ deftestcase 'stag', <<-'TESTCASEEND'
176
+
177
+ '<hoge>'
178
+ [ :on_stag, 'hoge' ]
179
+ [ :on_stag_end, 'hoge' ]
180
+
181
+ '<hoge >'
182
+ [ :on_stag, 'hoge' ]
183
+ [ :on_stag_end, 'hoge' ]
184
+
185
+ '<hoge'
186
+ [ :on_stag, 'hoge' ]
187
+ [ :parse_error, "unclosed start tag `hoge' meets EOF" ]
188
+ [ :on_stag_end, 'hoge' ]
189
+
190
+ '<hoge<fuga>'
191
+ [ :on_stag, 'hoge' ]
192
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
193
+ [ :on_stag_end, 'hoge' ]
194
+ [ :on_stag, 'fuga' ]
195
+ [ :on_stag_end, 'fuga' ]
196
+
197
+ '<hoge <fuga>'
198
+ [ :on_stag, 'hoge' ]
199
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
200
+ [ :on_stag_end, 'hoge' ]
201
+ [ :on_stag, 'fuga' ]
202
+ [ :on_stag_end, 'fuga' ]
203
+
204
+ '< hoge>'
205
+ [ :parse_error, "parse error at `<'" ]
206
+ [ :on_chardata, '< hoge>' ]
207
+
208
+ '<hoge/>'
209
+ [ :on_stag, 'hoge' ]
210
+ [ :parse_error, "parse error at `/'" ]
211
+ [ :on_stag_end, 'hoge' ]
212
+
213
+ '<hoge= >'
214
+ [ :on_stag, 'hoge' ]
215
+ [ :parse_error, "parse error at `='" ]
216
+ [ :on_stag_end, 'hoge' ]
217
+
218
+ '<=hoge >'
219
+ [ :parse_error, "parse error at `<'" ]
220
+ [ :on_chardata, '<=hoge >' ]
221
+
222
+ '< =hoge >'
223
+ [ :parse_error, "parse error at `<'" ]
224
+ [ :on_chardata, '< =hoge >' ]
225
+
226
+ '<hoge>fuga'
227
+ [ :on_stag, 'hoge' ]
228
+ [ :on_stag_end, 'hoge' ]
229
+ [ :on_chardata, 'fuga' ]
230
+
231
+ '<hoge>>'
232
+ [ :on_stag, 'hoge' ]
233
+ [ :on_stag_end, 'hoge' ]
234
+ [ :on_chardata, '>' ]
235
+
236
+ '< hoge>fuga'
237
+ [ :parse_error, "parse error at `<'" ]
238
+ [ :on_chardata, '< hoge>' ]
239
+ [ :on_chardata, 'fuga' ]
240
+
241
+ '< hoge>>'
242
+ [ :parse_error, "parse error at `<'" ]
243
+ [ :on_chardata, '< hoge>' ]
244
+ [ :on_chardata, '>' ]
245
+
246
+ '<hoge/>'
247
+ [ :on_stag, 'hoge' ]
248
+ [ :parse_error, "parse error at `/'" ]
249
+ [ :on_stag_end, 'hoge' ]
250
+
251
+ '<hoge/>fuga'
252
+ [ :on_stag, 'hoge' ]
253
+ [ :parse_error, "parse error at `/'" ]
254
+ [ :on_stag_end, 'hoge' ]
255
+ [ :on_chardata, 'fuga' ]
256
+
257
+ '<hoge/>>'
258
+ [ :on_stag, 'hoge' ]
259
+ [ :parse_error, "parse error at `/'" ]
260
+ [ :on_stag_end, 'hoge' ]
261
+ [ :on_chardata, '>' ]
262
+
263
+ TESTCASEEND
264
+
265
+
266
+
267
+ deftestcase 'attribute', <<-'TESTCASEEND'
268
+
269
+ '<hoge foo="bar">'
270
+ [ :on_stag, 'hoge' ]
271
+ [ :on_attribute, 'foo' ]
272
+ [ :on_attr_value, 'bar' ]
273
+ [ :on_attribute_end, 'foo' ]
274
+ [ :on_stag_end, 'hoge' ]
275
+
276
+ '<hoge foo="">'
277
+ [ :on_stag, 'hoge' ]
278
+ [ :on_attribute, 'foo' ]
279
+ [ :on_attribute_end, 'foo' ]
280
+ [ :on_stag_end, 'hoge' ]
281
+
282
+ "<hoge foo = ' bar ' HOGE = 'FUGA' >"
283
+ [ :on_stag, 'hoge' ]
284
+ [ :on_attribute, 'foo' ]
285
+ [ :on_attr_value, ' bar ' ]
286
+ [ :on_attribute_end, 'foo' ]
287
+ [ :on_attribute, 'HOGE' ]
288
+ [ :on_attr_value, 'FUGA' ]
289
+ [ :on_attribute_end, 'HOGE' ]
290
+ [ :on_stag_end, 'hoge' ]
291
+
292
+ '<hoge foo="bar"/>'
293
+ [ :on_stag, 'hoge' ]
294
+ [ :on_attribute, 'foo' ]
295
+ [ :on_attr_value, 'bar' ]
296
+ [ :on_attribute_end, 'foo' ]
297
+ [ :parse_error, "parse error at `/'" ]
298
+ [ :on_stag_end, 'hoge' ]
299
+
300
+ '<hoge foo=bar/>'
301
+ [ :on_stag, 'hoge' ]
302
+ [ :on_attribute, 'foo' ]
303
+ [ :on_attr_value, 'bar/' ]
304
+ [ :on_attribute_end, 'foo' ]
305
+ [ :on_stag_end, 'hoge' ]
306
+
307
+ '<hoge foo="b>a>b>c>ar">'
308
+ [ :on_stag, 'hoge' ]
309
+ [ :on_attribute, 'foo' ]
310
+ [ :on_attr_value, 'b' ]
311
+ [ :on_attr_value, '>' ]
312
+ [ :on_attr_value, 'a' ]
313
+ [ :on_attr_value, '>' ]
314
+ [ :on_attr_value, 'b' ]
315
+ [ :on_attr_value, '>' ]
316
+ [ :on_attr_value, 'c' ]
317
+ [ :on_attr_value, '>' ]
318
+ [ :on_attr_value, 'ar' ]
319
+ [ :on_attribute_end, 'foo' ]
320
+ [ :on_stag_end, 'hoge' ]
321
+
322
+ '<hoge foo="b>>a>>b>>c>>ar" HOGE="FUGA">'
323
+ [ :on_stag, 'hoge' ]
324
+ [ :on_attribute, 'foo' ]
325
+ [ :on_attr_value, 'b' ]
326
+ [ :on_attr_value, '>' ]
327
+ [ :on_attr_value, '>' ]
328
+ [ :on_attr_value, 'a' ]
329
+ [ :on_attr_value, '>' ]
330
+ [ :on_attr_value, '>' ]
331
+ [ :on_attr_value, 'b' ]
332
+ [ :on_attr_value, '>' ]
333
+ [ :on_attr_value, '>' ]
334
+ [ :on_attr_value, 'c' ]
335
+ [ :on_attr_value, '>' ]
336
+ [ :on_attr_value, '>' ]
337
+ [ :on_attr_value, 'ar' ]
338
+ [ :on_attribute_end, 'foo' ]
339
+ [ :on_attribute, 'HOGE' ]
340
+ [ :on_attr_value, 'FUGA' ]
341
+ [ :on_attribute_end, 'HOGE' ]
342
+ [ :on_stag_end, 'hoge' ]
343
+
344
+ '<hoge foo="b<a>b<c>ar">'
345
+ [ :on_stag, 'hoge' ]
346
+ [ :on_attribute, 'foo' ]
347
+ [ :on_attr_value, 'b' ]
348
+ [ :on_attr_value, '<a' ]
349
+ [ :on_attr_value, '>' ]
350
+ [ :on_attr_value, 'b' ]
351
+ [ :on_attr_value, '<c' ]
352
+ [ :on_attr_value, '>' ]
353
+ [ :on_attr_value, 'ar' ]
354
+ [ :on_attribute_end, 'foo' ]
355
+ [ :on_stag_end, 'hoge' ]
356
+
357
+ '<hoge foo=bar>'
358
+ [ :on_stag, 'hoge' ]
359
+ [ :on_attribute, 'foo' ]
360
+ [ :on_attr_value, 'bar' ]
361
+ [ :on_attribute_end, 'foo' ]
362
+ [ :on_stag_end, 'hoge' ]
363
+
364
+ '<hoge foo = bar >'
365
+ [ :on_stag, 'hoge' ]
366
+ [ :on_attribute, 'foo' ]
367
+ [ :on_attr_value, 'bar' ]
368
+ [ :on_attribute_end, 'foo' ]
369
+ [ :on_stag_end, 'hoge' ]
370
+
371
+ '<hoge foo = bar&fuga;bar >'
372
+ [ :on_stag, 'hoge' ]
373
+ [ :on_attribute, 'foo' ]
374
+ [ :on_attr_value, 'bar&fuga;bar' ]
375
+ [ :on_attribute_end, 'foo' ]
376
+ [ :on_stag_end, 'hoge' ]
377
+
378
+ '<hoge foo = bar/baz%fuga >'
379
+ [ :on_stag, 'hoge' ]
380
+ [ :on_attribute, 'foo' ]
381
+ [ :on_attr_value, 'bar/baz%fuga' ]
382
+ [ :on_attribute_end, 'foo' ]
383
+ [ :on_stag_end, 'hoge' ]
384
+
385
+ '<hoge foo/bar = bar/baz%fuga >'
386
+ [ :on_stag, 'hoge' ]
387
+ [ :on_attribute, nil ]
388
+ [ :on_attr_value, 'foo' ]
389
+ [ :on_attribute_end, nil ]
390
+ [ :parse_error, "parse error at `/'" ]
391
+ [ :on_attribute, 'bar' ]
392
+ [ :on_attr_value, 'bar/baz%fuga' ]
393
+ [ :on_attribute_end, 'bar' ]
394
+ [ :on_stag_end, 'hoge' ]
395
+
396
+
397
+ '<hoge foo = bar hoge = fuga >'
398
+ [ :on_stag, 'hoge' ]
399
+ [ :on_attribute, 'foo' ]
400
+ [ :on_attr_value, 'bar' ]
401
+ [ :on_attribute_end, 'foo' ]
402
+ [ :on_attribute, 'hoge' ]
403
+ [ :on_attr_value, 'fuga' ]
404
+ [ :on_attribute_end, 'hoge' ]
405
+ [ :on_stag_end, 'hoge' ]
406
+
407
+ '<hoge foo>'
408
+ [ :on_stag, 'hoge' ]
409
+ [ :on_attribute, nil ]
410
+ [ :on_attr_value, 'foo' ]
411
+ [ :on_attribute_end, nil ]
412
+ [ :on_stag_end, 'hoge' ]
413
+
414
+ '<hoge foo bar >'
415
+ [ :on_stag, 'hoge' ]
416
+ [ :on_attribute, nil ]
417
+ [ :on_attr_value, 'foo' ]
418
+ [ :on_attribute_end, nil ]
419
+ [ :on_attribute, nil ]
420
+ [ :on_attr_value, 'bar' ]
421
+ [ :on_attribute_end, nil ]
422
+ [ :on_stag_end, 'hoge' ]
423
+
424
+ '<hoge foo&hoge;bar>'
425
+ [ :on_stag, 'hoge' ]
426
+ [ :on_attribute, nil ]
427
+ [ :on_attr_value, 'foo&hoge;bar' ]
428
+ [ :on_attribute_end, nil ]
429
+ [ :on_stag_end, 'hoge' ]
430
+
431
+ '<hoge foo = bar hoge >'
432
+ [ :on_stag, 'hoge' ]
433
+ [ :on_attribute, 'foo' ]
434
+ [ :on_attr_value, 'bar' ]
435
+ [ :on_attribute_end, 'foo' ]
436
+ [ :on_attribute, nil ]
437
+ [ :on_attr_value, 'hoge' ]
438
+ [ :on_attribute_end, nil ]
439
+ [ :on_stag_end, 'hoge' ]
440
+
441
+ '<hoge foo = bar<fuga >'
442
+ [ :on_stag, 'hoge' ]
443
+ [ :on_attribute, 'foo' ]
444
+ [ :on_attr_value, 'bar' ]
445
+ [ :on_attribute_end, 'foo' ]
446
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
447
+ [ :on_stag_end, 'hoge' ]
448
+ [ :on_stag, 'fuga' ]
449
+ [ :on_stag_end, 'fuga' ]
450
+
451
+ '<hoge foo="bar"HOGE ="FUGA">'
452
+ [ :on_stag, 'hoge' ]
453
+ [ :on_attribute, 'foo' ]
454
+ [ :on_attr_value, 'bar' ]
455
+ [ :on_attribute_end, 'foo' ]
456
+ [ :on_attribute, 'HOGE' ]
457
+ [ :on_attr_value, 'FUGA' ]
458
+ [ :on_attribute_end, 'HOGE' ]
459
+ [ :on_stag_end, 'hoge' ]
460
+
461
+ '<hoge foo=bar=fuga >'
462
+ [ :on_stag, 'hoge' ]
463
+ [ :on_attribute, 'foo' ]
464
+ [ :on_attr_value, 'bar' ]
465
+ [ :on_attribute_end, 'foo' ]
466
+ [ :parse_error, "parse error at `='" ]
467
+ [ :on_attribute, nil ]
468
+ [ :on_attr_value, 'fuga' ]
469
+ [ :on_attribute_end, nil ]
470
+ [ :on_stag_end, 'hoge' ]
471
+
472
+ '<hoge foo="bar" <fuga>'
473
+ [ :on_stag, 'hoge' ]
474
+ [ :on_attribute, 'foo' ]
475
+ [ :on_attr_value, 'bar' ]
476
+ [ :on_attribute_end, 'foo' ]
477
+ [ :parse_error, "unclosed start tag `hoge' meets another tag" ]
478
+ [ :on_stag_end, 'hoge' ]
479
+ [ :on_stag, 'fuga' ]
480
+ [ :on_stag_end, 'fuga' ]
481
+
482
+ '<hoge foo="bar>'
483
+ [ :on_stag, 'hoge' ]
484
+ [ :on_attribute, 'foo' ]
485
+ [ :on_attr_value, 'bar' ]
486
+ [ :on_attr_value, '>' ]
487
+ [ :parse_error, "unterminated attribute `foo' meets EOF" ]
488
+ [ :on_attribute_end, 'foo' ]
489
+ [ :parse_error, "unclosed start tag `hoge' meets EOF" ]
490
+ [ :on_stag_end, 'hoge' ]
491
+
492
+ '<hoge foo= >'
493
+ [ :on_stag, 'hoge' ]
494
+ [ :on_attribute, nil ]
495
+ [ :on_attr_value, 'foo' ]
496
+ [ :on_attribute_end, nil ]
497
+ [ :parse_error, "parse error at `='" ]
498
+ [ :on_stag_end, 'hoge' ]
499
+
500
+ '<hoge ="fuga" >'
501
+ [ :on_stag, 'hoge' ]
502
+ [ :parse_error, "parse error at `='" ]
503
+ [ :parse_error, "parse error at `\"'" ]
504
+ [ :on_attribute, nil ]
505
+ [ :on_attr_value, 'fuga' ]
506
+ [ :on_attribute_end, nil ]
507
+ [ :parse_error, "parse error at `\"'" ]
508
+ [ :on_stag_end, 'hoge' ]
509
+
510
+ '<hoge "fuga" >'
511
+ [ :on_stag, 'hoge' ]
512
+ [ :parse_error, "parse error at `\"'" ]
513
+ [ :on_attribute, nil ]
514
+ [ :on_attr_value, 'fuga' ]
515
+ [ :on_attribute_end, nil ]
516
+ [ :parse_error, "parse error at `\"'" ]
517
+ [ :on_stag_end, 'hoge' ]
518
+
519
+ '<hoge"fuga" >'
520
+ [ :on_stag, 'hoge' ]
521
+ [ :parse_error, "parse error at `\"'" ]
522
+ [ :on_attribute, nil ]
523
+ [ :on_attr_value, 'fuga' ]
524
+ [ :on_attribute_end, nil ]
525
+ [ :parse_error, "parse error at `\"'" ]
526
+ [ :on_stag_end, 'hoge' ]
527
+
528
+ '<hoge = fuga >'
529
+ [ :on_stag, 'hoge' ]
530
+ [ :parse_error, "parse error at `='" ]
531
+ [ :on_attribute, nil ]
532
+ [ :on_attr_value, 'fuga' ]
533
+ [ :on_attribute_end, nil ]
534
+ [ :on_stag_end, 'hoge' ]
535
+
536
+ TESTCASEEND
537
+
538
+
539
+
540
+ deftestcase 'bang_tag', <<-'TESTCASEEND'
541
+
542
+ '<!hoge>'
543
+ [ :parse_error, "parse error at `<!'" ]
544
+
545
+ '<!hoge fuga>'
546
+ [ :parse_error, "parse error at `<!'" ]
547
+
548
+ '<!hoge'
549
+ [ :parse_error, "parse error at `<!'" ]
550
+
551
+ '<!>'
552
+ [ :on_comment, '' ]
553
+
554
+ '<!'
555
+ [ :parse_error, "parse error at `<!'" ]
556
+
557
+ '<!hoge>fuga'
558
+ [ :parse_error, "parse error at `<!'" ]
559
+ [ :on_chardata, 'fuga' ]
560
+
561
+ '<!hoge>>'
562
+ [ :parse_error, "parse error at `<!'" ]
563
+ [ :on_chardata, '>' ]
564
+
565
+ TESTCASEEND
566
+
567
+
568
+
569
+ deftestcase 'internal_dtd', <<-'TESTCASEEND'
570
+
571
+ '<!DOCTYPE hoge[ <!ENTITY fuga "hoge"> ]>'
572
+ [ :on_doctype, 'hoge', nil, nil ]
573
+ [ :parse_error, "DTD subset is found but it is not permitted in HTML" ]
574
+
575
+ TESTCASEEND
576
+
577
+
578
+
579
+ deftestcase 'doctype', <<-'TESTCASEEND'
580
+
581
+ '<!DOCTYPE hoge public "fuga">'
582
+ [ :on_doctype, 'hoge', 'fuga', nil ]
583
+
584
+ '<!DOCTYPE hoge system "fuga">'
585
+ [ :on_doctype, 'hoge', nil, 'fuga' ]
586
+
587
+ '<!DOCTYPE hoge PuBliC "fuga">'
588
+ [ :on_doctype, 'hoge', 'fuga', nil ]
589
+
590
+ '<!DOCTYPE hoge sYsTEm "fuga">'
591
+ [ :on_doctype, 'hoge', nil, 'fuga' ]
592
+
593
+ TESTCASEEND
594
+
595
+
596
+
597
+ deftestcase 'prolog', <<-'TESTCASEEND'
598
+
599
+ '<!DOCTYPE hoge><hoge>'
600
+ [ :on_doctype, 'hoge', nil, nil ]
601
+ [ :on_stag, 'hoge' ]
602
+ [ :on_stag_end, 'hoge' ]
603
+
604
+ '<!doctype hoge><hoge>'
605
+ [ :on_doctype, 'hoge', nil, nil ]
606
+ [ :on_stag, 'hoge' ]
607
+ [ :on_stag_end, 'hoge' ]
608
+
609
+ '<!dOcTyPe hoge><hoge>'
610
+ [ :on_doctype, 'hoge', nil, nil ]
611
+ [ :on_stag, 'hoge' ]
612
+ [ :on_stag_end, 'hoge' ]
613
+
614
+ '<hoge><!DOCTYPE hoge>'
615
+ [ :on_stag, 'hoge' ]
616
+ [ :on_stag_end, 'hoge' ]
617
+ [ :parse_error, "parse error at `<!'" ]
618
+
619
+ ' <!DOCTYPE hoge> <hoge>'
620
+ [ :on_prolog_space, ' ' ]
621
+ [ :on_doctype, 'hoge', nil, nil ]
622
+ [ :on_prolog_space, ' ' ]
623
+ [ :on_stag, 'hoge' ]
624
+ [ :on_stag_end, 'hoge' ]
625
+
626
+ '<!--hoge--><!DOCTYPE hoge><?fuga?><hoge>'
627
+ [ :on_comment, 'hoge' ]
628
+ [ :on_doctype, 'hoge', nil, nil ]
629
+ [ :on_pi, '', 'fuga?' ]
630
+ [ :on_stag, 'hoge' ]
631
+ [ :on_stag_end, 'hoge' ]
632
+
633
+ '<!--hoge--><!DOCTYPE hoge><!--fuga--><hoge>'
634
+ [ :on_comment, 'hoge' ]
635
+ [ :on_doctype, 'hoge', nil, nil ]
636
+ [ :on_comment, 'fuga' ]
637
+ [ :on_stag, 'hoge' ]
638
+ [ :on_stag_end, 'hoge' ]
639
+
640
+ '<!--hoge--> <hoge>'
641
+ [ :on_comment, 'hoge' ]
642
+ [ :on_prolog_space, ' ' ]
643
+ [ :on_stag, 'hoge' ]
644
+ [ :on_stag_end, 'hoge' ]
645
+
646
+ '<?hoge?> <hoge>'
647
+ [ :on_pi, '', 'hoge?' ]
648
+ [ :on_prolog_space, ' ' ]
649
+ [ :on_stag, 'hoge' ]
650
+ [ :on_stag_end, 'hoge' ]
651
+
652
+ 'hoge<!DOCTYPE hoge>'
653
+ [ :on_chardata, 'hoge' ]
654
+ [ :parse_error, "parse error at `<!'" ]
655
+
656
+ '>hoge<!DOCTYPE hoge>'
657
+ [ :on_chardata, '>hoge' ]
658
+ [ :parse_error, "parse error at `<!'" ]
659
+
660
+ '<?hoge?> fuga <!DOCTYPE hoge>'
661
+ [ :on_pi, '', 'hoge?' ]
662
+ [ :on_chardata, ' fuga ' ]
663
+ [ :parse_error, "parse error at `<!'" ]
664
+
665
+ '<!DOCTYPE hoge><!DOCTYPE fuga><hoge>'
666
+ [ :on_doctype, 'hoge', nil, nil ]
667
+ [ :parse_error, "another document type declaration is found" ]
668
+ [ :on_doctype, 'fuga', nil, nil ]
669
+ [ :on_stag, 'hoge' ]
670
+ [ :on_stag_end, 'hoge' ]
671
+
672
+ TESTCASEEND
673
+
674
+ end
675
+
676
+
677
+ class TestHTMLScannerCDATA < Test::Unit::TestCase
678
+
679
+ include DefTestCase
680
+
681
+ class CDATAContentTestVisitor < TestHTMLScanner::Visitor
682
+ def make_scanner
683
+ @scanner = XMLScan::HTMLScanner.new(self)
684
+ end
685
+ def on_stag_end(name)
686
+ super
687
+ s = @scanner.get_cdata_content
688
+ @result.push [ :cdata_content, s ]
689
+ end
690
+ end
691
+
692
+
693
+ private
694
+
695
+ def setup
696
+ @v = CDATAContentTestVisitor.new
697
+ @s = @v.make_scanner
698
+ end
699
+
700
+ def parse(src)
701
+ @s.parse src
702
+ @v.result
703
+ end
704
+
705
+
706
+ public
707
+
708
+ deftestcase 'cdata_content', <<-'TESTCASEEND'
709
+
710
+ '<hoge>fuga</hoge>'
711
+ [ :on_stag, 'hoge' ]
712
+ [ :on_stag_end, 'hoge' ]
713
+ [ :cdata_content, 'fuga' ]
714
+ [ :on_etag, 'hoge' ]
715
+
716
+ '<hoge>fuga<foo><bar>fuga</hoge>'
717
+ [ :on_stag, 'hoge' ]
718
+ [ :on_stag_end, 'hoge' ]
719
+ [ :cdata_content, 'fuga<foo><bar>fuga' ]
720
+ [ :on_etag, 'hoge' ]
721
+
722
+ '<hoge>><><><<><a><>><></hoge>'
723
+ [ :on_stag, 'hoge' ]
724
+ [ :on_stag_end, 'hoge' ]
725
+ [ :cdata_content, '><><><<><a><>><>' ]
726
+ [ :on_etag, 'hoge' ]
727
+
728
+ '<hoge>fuga</'
729
+ [ :on_stag, 'hoge' ]
730
+ [ :on_stag_end, 'hoge' ]
731
+ [ :cdata_content, 'fuga' ]
732
+ [ :parse_error, "parse error at `</'" ]
733
+ [ :on_chardata, '</' ]
734
+
735
+ '<hoge>fuga<'
736
+ [ :on_stag, 'hoge' ]
737
+ [ :on_stag_end, 'hoge' ]
738
+ [ :cdata_content, 'fuga<' ]
739
+
740
+ '<hoge>fuga>'
741
+ [ :on_stag, 'hoge' ]
742
+ [ :on_stag_end, 'hoge' ]
743
+ [ :cdata_content, 'fuga>' ]
744
+
745
+ TESTCASEEND
746
+
747
+ end
748
+
749
+
750
+
751
+
752
+ load "#{File.dirname($0)}/runtest.rb" if __FILE__ == $0