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,457 @@
1
+ #
2
+ # tests/namespace.rb
3
+ #
4
+ # Copyright (C) UENO Katsuhiro 2002
5
+ #
6
+ # $Id: testnamespace.rb,v 1.10 2003/02/28 12:31:07 katsu Exp $
7
+ #
8
+
9
+ require 'test/unit'
10
+ require 'deftestcase'
11
+ require 'xmlscan/namespace'
12
+ require 'visitor'
13
+
14
+
15
+ class TestXMLNamespace < Test::Unit::TestCase
16
+
17
+ include DefTestCase
18
+
19
+ class Visitor < RecordingVisitor.new_class(XMLScan::NSVisitor)
20
+
21
+ def on_stag_end_ns(qname, ns)
22
+ super qname, ns.dup
23
+ end
24
+
25
+ def on_stag_end_empty_ns(qname, ns)
26
+ super qname, ns.dup
27
+ end
28
+
29
+ end
30
+
31
+
32
+ private
33
+
34
+ def setup
35
+ @v = Visitor.new
36
+ @s = XMLScan::XMLParserNS.new(@v)
37
+ end
38
+
39
+ def parse(src)
40
+ @s.parse src
41
+ @v.result
42
+ end
43
+
44
+
45
+
46
+ NS_XML = 'http://www.w3.org/XML/1998/namespace'
47
+ NS_XMLNS = 'http://www.w3.org/2000/xmlns/'
48
+
49
+
50
+ public
51
+
52
+ deftestcase 'default', <<-'TESTCASEEND'
53
+
54
+ '<hoge xmlns="fuga"></hoge>'
55
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
56
+ [ :on_stag_end_ns, 'hoge', {''=>'fuga'} ]
57
+ [ :on_etag, 'hoge' ]
58
+
59
+ '<hoge xmlns="fuga"/>'
60
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
61
+ [ :on_stag_end_empty_ns, 'hoge', {''=>'fuga'} ]
62
+
63
+ '<hoge></hoge>'
64
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
65
+ [ :on_stag_end_ns, 'hoge', {} ]
66
+ [ :on_etag, 'hoge' ]
67
+
68
+ '<hoge/>'
69
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
70
+ [ :on_stag_end_empty_ns, 'hoge', {} ]
71
+
72
+ '<hoge xmlns="fuga" foo="bar"/>'
73
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
74
+ [ :on_attribute_ns, 'foo', nil, 'foo' ]
75
+ [ :on_attr_value, 'bar' ]
76
+ [ :on_attribute_end, 'foo' ]
77
+ [ :on_stag_end_empty_ns, 'hoge', {''=>'fuga'} ]
78
+
79
+ '<hoge foo="bar" xmlns="fuga"/>'
80
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
81
+ [ :on_attribute_ns, 'foo', nil, 'foo' ]
82
+ [ :on_attr_value, 'bar' ]
83
+ [ :on_attribute_end, 'foo' ]
84
+ [ :on_stag_end_empty_ns, 'hoge', {''=>'fuga'} ]
85
+
86
+ '<hoge xmlns="fu&#103;a"/>'
87
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
88
+ [ :on_stag_end_empty_ns, 'hoge', {''=>'fuga'} ]
89
+
90
+ '<hoge xmlns="fu&#x67;a"/>'
91
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
92
+ [ :on_stag_end_empty_ns, 'hoge', {''=>'fuga'} ]
93
+
94
+ '<hoge xmlns="fu&foo;a"/>'
95
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
96
+ [ :ns_wellformed_error, "xmlns includes undeclared entity reference" ]
97
+ [ :on_stag_end_empty_ns, 'hoge', {''=>'fua'} ]
98
+
99
+ '<hoge xmlns="foo"><fuga/></hoge>'
100
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
101
+ [ :on_stag_end_ns, 'hoge', {''=>'foo'} ]
102
+ [ :on_stag_ns, 'fuga', '', 'fuga' ]
103
+ [ :on_stag_end_empty_ns, 'fuga', {''=>'foo'} ]
104
+ [ :on_etag, 'hoge' ]
105
+
106
+ '<hoge xmlns="foo"><fuga xmlns="bar"/><moga/></hoge>'
107
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
108
+ [ :on_stag_end_ns, 'hoge', {''=>'foo'} ]
109
+ [ :on_stag_ns, 'fuga', '', 'fuga' ]
110
+ [ :on_stag_end_empty_ns, 'fuga', {''=>'bar'} ]
111
+ [ :on_stag_ns, 'moga', '', 'moga' ]
112
+ [ :on_stag_end_empty_ns, 'moga', {''=>'foo'} ]
113
+ [ :on_etag, 'hoge' ]
114
+
115
+ '<hoge xmlns="foo"><fuga xmlns=""><moga/></fuga></hoge>'
116
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
117
+ [ :on_stag_end_ns, 'hoge', {''=>'foo'} ]
118
+ [ :on_stag_ns, 'fuga', '', 'fuga' ]
119
+ [ :on_stag_end_ns, 'fuga', {''=>nil} ]
120
+ [ :on_stag_ns, 'moga', '', 'moga' ]
121
+ [ :on_stag_end_empty_ns, 'moga', {''=>nil} ]
122
+ [ :on_etag, 'fuga' ]
123
+ [ :on_etag, 'hoge' ]
124
+
125
+ TESTCASEEND
126
+
127
+
128
+
129
+ deftestcase 'prefix', <<-'TESTCASEEND'
130
+
131
+ '<foo:hoge xmlns:foo="fuga"></foo:hoge>'
132
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
133
+ [ :on_stag_end_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fuga'} ]
134
+ [ :on_etag, 'foo:hoge' ]
135
+
136
+ '<foo:hoge xmlns:foo="fuga"/>'
137
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
138
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fuga'} ]
139
+
140
+ '<foo:hoge></foo:hoge>'
141
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
142
+ [ :ns_wellformed_error, "prefix `foo' is not declared" ]
143
+ [ :on_stag_end_ns, 'foo:hoge', {} ]
144
+ [ :on_etag, 'foo:hoge' ]
145
+
146
+ '<foo:hoge/>'
147
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
148
+ [ :ns_wellformed_error, "prefix `foo' is not declared" ]
149
+ [ :on_stag_end_empty_ns, 'foo:hoge', {} ]
150
+
151
+ '<foo:hoge:fuga/>'
152
+ [ :ns_parse_error, "localpart `hoge:fuga' includes `:'" ]
153
+ [ :on_stag_ns, 'foo:hoge:fuga', 'foo', 'hoge:fuga' ]
154
+ [ :ns_wellformed_error, "prefix `foo' is not declared" ]
155
+ [ :on_stag_end_empty_ns, 'foo:hoge:fuga', {} ]
156
+
157
+ '<foo:hoge xmlns:foo="fuga" foo="bar"/>'
158
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
159
+ [ :on_attribute_ns, 'foo', nil, 'foo' ]
160
+ [ :on_attr_value, 'bar' ]
161
+ [ :on_attribute_end, 'foo' ]
162
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fuga'} ]
163
+
164
+ '<foo:hoge foo="bar" xmlns:foo="fuga"/>'
165
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
166
+ [ :on_attribute_ns, 'foo', nil, 'foo' ]
167
+ [ :on_attr_value, 'bar' ]
168
+ [ :on_attribute_end, 'foo' ]
169
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fuga'} ]
170
+
171
+ '<bar:hoge xmlns:foo="fuga"/>'
172
+ [ :on_stag_ns, 'bar:hoge', 'bar', 'hoge' ]
173
+ [ :ns_wellformed_error, "prefix `bar' is not declared" ]
174
+ [ :on_stag_end_empty_ns, 'bar:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fuga'} ]
175
+
176
+ '<foo:hoge xmlns:foo=""/>'
177
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
178
+ [ :ns_parse_error, "`foo' is bound to empty namespace name" ]
179
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>''} ]
180
+
181
+ '<foo:hoge xmlns:foo="fu&#103;a"/>'
182
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
183
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fuga'} ]
184
+
185
+ '<foo:hoge xmlns:foo="fu&#x67;a"/>'
186
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
187
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fuga'} ]
188
+
189
+ '<foo:hoge xmlns:foo="fu&foo;a"/>'
190
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
191
+ [ :ns_wellformed_error, "xmlns includes undeclared entity reference" ]
192
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'fua'} ]
193
+
194
+ '<foo:hoge xmlns:foo="foo"><foo:fuga/></foo:hoge>'
195
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
196
+ [ :on_stag_end_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'foo'} ]
197
+ [ :on_stag_ns, 'foo:fuga', 'foo', 'fuga' ]
198
+ [ :on_stag_end_empty_ns, 'foo:fuga', {'xmlns'=>NS_XMLNS, 'foo'=>'foo'} ]
199
+ [ :on_etag, 'foo:hoge' ]
200
+
201
+ '<foo:hoge xmlns:foo="foo"><foo:fuga xmlns:foo="bar"/><foo:moga/></foo:hoge>'
202
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
203
+ [ :on_stag_end_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'foo'} ]
204
+ [ :on_stag_ns, 'foo:fuga', 'foo', 'fuga' ]
205
+ [ :on_stag_end_empty_ns, 'foo:fuga', {'xmlns'=>NS_XMLNS, 'foo'=>'bar'} ]
206
+ [ :on_stag_ns, 'foo:moga', 'foo', 'moga' ]
207
+ [ :on_stag_end_empty_ns, 'foo:moga', {'xmlns'=>NS_XMLNS, 'foo'=>'foo'} ]
208
+ [ :on_etag, 'foo:hoge' ]
209
+
210
+ '<foo:hoge xmlns:foo="foo"><foo:fuga xmlns:foo="bar"><foo:moga/></foo:fuga></foo:hoge>'
211
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
212
+ [ :on_stag_end_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'foo'} ]
213
+ [ :on_stag_ns, 'foo:fuga', 'foo', 'fuga' ]
214
+ [ :on_stag_end_ns, 'foo:fuga', {'xmlns'=>NS_XMLNS, 'foo'=>'bar'} ]
215
+ [ :on_stag_ns, 'foo:moga', 'foo', 'moga' ]
216
+ [ :on_stag_end_empty_ns, 'foo:moga', {'xmlns'=>NS_XMLNS, 'foo'=>'bar'} ]
217
+ [ :on_etag, 'foo:fuga' ]
218
+ [ :on_etag, 'foo:hoge' ]
219
+
220
+ '<foo:hoge xmlns:foo="foo" xmlns:bar="bar"/>'
221
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
222
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'foo', 'bar'=>'bar'} ]
223
+
224
+ '<foo:hoge xmlns:foo="foo" xmlns:bar="bar"><bar:fuga/></foo:hoge>'
225
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
226
+ [ :on_stag_end_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'foo', 'bar'=>'bar'} ]
227
+ [ :on_stag_ns, 'bar:fuga', 'bar', 'fuga' ]
228
+ [ :on_stag_end_empty_ns, 'bar:fuga', {'xmlns'=>NS_XMLNS, 'foo'=>'foo', 'bar'=>'bar'} ]
229
+ [ :on_etag, 'foo:hoge' ]
230
+
231
+ '<foo:hoge xmlns:foo="foo" xmlns:bar="bar"><bar:fuga xmlns:foo="baz"/><moga/></foo:hoge>'
232
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
233
+ [ :on_stag_end_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'foo', 'bar'=>'bar'} ]
234
+ [ :on_stag_ns, 'bar:fuga', 'bar', 'fuga' ]
235
+ [ :on_stag_end_empty_ns, 'bar:fuga', {'xmlns'=>NS_XMLNS, 'foo'=>'baz', 'bar'=>'bar'} ]
236
+ [ :on_stag_ns, 'moga', '', 'moga' ]
237
+ [ :on_stag_end_empty_ns, 'moga', {'xmlns'=>NS_XMLNS, 'foo'=>'foo', 'bar'=>'bar'} ]
238
+ [ :on_etag, 'foo:hoge' ]
239
+
240
+ '<hoge><foo:hoge xmlns:foo="foo" xmlns:bar="bar"/><fuga/></hoge>'
241
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
242
+ [ :on_stag_end_ns, 'hoge', {} ]
243
+ [ :on_stag_ns, 'foo:hoge', 'foo', 'hoge' ]
244
+ [ :on_stag_end_empty_ns, 'foo:hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'foo', 'bar'=>'bar'} ]
245
+ [ :on_stag_ns, 'fuga', '', 'fuga' ]
246
+ [ :on_stag_end_empty_ns, 'fuga', {'xmlns'=>NS_XMLNS, 'foo'=>nil, 'bar'=>nil} ]
247
+ [ :on_etag, 'hoge' ]
248
+
249
+ TESTCASEEND
250
+
251
+
252
+
253
+ deftestcase 'attribute', <<-'TESTCASEEND'
254
+
255
+ '<hoge xmlns="bar" fuga="moga"/>'
256
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
257
+ [ :on_attribute_ns, 'fuga', nil, 'fuga' ]
258
+ [ :on_attr_value, 'moga' ]
259
+ [ :on_attribute_end, 'fuga' ]
260
+ [ :on_stag_end_empty_ns, 'hoge', {''=>'bar'} ]
261
+
262
+ '<hoge xmlns:foo="bar" foo:fuga="moga"/>'
263
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
264
+ [ :on_attribute_ns, 'foo:fuga', 'foo', 'fuga' ]
265
+ [ :on_attr_value, 'moga' ]
266
+ [ :on_attribute_end, 'foo:fuga' ]
267
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'bar'} ]
268
+
269
+ '<hoge xmlns:foo="bar" bar:fuga="moga"/>'
270
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
271
+ [ :on_attribute_ns, 'bar:fuga', 'bar', 'fuga' ]
272
+ [ :on_attr_value, 'moga' ]
273
+ [ :on_attribute_end, 'bar:fuga' ]
274
+ [ :ns_wellformed_error, "prefix `bar' is not declared" ]
275
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'bar'} ]
276
+
277
+ '<hoge xmlns:foo="bar"><fuga foo:baz="moga"/></hoge>'
278
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
279
+ [ :on_stag_end_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'bar'} ]
280
+ [ :on_stag_ns, 'fuga', '', 'fuga' ]
281
+ [ :on_attribute_ns, 'foo:baz', 'foo', 'baz' ]
282
+ [ :on_attr_value, 'moga' ]
283
+ [ :on_attribute_end, 'foo:baz' ]
284
+ [ :on_stag_end_empty_ns, 'fuga', {'xmlns'=>NS_XMLNS, 'foo'=>'bar'} ]
285
+ [ :on_etag, 'hoge' ]
286
+
287
+ '<hoge xmlns:foo="bar" xmlns:bar="baz" foo:fuga="moga" bar:fuga="gema"/>'
288
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
289
+ [ :on_attribute_ns, 'foo:fuga', 'foo', 'fuga' ]
290
+ [ :on_attr_value, 'moga' ]
291
+ [ :on_attribute_end, 'foo:fuga' ]
292
+ [ :on_attribute_ns, 'bar:fuga', 'bar', 'fuga' ]
293
+ [ :on_attr_value, 'gema' ]
294
+ [ :on_attribute_end, 'bar:fuga' ]
295
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'bar', 'bar'=>'baz'} ]
296
+
297
+ '<hoge xmlns:foo="bar" xmlns:bar="bar" foo:fuga="moga" bar:fuga="gema"/>'
298
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
299
+ [ :on_attribute_ns, 'foo:fuga', 'foo', 'fuga' ]
300
+ [ :on_attr_value, 'moga' ]
301
+ [ :on_attribute_end, 'foo:fuga' ]
302
+ [ :on_attribute_ns, 'bar:fuga', 'bar', 'fuga' ]
303
+ [ :on_attr_value, 'gema' ]
304
+ [ :on_attribute_end, 'bar:fuga' ]
305
+ [ :ns_wellformed_error, "doubled localpart `fuga' in the same namespace" ]
306
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'bar', 'bar'=>'bar'} ]
307
+
308
+ '<hoge foo:fuga="moga" bar:fuga="gema" xmlns:foo="bar" xmlns:bar="bar"/>'
309
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
310
+ [ :on_attribute_ns, 'foo:fuga', 'foo', 'fuga' ]
311
+ [ :on_attr_value, 'moga' ]
312
+ [ :on_attribute_end, 'foo:fuga' ]
313
+ [ :on_attribute_ns, 'bar:fuga', 'bar', 'fuga' ]
314
+ [ :on_attr_value, 'gema' ]
315
+ [ :on_attribute_end, 'bar:fuga' ]
316
+ [ :ns_wellformed_error, "doubled localpart `fuga' in the same namespace" ]
317
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'bar', 'bar'=>'bar'} ]
318
+
319
+ '<hoge xmlns:foo="moga"><fuga foo:bar="a" baz:bar="a" xmlns:baz="moga"/></hoge>'
320
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
321
+ [ :on_stag_end_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'foo'=>'moga'} ]
322
+ [ :on_stag_ns, 'fuga', '', 'fuga' ]
323
+ [ :on_attribute_ns, 'foo:bar', 'foo', 'bar' ]
324
+ [ :on_attr_value, 'a' ]
325
+ [ :on_attribute_end, 'foo:bar' ]
326
+ [ :on_attribute_ns, 'baz:bar', 'baz', 'bar' ]
327
+ [ :on_attr_value, 'a' ]
328
+ [ :on_attribute_end, 'baz:bar' ]
329
+ [ :ns_wellformed_error, "doubled localpart `bar' in the same namespace" ]
330
+ [ :on_stag_end_empty_ns, 'fuga', {'xmlns'=>NS_XMLNS, 'foo'=>'moga', 'baz'=>'moga'} ]
331
+ [ :on_etag, 'hoge' ]
332
+
333
+ '<foo foo:bar:fuga="hoge" xmlns:foo="bar" xmlns:bar="bar"/>'
334
+ [ :on_stag_ns, 'foo', '', 'foo' ]
335
+ [ :ns_parse_error, "localpart `bar:fuga' includes `:'" ]
336
+ [ :on_attribute_ns, 'foo:bar:fuga', 'foo', 'bar:fuga' ]
337
+ [ :on_attr_value, 'hoge' ]
338
+ [ :on_attribute_end, 'foo:bar:fuga' ]
339
+ [ :on_stag_end_empty_ns, 'foo', {'xmlns'=>NS_XMLNS, 'foo'=>'bar', 'bar'=>'bar'} ]
340
+
341
+ TESTCASEEND
342
+
343
+
344
+
345
+ deftestcase 'reserved', <<-'TESTCASEEND'
346
+
347
+ '<hoge xml:lang="ja"/>'
348
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
349
+ [ :on_attribute_ns, 'xml:lang', 'xml', 'lang' ]
350
+ [ :on_attr_value, 'ja' ]
351
+ [ :on_attribute_end, 'xml:lang' ]
352
+ [ :on_stag_end_empty_ns, 'hoge', {'xml'=>NS_XML} ]
353
+
354
+ '<foo><bar><baz xml:lang="ja"/></bar><hoge/></foo>'
355
+ [ :on_stag_ns, 'foo', '', 'foo' ]
356
+ [ :on_stag_end_ns, 'foo', {} ]
357
+ [ :on_stag_ns, 'bar', '', 'bar' ]
358
+ [ :on_stag_end_ns, 'bar', {} ]
359
+ [ :on_stag_ns, 'baz', '', 'baz' ]
360
+ [ :on_attribute_ns, 'xml:lang', 'xml', 'lang' ]
361
+ [ :on_attr_value, 'ja' ]
362
+ [ :on_attribute_end, 'xml:lang' ]
363
+ [ :on_stag_end_empty_ns, 'baz', {'xml'=>NS_XML} ]
364
+ [ :on_etag, 'bar' ]
365
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
366
+ [ :on_stag_end_empty_ns, 'hoge', {'xml'=>NS_XML} ]
367
+ [ :on_etag, 'foo' ]
368
+
369
+ '<xmlns:hoge/>'
370
+ [ :ns_wellformed_error, "prefix `xmlns' is not used for namespace prefix declaration" ]
371
+ [ :on_stag_ns, 'xmlns:hoge', 'xmlns', 'hoge' ]
372
+ [ :on_stag_end_empty_ns, 'xmlns:hoge', {'xmlns'=>NS_XMLNS} ]
373
+
374
+ '<hoge xmlns:xml="fuga"/>'
375
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
376
+ [ :ns_wellformed_error, "prefix `xml' can't be bound to any namespace except `http://www.w3.org/XML/1998/namespace'" ]
377
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'xml'=>'fuga'} ]
378
+
379
+ '<hoge xmlns:xml="http://www.w3.org/XML/1998/namespace"/>'
380
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
381
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'xml'=>NS_XML} ]
382
+
383
+ '<hoge xmlns:fuga="http://www.w3.org/XML/1998/namespace"/>'
384
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
385
+ [ :ns_wellformed_error, "namespace `http://www.w3.org/XML/1998/namespace' is reserved for prefix `xml'" ]
386
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'fuga'=>NS_XML} ]
387
+
388
+ '<hoge xmlns:xmlns="fuga"/>'
389
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
390
+ [ :ns_wellformed_error, "prefix `xmlns' can't be bound to any namespace explicitly" ]
391
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>'fuga'} ]
392
+
393
+ '<hoge xmlns:xmlns="http://www.w3.org/2000/xmlns/"/>'
394
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
395
+ [ :ns_wellformed_error, "prefix `xmlns' can't be bound to any namespace explicitly" ]
396
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS} ]
397
+
398
+ '<hoge xmlns:fuga="http://www.w3.org/2000/xmlns/"/>'
399
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
400
+ [ :ns_wellformed_error, "namespace `http://www.w3.org/2000/xmlns/' is reserved for prefix `xmlns'" ]
401
+ [ :on_stag_end_empty_ns, 'hoge', {'xmlns'=>NS_XMLNS, 'fuga'=>NS_XMLNS} ]
402
+
403
+ TESTCASEEND
404
+
405
+
406
+
407
+ deftestcase 'wellformedness', <<-'TESTCASEEND'
408
+
409
+ '<!DOCTYPE foo:bar><hoge/>'
410
+ [ :on_doctype, 'foo:bar', nil, nil ]
411
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
412
+ [ :on_stag_end_empty_ns, 'hoge', {} ]
413
+
414
+ '<!DOCTYPE foo:bar:baz><hoge/>'
415
+ [ :ns_parse_error, "qualified name `foo:bar:baz' includes `:'" ]
416
+ [ :on_doctype, 'foo:bar:baz', nil, nil ]
417
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
418
+ [ :on_stag_end_empty_ns, 'hoge', {} ]
419
+
420
+ '<?foo?><hoge/>'
421
+ [ :on_pi, 'foo', '' ]
422
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
423
+ [ :on_stag_end_empty_ns, 'hoge', {} ]
424
+
425
+ '<?foo:bar?><hoge/>'
426
+ [ :ns_parse_error, "PI target `foo:bar' includes `:'" ]
427
+ [ :on_pi, 'foo:bar', '' ]
428
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
429
+ [ :on_stag_end_empty_ns, 'hoge', {} ]
430
+
431
+ '<hoge fuga="&foo:bar;"/>'
432
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
433
+ [ :on_attribute_ns, 'fuga', nil, 'fuga' ]
434
+ [ :ns_parse_error, "entity reference `foo:bar' includes `:'" ]
435
+ [ :on_attr_entityref, 'foo:bar' ]
436
+ [ :on_attribute_end, 'fuga' ]
437
+ [ :on_stag_end_empty_ns, 'hoge', {} ]
438
+
439
+ '<hoge>&foo:bar;</hoge>'
440
+ [ :on_stag_ns, 'hoge', '', 'hoge' ]
441
+ [ :on_stag_end_ns, 'hoge', {} ]
442
+ [ :ns_parse_error, "entity reference `foo:bar' includes `:'" ]
443
+ [ :on_entityref, 'foo:bar' ]
444
+ [ :on_etag, 'hoge' ]
445
+
446
+ TESTCASEEND
447
+
448
+
449
+
450
+
451
+
452
+ end
453
+
454
+
455
+
456
+
457
+ load "#{File.dirname($0)}/runtest.rb" if __FILE__ == $0