rxsd 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ # tests the loader module
2
+ #
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
+ # See COPYING for the License of this software
5
+
6
+ require File.dirname(__FILE__) + '/spec_helper'
7
+
8
+ describe "Loader" do
9
+
10
+ it "should load file" do
11
+ File.write("/tmp/rxsd-test", "foobar")
12
+ data = RXSD::Loader.load("file:///tmp/rxsd-test")
13
+ data.should == "foobar"
14
+ end
15
+
16
+ it "should load http uri" do
17
+ # uploaded a minimal test to projects.morsi.org
18
+ data = RXSD::Loader.load("http://projects.morsi.org/rxsd/test-schema1.xsd")
19
+ data.should == "foobar\n"
20
+ end
21
+
22
+ end
@@ -0,0 +1,475 @@
1
+ # tests the parser module
2
+ #
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
+ # See COPYING for the License of this software
5
+
6
+ require File.dirname(__FILE__) + '/spec_helper'
7
+
8
+ describe "Parser" do
9
+
10
+ it "should parse xsd" do
11
+ File.write("/tmp/rxsd-test", "<schema><element name='foo' type='xs:boolean' />" +
12
+ "<complexType><choice><element ref='foo' /></choice></complexType></schema>")
13
+ schema = Parser.parse_xsd :uri => "file:///tmp/rxsd-test"
14
+ schema.elements.size.should == 1
15
+ schema.complex_types.size.should == 1
16
+ schema.elements[0].name.should == "foo"
17
+ schema.elements[0].type.should == Boolean
18
+ schema.complex_types[0].choice.elements[0].ref.name.should == "foo"
19
+ schema.complex_types[0].choice.elements[0].ref.type.should == Boolean
20
+ end
21
+
22
+ it "should identifity builtin types" do
23
+ Parser.is_builtin?(String).should == true
24
+ Parser.is_builtin?(Boolean).should == true
25
+ Parser.is_builtin?(XSDFloat).should == true
26
+ Parser.is_builtin?(XSDInteger).should == true
27
+ !Parser.is_builtin?(Parser).should == true
28
+ end
29
+
30
+ it "should parse builtin types" do
31
+ Parser.parse_builtin_type("xs:string").should == String
32
+ Parser.parse_builtin_type("xs:boolean").should == Boolean
33
+ Parser.parse_builtin_type("xs:decimal").should == XSDFloat
34
+ Parser.parse_builtin_type("xs:float").should == XSDFloat
35
+ Parser.parse_builtin_type("xs:double").should == XSDFloat
36
+ end
37
+
38
+ it "should parse schema" do
39
+ data = "<schema version='4.20' targetNamespace='foobar' xmlns='http://www.w3.org/2001/XMLSchema' xmlns:foo='http://morsi.org/myschema' " +
40
+ " elementFormDefault='qualified' attributeFormDefault='unqualified' />"
41
+ doc = LibXML::XML::Document.string data
42
+ schema = Schema.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root))
43
+ schema.namespaces.size.should == 2
44
+ schema.targetNamespace.should == 'foobar'
45
+ schema.namespaces[nil].should == 'http://www.w3.org/2001/XMLSchema'
46
+ schema.namespaces['foo'].should == 'http://morsi.org/myschema'
47
+ schema.elementFormDefault.should == "qualified"
48
+ schema.attributeFormDefault.should == "unqualified"
49
+
50
+ data = "<schema><element id='foo'/></schema>"
51
+ doc = LibXML::XML::Document.string data
52
+ schema = Schema.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root))
53
+ schema.elements.size.should == 1
54
+ schema.elements[0].id.should == "foo"
55
+
56
+ data = "<schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element id='foo'/></schema>"
57
+ doc = LibXML::XML::Document.string data
58
+ schema = Schema.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root))
59
+ schema.elements.size.should == 1
60
+ schema.elements[0].id.should == "foo"
61
+ end
62
+
63
+ it "should parse element" do
64
+ data = '<s xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
65
+ '<xs:element id="iii" name="xxx" type="yyy" default="Foobar" maxOccurs="5" '+
66
+ ' nillable="true" abstract="true" ref="Foo" form="qualified" />' +
67
+ '</s>'
68
+ doc = LibXML::XML::Document.string data
69
+ element = Element.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
70
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
71
+ element.id.should == "iii"
72
+ element.name.should == "xxx"
73
+ element.type.should == "yyy"
74
+ element.default.should == nil
75
+ element.maxOccurs.should == 5
76
+ element.minOccurs.should == 1
77
+ element.nillable.should == true
78
+ element.abstract.should == true
79
+ element.ref.should == "Foo"
80
+ element.form.should == "qualified"
81
+
82
+ data = '<s xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
83
+ '<xs:element default="Foobar" minOccurs="unbounded">' +
84
+ '<Foo/>' +
85
+ '</xs:element>' +
86
+ '</s>'
87
+ doc = LibXML::XML::Document.string data
88
+ element = Element.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
89
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
90
+ element.default.should == nil
91
+ element.minOccurs.should == "unbounded"
92
+
93
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">'+
94
+ '<xs:element id="iii" ref="Foo" />'+
95
+ '</schema>'
96
+ doc = LibXML::XML::Document.string data
97
+ element = Element.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
98
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
99
+ element.id.should == "iii"
100
+ element.ref.should == nil
101
+ element.form.should == "unqualified"
102
+
103
+ data = '<s xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
104
+ '<xs:element default="Foobar" minOccurs="unbounded">' +
105
+ '<simpleType id="foobar"/>' +
106
+ '</xs:element>'+
107
+ '</s>'
108
+ doc = LibXML::XML::Document.string data
109
+ element = Element.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
110
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
111
+ element.default.should == "Foobar"
112
+ element.simple_type.id.should == "foobar"
113
+ end
114
+
115
+ it "should parse complex type" do
116
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
117
+ '<xs:complexType id="iii" name="xxx" abstract="true" mixed="true">' +
118
+ '<xs:attribute name="Foo" />' +
119
+ '<xs:attribute name="Bar" />' +
120
+ '<xs:group name="Gr" />' +
121
+ '</xs:complexType>' +
122
+ '</schema>'
123
+ doc = LibXML::XML::Document.string data
124
+ complexType = ComplexType.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
125
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
126
+ complexType.id.should == "iii"
127
+ complexType.name.should == "xxx"
128
+ complexType.abstract.should == true
129
+ complexType.mixed.should == true
130
+ complexType.attributes.size.should == 2
131
+ complexType.attributes[0].name.should == "Foo"
132
+ complexType.attributes[1].name.should == "Bar"
133
+ complexType.group.name.should == "Gr"
134
+
135
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
136
+ '<xs:complexType mixed="true">' +
137
+ '<xs:simpleContent id="123" />' +
138
+ '</xs:complexType>' +
139
+ '</schema>'
140
+ doc = LibXML::XML::Document.string data
141
+ complexType = ComplexType.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
142
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
143
+ complexType.mixed.should == false
144
+ complexType.simple_content.id.should == "123"
145
+ end
146
+
147
+ it "should parse simple type" do
148
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
149
+ '<xs:simpleType id="iii" name="xxx">' +
150
+ '<xs:restriction id="rs1" />' +
151
+ '<xs:list id="li1" />' +
152
+ '</xs:simpleType>' +
153
+ '</schema>'
154
+ doc = LibXML::XML::Document.string data
155
+ simpleType = SimpleType.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
156
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
157
+ simpleType.id.should == "iii"
158
+ simpleType.name.should == "xxx"
159
+ simpleType.restriction.id.should == "rs1"
160
+ simpleType.list.id.should == "li1"
161
+ end
162
+
163
+ it "should parse attribute" do
164
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
165
+ '<xs:attribute id="at1" name="at1" use="optional" form="qualified" default="123" type="foo" />' +
166
+ '</schema>'
167
+ doc = LibXML::XML::Document.string data
168
+ attr = Attribute.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
169
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
170
+ attr.id.should == "at1"
171
+ attr.name.should == "at1"
172
+ attr.form.should == "qualified"
173
+ attr.default.should == "123"
174
+ attr.type.should == "foo"
175
+ attr.simple_type.should == nil
176
+
177
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" >' +
178
+ '<xs:attribute id="at2" fixed="123" type="foo">' +
179
+ '<xs:simpleType id="st1" />' +
180
+ '</xs:attribute>' +
181
+ '</schema>'
182
+ doc = LibXML::XML::Document.string data
183
+ attr = Attribute.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
184
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
185
+ attr.id.should == "at2"
186
+ attr.form.should == "unqualified"
187
+ attr.type.should == nil
188
+ attr.simple_type.should_not be_nil
189
+ attr.simple_type.id.should == "st1"
190
+ end
191
+
192
+ it "should parse attribute group" do
193
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
194
+ '<xs:attributeGroup id="ag1" name="ag1" ref="ag2">' +
195
+ '<xs:attribute id="a1" />' +
196
+ '<xs:attribute id="a2" />' +
197
+ '<xs:attributeGroup id="ag3" />' +
198
+ '</xs:attributeGroup>' +
199
+ '</schema>'
200
+ doc = LibXML::XML::Document.string data
201
+ attrGroup = AttributeGroup.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
202
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
203
+ attrGroup.id.should == "ag1"
204
+ attrGroup.name.should == "ag1"
205
+ attrGroup.ref.should == "ag2"
206
+ attrGroup.attributes.size.should == 2
207
+ attrGroup.attribute_groups.size.should == 1
208
+ attrGroup.attributes[0].id.should == "a1"
209
+ attrGroup.attributes[1].id.should == "a2"
210
+ attrGroup.attribute_groups[0].id.should == "ag3"
211
+ end
212
+
213
+ it "should parse group" do
214
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
215
+ '<xs:group id="g1" name="g1" maxOccurs="5" minOccurs="unbounded">' +
216
+ '<xs:choice id="c1" />' +
217
+ '</xs:group>' +
218
+ '</schema>'
219
+ doc = LibXML::XML::Document.string data
220
+ group = Group.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
221
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
222
+ group.id.should == "g1"
223
+ group.name.should == "g1"
224
+ group.maxOccurs.should == 5
225
+ group.minOccurs.should == "unbounded"
226
+ group.choice.id.should == "c1"
227
+
228
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
229
+ '<xs:group id="g2" ref="g1" >'+
230
+ '<xs:sequence id="s1" />' +
231
+ '</xs:group>' +
232
+ '</schema>'
233
+ doc = LibXML::XML::Document.string data
234
+ group = Group.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
235
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))
236
+ group.ref.should == "g1"
237
+ group.minOccurs.should == 1
238
+ group.maxOccurs.should == 1
239
+ group.sequence.id.should == "s1"
240
+ end
241
+
242
+ it "should parse list" do
243
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
244
+ '<xs:simpleType id="st1" name="st1">' +
245
+ '<xs:list id="li1" itemType="Foo">' +
246
+ '<xs:simpleType id="st2" />' +
247
+ '</xs:list>' +
248
+ '</xs:simpleType>' +
249
+ '</schema>'
250
+ doc = LibXML::XML::Document.string data
251
+ list = List.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
252
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0])))
253
+ list.id.should == "li1"
254
+ list.itemType.should == nil
255
+ list.simple_type.id.should == "st2"
256
+
257
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
258
+ '<xs:simpleType id="st1" name="st1">' +
259
+ '<xs:list id="li1" itemType="Foo" />' +
260
+ '</xs:simpleType>' +
261
+ '</schema>'
262
+ doc = LibXML::XML::Document.string data
263
+ list = List.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
264
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0])))
265
+ list.itemType.should == "Foo"
266
+ end
267
+
268
+ it "should parse simple content" do
269
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
270
+ '<xs:complexType id="ct1">' +
271
+ '<xs:simpleContent id="sc1">' +
272
+ ' <xs:restriction id="r1" />' +
273
+ '</xs:simpleContent>' +
274
+ '</xs:complexType>' +
275
+ '</schema>'
276
+ doc = LibXML::XML::Document.string data
277
+ simple_content = SimpleContent.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
278
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0])))
279
+ simple_content.id.should == "sc1"
280
+ simple_content.restriction.id.should == "r1"
281
+ end
282
+
283
+ it "should parse choice" do
284
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
285
+ '<xs:complexType id="ct1">' +
286
+ '<xs:choice id="c1" maxOccurs="5" minOccurs="unbounded" >' +
287
+ ' <xs:element id="e1" />' +
288
+ ' <xs:element id="e2" />' +
289
+ ' <xs:element id="e3" />' +
290
+ ' <xs:choice id="c2" />' +
291
+ ' <xs:choice id="c3" />' +
292
+ '</xs:choice>' +
293
+ '</xs:complexType>' +
294
+ '</schema>'
295
+ doc = LibXML::XML::Document.string data
296
+ choice = Choice.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
297
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
298
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root ))))
299
+ choice.id.should == "c1"
300
+ choice.maxOccurs.should == 5
301
+ choice.minOccurs.should == "unbounded"
302
+ choice.elements.size.should == 3
303
+ choice.elements[1].id.should == "e2"
304
+ choice.choices.size.should == 2
305
+ choice.choices[0].id.should == "c2"
306
+
307
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
308
+ '<xs:complexType id="ct1">' +
309
+ '<xs:choice id="c1" >'+
310
+ ' <xs:sequence id="s1" />' +
311
+ '</xs:choice>' +
312
+ '</xs:complexType>' +
313
+ '</schema>'
314
+ doc = LibXML::XML::Document.string data
315
+ choice = Choice.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
316
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0])))
317
+ choice.maxOccurs.should == 1
318
+ choice.minOccurs.should == 1
319
+ choice.sequences.size.should == 1
320
+ choice.sequences[0].id.should == "s1"
321
+ end
322
+
323
+ it "should parse complex content" do
324
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
325
+ '<xs:complexType id="ct1" name="ct1">' +
326
+ '<xs:complexContent id="cc1" mixed="true">' +
327
+ '<xs:restriction id="r1"/>' +
328
+ '</xs:complexContent>' +
329
+ '</xs:complexType>' +
330
+ '</schema>'
331
+ doc = LibXML::XML::Document.string data
332
+ complexContent = ComplexContent.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
333
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0])))
334
+ complexContent.id.should == "cc1"
335
+ complexContent.mixed.should == true
336
+ complexContent.restriction.id.should == "r1"
337
+ end
338
+
339
+ it "should parse sequence" do
340
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
341
+ '<xs:complexType id="ct1">' +
342
+ '<xs:sequence id="s1" maxOccurs="5" minOccurs="unbounded" >' +
343
+ ' <xs:element id="e1" />' +
344
+ ' <xs:element id="e2" />' +
345
+ ' <xs:element id="e3" />' +
346
+ ' <xs:choice id="c2" />' +
347
+ ' <xs:choice id="c3" />' +
348
+ '</xs:sequence>' +
349
+ '</xs:complexType>' +
350
+ '</schema>'
351
+ doc = LibXML::XML::Document.string data
352
+ seq = Sequence.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
353
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
354
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root ))))
355
+ seq.id.should == "s1"
356
+ seq.maxOccurs.should == 5
357
+ seq.minOccurs.should == "unbounded"
358
+ seq.elements.size.should == 3
359
+ seq.elements[1].id.should == "e2"
360
+ seq.choices.size.should == 2
361
+ seq.choices[0].id.should == "c2"
362
+ end
363
+
364
+ it "should parse extension" do
365
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
366
+ '<xs:complexType id="ct1" name="ct1">' +
367
+ '<xs:complexContent id="cc1" mixed="true">' +
368
+ '<xs:extension id="e1" base="Foo">' +
369
+ '<xs:group id="g1" />' +
370
+ '<xs:attribute id="a1" />' +
371
+ '<xs:attribute id="a2" />' +
372
+ '</xs:extension>' +
373
+ '</xs:complexContent>' +
374
+ '</xs:complexType>' +
375
+ '</schema>'
376
+ doc = LibXML::XML::Document.string data
377
+ ext = Extension.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0].children[0],
378
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
379
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
380
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))))
381
+ ext.id.should == "e1"
382
+ ext.base.should == "Foo"
383
+ ext.group.id.should == "g1"
384
+ ext.attributes.size.should == 2
385
+ ext.attributes[0].id.should == "a1"
386
+ end
387
+
388
+ it "should parse restriction" do
389
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
390
+ '<xs:complexType id="ct1" name="ct1">' +
391
+ '<xs:complexContent id="cc1" mixed="true">' +
392
+ '<xs:restriction id="r1" base="xs:integer">' +
393
+ '<xs:attributeGroup id="ag1" />' +
394
+ '<xs:attributeGroup id="ag2" />' +
395
+ '<xs:minLength id="5" />' +
396
+ '</xs:restriction>' +
397
+ '</xs:complexContent>' +
398
+ '</xs:complexType>' +
399
+ '</schema>'
400
+ doc = LibXML::XML::Document.string data
401
+ res = Restriction.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0].children[0],
402
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
403
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
404
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))))
405
+ res.id.should == "r1"
406
+ res.base.should == "xs:integer"
407
+ res.attribute_groups.size.should == 2
408
+ res.min_length.should == nil
409
+
410
+ data = '<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' +
411
+ '<xs:complexType id="ct1" name="ct1">' +
412
+ '<xs:simpleContent id="sc1">' +
413
+ '<xs:restriction id="r1">'+
414
+ '<xs:attributeGroup id="ag1" />' +
415
+ '<xs:attributeGroup id="ag2" />' +
416
+ '<xs:minLength value="5" />' +
417
+ '<xs:maxExclusive value="15" />' +
418
+ '<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>' +
419
+ '<xs:enumeration value="foo"/>' +
420
+ '<xs:enumeration value="bar"/>' +
421
+ '</xs:restriction>' +
422
+ '</xs:simpleContent>' +
423
+ '</xs:complexType>' +
424
+ '</schema>'
425
+ doc = LibXML::XML::Document.string data
426
+ res = Restriction.from_xml(RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0].children[0],
427
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0].children[0],
428
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root.children[0],
429
+ :parent => RXSD::XML::LibXMLNode.new(:node => doc.root)))))
430
+ res.attribute_groups.size.should == 2
431
+ res.min_length.should == 5
432
+ res.max_exclusive.should == 15
433
+ res.pattern.should == "[a-zA-Z][a-zA-Z][a-zA-Z]"
434
+ res.enumerations.size.should == 2
435
+ res.enumerations[0].should == "foo"
436
+ end
437
+
438
+
439
+ ##########################################################
440
+
441
+ it "should parse xml" do
442
+ data = "<root_tag some_string='foo' MyInt='bar' >" +
443
+ "<child_tag>" +
444
+ "<grandchild_tag id='25' />" +
445
+ "</child_tag>" +
446
+ "</root_tag>"
447
+
448
+ schema_instance = Parser.parse_xml :raw => data
449
+ schema_instance.object_builders.size.should == 3
450
+ rt = schema_instance.object_builders.find { |ob| ob.tag_name == "root_tag" }
451
+ ct = schema_instance.object_builders.find { |ob| ob.tag_name == "child_tag" }
452
+ gt = schema_instance.object_builders.find { |ob| ob.tag_name == "grandchild_tag" }
453
+
454
+ rt.should_not be_nil
455
+ ct.should_not be_nil
456
+ gt.should_not be_nil
457
+
458
+ #rt.children.size.should == 1
459
+ #rt.children[0].should == ct
460
+
461
+ #ct.children.size.should == 1
462
+ #ct.children[0].should == gt
463
+
464
+ rt.attributes.size.should == 2
465
+ rt.attributes.has_key?("some_string").should be == true
466
+ rt.attributes["some_string"].should == "foo"
467
+ rt.attributes.has_key?("MyInt").should == true
468
+ rt.attributes["MyInt"].should == "bar"
469
+
470
+ #gt.children.size.should == 0
471
+ gt.attributes.has_key?("id").should == true
472
+ gt.attributes["id"].should == "25"
473
+ end
474
+
475
+ end