libxml-ruby 4.1.1-x64-mingw-ucrt → 4.1.2-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,27 @@
1
- # encoding: UTF-8
2
-
3
- module LibXML
4
- module XML
5
- class Schema::Element
6
- def required?
7
- !min_occurs.zero?
8
- end
9
-
10
- def array?
11
- max_occurs > 1
12
- end
13
-
14
- def elements
15
- type.elements
16
- end
17
- end
18
- end
19
- end
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Schema::Element
6
+ def min_occurs
7
+ @min
8
+ end
9
+
10
+ def max_occurs
11
+ @max
12
+ end
13
+
14
+ def required?
15
+ !min_occurs.zero?
16
+ end
17
+
18
+ def array?
19
+ max_occurs > 1
20
+ end
21
+
22
+ def elements
23
+ type.elements
24
+ end
25
+ end
26
+ end
27
+ end
data/test/test_schema.rb CHANGED
@@ -1,231 +1,237 @@
1
- # encoding: UTF-8
2
-
3
- require_relative './test_helper'
4
-
5
- class TestSchema < Minitest::Test
6
- Import_NS = 'http://xml4r.org/libxml-ruby/test/shiporder'.freeze
7
-
8
- def setup
9
- file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
10
- @doc = LibXML::XML::Document.file(file)
11
- schema_file = File.join(File.dirname(__FILE__), 'model/shiporder.xsd')
12
- schema_doc = LibXML::XML::Document.file(schema_file)
13
- @schema = LibXML::XML::Schema.document(schema_doc)
14
- end
15
-
16
- def teardown
17
- @doc = nil
18
- @schema = nil
19
- end
20
-
21
- def check_error(error)
22
- refute_nil(error)
23
- assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
24
- assert_kind_of(LibXML::XML::Error, error)
25
- assert_equal(LibXML::XML::Error::SCHEMASV, error.domain)
26
- assert_equal(LibXML::XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
27
- assert_equal(LibXML::XML::Error::ERROR, error.level)
28
- assert(error.file.match(/shiporder.xml/)) if error.file
29
- assert_nil(error.str1)
30
- assert_nil(error.str2)
31
- assert_nil(error.str3)
32
- assert_equal(0, error.int1)
33
- assert_equal(0, error.int2)
34
- end
35
-
36
- def test_load_from_doc
37
- assert_instance_of(LibXML::XML::Schema, @schema)
38
- end
39
-
40
- def test_schema_load_from_uri
41
- xlink_schema = LibXML::XML::Schema.new('http://www.w3.org/1999/xlink.xsd')
42
- assert_instance_of(LibXML::XML::Schema, xlink_schema)
43
- assert_instance_of(LibXML::XML::Schema::Element, xlink_schema.elements['title'])
44
- assert_instance_of(LibXML::XML::Schema::Type, xlink_schema.types['titleEltType'])
45
- assert_equal('http://www.w3.org/1999/xlink', xlink_schema.target_namespace)
46
- end
47
-
48
- def test_schema_from_string
49
- schema_file = File.join(File.dirname(__FILE__), 'model/shiporder.xsd')
50
- schema_from_str = LibXML::XML::Schema.from_string(File.read(schema_file))
51
- assert_instance_of(LibXML::XML::Schema, schema_from_str)
52
- end
53
-
54
- def test_invalid_schema_doc
55
- bad_schema_file = File.join(File.dirname(__FILE__), 'model/shiporder_bad.xsd')
56
- bad_schema_doc = LibXML::XML::Document.file(bad_schema_file)
57
- bad_schema = nil
58
- ## Note: this type of error throws
59
- begin
60
- bad_schema = LibXML::XML::Schema.document(bad_schema_doc)
61
- rescue LibXML::XML::Error => error
62
- bad_schema = error
63
- assert(error.message.match(/Error: Element '.*': The content is not valid. Expected is \(/))
64
- assert_kind_of(LibXML::XML::Error, error)
65
- assert_equal(LibXML::XML::Error::SCHEMASP, error.domain)
66
- assert_equal(LibXML::XML::Error::SCHEMAP_S4S_ELEM_NOT_ALLOWED, error.code)
67
- assert_equal(LibXML::XML::Error::ERROR, error.level)
68
- assert(error.file.match(/shiporder_bad.xsd/))
69
- assert_equal("Element '{http://www.w3.org/2001/XMLSchema}complexType'", error.str1)
70
- refute_nil(error.str2)
71
- assert_nil(error.str3)
72
- assert_equal(0, error.int1)
73
- assert_equal(0, error.int2)
74
- end
75
- ## Last but not least, make sure we threw an error
76
- assert_instance_of(LibXML::XML::Error, bad_schema)
77
- end
78
-
79
- def test_doc_valid
80
- assert(@doc.validate_schema(@schema))
81
- end
82
-
83
- def test_doc_invalid
84
- new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
85
- @doc.root << new_node
86
-
87
- error = assert_raises(LibXML::XML::Error) do
88
- @doc.validate_schema(@schema)
89
- end
90
-
91
- check_error(error)
92
- assert_nil(error.line)
93
- refute_nil(error.node)
94
- assert_equal('invalid', error.node.name)
95
- end
96
-
97
- def test_reader_valid
98
- reader = LibXML::XML::Reader.string(@doc.to_s)
99
- assert(reader.schema_validate(@schema))
100
-
101
- while reader.read
102
- end
103
- end
104
-
105
- def test_reader_invalid
106
- # Set error handler
107
- errors = Array.new
108
- LibXML::XML::Error.set_handler do |error|
109
- errors << error
110
- end
111
-
112
- new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
113
- @doc.root << new_node
114
- reader = LibXML::XML::Reader.string(@doc.to_s)
115
-
116
- # Set a schema
117
- assert(reader.schema_validate(@schema))
118
-
119
- while reader.read
120
- end
121
-
122
- assert_equal(1, errors.length)
123
-
124
- error = errors.first
125
- check_error(error)
126
- assert_equal(21, error.line)
127
- ensure
128
- LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
129
- end
130
-
131
-
132
- # Schema meta-data tests
133
- def test_elements
134
- assert_instance_of(Hash, @schema.elements)
135
- assert_equal(1, @schema.elements.length)
136
- assert_instance_of(LibXML::XML::Schema::Element, @schema.elements['shiporder'])
137
- end
138
-
139
- def test_types
140
- assert_instance_of(Hash, @schema.types)
141
- assert_equal(1, @schema.types.length)
142
- assert_instance_of(LibXML::XML::Schema::Type, @schema.types['shiporderType'])
143
- end
144
-
145
- def test_imported_types
146
- assert_instance_of(Hash, @schema.imported_types)
147
- assert_equal(2, @schema.imported_types.length)
148
- assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_types['shiporderType'])
149
- assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_types['shiporderFooType'])
150
- end
151
-
152
- def test_imported_ns_types
153
- assert_instance_of(Hash, @schema.imported_ns_types)
154
- assert_equal(2, @schema.imported_ns_types.length)
155
- assert_equal(1, @schema.imported_ns_types[nil].length)
156
- assert_equal(1, @schema.imported_ns_types[Import_NS].length)
157
- assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_ns_types[nil]['shiporderType'])
158
- assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_ns_types[Import_NS]['shiporderFooType'])
159
- end
160
-
161
- def test_imported_ns_elements
162
- assert_instance_of(Hash, @schema.imported_ns_elements)
163
- assert_equal(2, @schema.imported_ns_elements.length)
164
- assert_equal(1, @schema.imported_ns_elements[nil].length)
165
- assert_equal(1, @schema.imported_ns_elements[Import_NS].length)
166
- assert_instance_of(LibXML::XML::Schema::Element, @schema.imported_ns_elements[nil]['shiporder'])
167
- assert_instance_of(LibXML::XML::Schema::Element, @schema.imported_ns_elements[Import_NS]['shiporder'])
168
- assert_equal('shiporderType', @schema.imported_ns_elements[nil]['shiporder'].type.name)
169
- assert_equal('shiporderFooType', @schema.imported_ns_elements[Import_NS]['shiporder'].type.name)
170
- end
171
-
172
- def test_namespaces
173
- assert_instance_of(Array, @schema.namespaces)
174
- ## For some reason, when importing another schema we end up with two xs->http://www.w3.org/2001/XMLSchema namespaces.
175
- ## So, we expect 3 here (one for Import_NS and then two for the schema namespace.
176
- assert_equal(3, @schema.namespaces.length)
177
- end
178
-
179
- def test_schema_type
180
- type = @schema.types['shiporderType']
181
-
182
- assert_equal('shiporderType', type.name)
183
- assert_nil(type.namespace)
184
- assert_equal("Shiporder type documentation", type.annotation)
185
- assert_instance_of(LibXML::XML::Node, type.node)
186
- assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind)
187
- assert_instance_of(LibXML::XML::Schema::Type, type.base)
188
- assert_equal("anyType", type.base.name)
189
- assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind)
190
-
191
- assert_instance_of(Hash, type.elements)
192
- assert_equal(3, type.elements.length)
193
- end
194
-
195
- def test_schema_element
196
- element = @schema.types['shiporderType'].elements['orderperson']
197
-
198
- assert_equal('orderperson', element.name)
199
- assert_nil(element.namespace)
200
- assert_equal("orderperson element documentation", element.annotation)
201
-
202
- element = @schema.types['shiporderType'].elements['item']
203
- assert_equal('item', element.name)
204
-
205
- element = @schema.types['shiporderType'].elements['item'].type.elements['note']
206
- assert_equal('note', element.name)
207
- assert_equal('string', element.type.name)
208
- end
209
-
210
- def test_schema_attributes
211
- type = @schema.types['shiporderType']
212
-
213
- assert_instance_of(Array, type.attributes)
214
- assert_equal(2, type.attributes.length)
215
- assert_instance_of(LibXML::XML::Schema::Attribute, type.attributes.first)
216
- end
217
-
218
- def test_schema_attribute
219
- attribute = @schema.types['shiporderType'].attributes.first
220
-
221
- assert_equal("orderid", attribute.name)
222
- assert_nil(attribute.namespace)
223
- assert_equal(1, attribute.occurs)
224
- assert_equal('string', attribute.type.name)
225
-
226
- attribute = @schema.types['shiporderType'].attributes[1]
227
- assert_equal(2, attribute.occurs)
228
- assert_equal('1', attribute.default)
229
- assert_equal('integer', attribute.type.name)
230
- end
231
- end
1
+ # encoding: UTF-8
2
+
3
+ require_relative './test_helper'
4
+
5
+ class TestSchema < Minitest::Test
6
+ Import_NS = 'http://xml4r.org/libxml-ruby/test/shiporder'.freeze
7
+
8
+ def setup
9
+ file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
10
+ @doc = LibXML::XML::Document.file(file)
11
+ schema_file = File.join(File.dirname(__FILE__), 'model/shiporder.xsd')
12
+ schema_doc = LibXML::XML::Document.file(schema_file)
13
+ @schema = LibXML::XML::Schema.document(schema_doc)
14
+ end
15
+
16
+ def teardown
17
+ @doc = nil
18
+ @schema = nil
19
+ end
20
+
21
+ def check_error(error)
22
+ refute_nil(error)
23
+ assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
24
+ assert_kind_of(LibXML::XML::Error, error)
25
+ assert_equal(LibXML::XML::Error::SCHEMASV, error.domain)
26
+ assert_equal(LibXML::XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
27
+ assert_equal(LibXML::XML::Error::ERROR, error.level)
28
+ assert(error.file.match(/shiporder.xml/)) if error.file
29
+ assert_nil(error.str1)
30
+ assert_nil(error.str2)
31
+ assert_nil(error.str3)
32
+ assert_equal(0, error.int1)
33
+ assert_equal(0, error.int2)
34
+ end
35
+
36
+ def test_load_from_doc
37
+ assert_instance_of(LibXML::XML::Schema, @schema)
38
+ end
39
+
40
+ def test_schema_load_from_uri
41
+ xlink_schema = LibXML::XML::Schema.new('http://www.w3.org/1999/xlink.xsd')
42
+ assert_instance_of(LibXML::XML::Schema, xlink_schema)
43
+ assert_instance_of(LibXML::XML::Schema::Element, xlink_schema.elements['title'])
44
+ assert_instance_of(LibXML::XML::Schema::Type, xlink_schema.types['titleEltType'])
45
+ assert_equal('http://www.w3.org/1999/xlink', xlink_schema.target_namespace)
46
+ end
47
+
48
+ def test_schema_from_string
49
+ schema_file = File.join(File.dirname(__FILE__), 'model/shiporder.xsd')
50
+ schema_from_str = LibXML::XML::Schema.from_string(File.read(schema_file))
51
+ assert_instance_of(LibXML::XML::Schema, schema_from_str)
52
+ end
53
+
54
+ def test_invalid_schema_doc
55
+ bad_schema_file = File.join(File.dirname(__FILE__), 'model/shiporder_bad.xsd')
56
+ bad_schema_doc = LibXML::XML::Document.file(bad_schema_file)
57
+ bad_schema = nil
58
+ ## Note: this type of error throws
59
+ begin
60
+ bad_schema = LibXML::XML::Schema.document(bad_schema_doc)
61
+ rescue LibXML::XML::Error => error
62
+ bad_schema = error
63
+ assert(error.message.match(/Error: Element '.*': The content is not valid. Expected is \(/))
64
+ assert_kind_of(LibXML::XML::Error, error)
65
+ assert_equal(LibXML::XML::Error::SCHEMASP, error.domain)
66
+ assert_equal(LibXML::XML::Error::SCHEMAP_S4S_ELEM_NOT_ALLOWED, error.code)
67
+ assert_equal(LibXML::XML::Error::ERROR, error.level)
68
+ assert(error.file.match(/shiporder_bad.xsd/))
69
+ assert_equal("Element '{http://www.w3.org/2001/XMLSchema}complexType'", error.str1)
70
+ refute_nil(error.str2)
71
+ assert_nil(error.str3)
72
+ assert_equal(0, error.int1)
73
+ assert_equal(0, error.int2)
74
+ end
75
+ ## Last but not least, make sure we threw an error
76
+ assert_instance_of(LibXML::XML::Error, bad_schema)
77
+ end
78
+
79
+ def test_doc_valid
80
+ assert(@doc.validate_schema(@schema))
81
+ end
82
+
83
+ def test_doc_invalid
84
+ new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
85
+ @doc.root << new_node
86
+
87
+ error = assert_raises(LibXML::XML::Error) do
88
+ @doc.validate_schema(@schema)
89
+ end
90
+
91
+ check_error(error)
92
+ assert_nil(error.line)
93
+ refute_nil(error.node)
94
+ assert_equal('invalid', error.node.name)
95
+ end
96
+
97
+ def test_reader_valid
98
+ reader = LibXML::XML::Reader.string(@doc.to_s)
99
+ assert(reader.schema_validate(@schema))
100
+
101
+ while reader.read
102
+ end
103
+ end
104
+
105
+ def test_reader_invalid
106
+ # Set error handler
107
+ errors = Array.new
108
+ LibXML::XML::Error.set_handler do |error|
109
+ errors << error
110
+ end
111
+
112
+ new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
113
+ @doc.root << new_node
114
+ reader = LibXML::XML::Reader.string(@doc.to_s)
115
+
116
+ # Set a schema
117
+ assert(reader.schema_validate(@schema))
118
+
119
+ while reader.read
120
+ end
121
+
122
+ assert_equal(1, errors.length)
123
+
124
+ error = errors.first
125
+ check_error(error)
126
+ assert_equal(21, error.line)
127
+ ensure
128
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
129
+ end
130
+
131
+
132
+ # Schema meta-data tests
133
+ def test_elements
134
+ assert_instance_of(Hash, @schema.elements)
135
+ assert_equal(1, @schema.elements.length)
136
+ assert_instance_of(LibXML::XML::Schema::Element, @schema.elements['shiporder'])
137
+ end
138
+
139
+ def test_types
140
+ assert_instance_of(Hash, @schema.types)
141
+ assert_equal(1, @schema.types.length)
142
+ assert_instance_of(LibXML::XML::Schema::Type, @schema.types['shiporderType'])
143
+ end
144
+
145
+ def test_imported_types
146
+ assert_instance_of(Hash, @schema.imported_types)
147
+ assert_equal(2, @schema.imported_types.length)
148
+ assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_types['shiporderType'])
149
+ assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_types['shiporderFooType'])
150
+ end
151
+
152
+ def test_imported_ns_types
153
+ assert_instance_of(Hash, @schema.imported_ns_types)
154
+ assert_equal(2, @schema.imported_ns_types.length)
155
+ assert_equal(1, @schema.imported_ns_types[nil].length)
156
+ assert_equal(1, @schema.imported_ns_types[Import_NS].length)
157
+ assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_ns_types[nil]['shiporderType'])
158
+ assert_instance_of(LibXML::XML::Schema::Type, @schema.imported_ns_types[Import_NS]['shiporderFooType'])
159
+ end
160
+
161
+ def test_imported_ns_elements
162
+ assert_instance_of(Hash, @schema.imported_ns_elements)
163
+ assert_equal(2, @schema.imported_ns_elements.length)
164
+ assert_equal(1, @schema.imported_ns_elements[nil].length)
165
+ assert_equal(1, @schema.imported_ns_elements[Import_NS].length)
166
+ assert_instance_of(LibXML::XML::Schema::Element, @schema.imported_ns_elements[nil]['shiporder'])
167
+ assert_instance_of(LibXML::XML::Schema::Element, @schema.imported_ns_elements[Import_NS]['shiporder'])
168
+ assert_equal('shiporderType', @schema.imported_ns_elements[nil]['shiporder'].type.name)
169
+ assert_equal('shiporderFooType', @schema.imported_ns_elements[Import_NS]['shiporder'].type.name)
170
+ end
171
+
172
+ def test_namespaces
173
+ assert_instance_of(Array, @schema.namespaces)
174
+ ## For some reason, when importing another schema we end up with two xs->http://www.w3.org/2001/XMLSchema namespaces.
175
+ ## So, we expect 3 here (one for Import_NS and then two for the schema namespace.
176
+ assert_equal(3, @schema.namespaces.length)
177
+ end
178
+
179
+ def test_schema_type
180
+ type = @schema.types['shiporderType']
181
+
182
+ assert_equal('shiporderType', type.name)
183
+ assert_nil(type.namespace)
184
+ assert_equal("Shiporder type documentation", type.annotation)
185
+ assert_instance_of(LibXML::XML::Node, type.node)
186
+ assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind)
187
+ assert_instance_of(LibXML::XML::Schema::Type, type.base)
188
+ assert_equal("anyType", type.base.name)
189
+ assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind)
190
+
191
+ assert_instance_of(Hash, type.elements)
192
+ assert_equal(3, type.elements.length)
193
+ end
194
+
195
+ def test_schema_element
196
+ element = @schema.types['shiporderType'].elements['orderperson']
197
+
198
+ assert_equal('orderperson', element.name)
199
+ assert_nil(element.namespace)
200
+ assert_equal("orderperson element documentation", element.annotation)
201
+ assert_equal(false, element.array?)
202
+ assert_equal(true, element.required?)
203
+
204
+ element = @schema.types['shiporderType'].elements['item']
205
+ assert_equal('item', element.name)
206
+ assert_equal(true, element.array?)
207
+ assert_equal(true, element.required?)
208
+
209
+ element = @schema.types['shiporderType'].elements['item'].type.elements['note']
210
+ assert_equal('note', element.name)
211
+ assert_equal('string', element.type.name)
212
+ assert_equal(false, element.array?)
213
+ assert_equal(false, element.required?)
214
+ end
215
+
216
+ def test_schema_attributes
217
+ type = @schema.types['shiporderType']
218
+
219
+ assert_instance_of(Array, type.attributes)
220
+ assert_equal(2, type.attributes.length)
221
+ assert_instance_of(LibXML::XML::Schema::Attribute, type.attributes.first)
222
+ end
223
+
224
+ def test_schema_attribute
225
+ attribute = @schema.types['shiporderType'].attributes.first
226
+
227
+ assert_equal("orderid", attribute.name)
228
+ assert_nil(attribute.namespace)
229
+ assert_equal(1, attribute.occurs)
230
+ assert_equal('string', attribute.type.name)
231
+
232
+ attribute = @schema.types['shiporderType'].attributes[1]
233
+ assert_equal(2, attribute.occurs)
234
+ assert_equal('1', attribute.default)
235
+ assert_equal('integer', attribute.type.name)
236
+ end
237
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libxml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.2
5
5
  platform: x64-mingw-ucrt
6
6
  authors:
7
7
  - Ross Bamform
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2023-05-02 00:00:00.000000000 Z
17
+ date: 2023-11-04 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: rake-compiler
@@ -136,7 +136,6 @@ files:
136
136
  - ext/libxml/ruby_xml_xpath_object.h
137
137
  - ext/vc/libxml_ruby.sln
138
138
  - lib/3.1/libxml_ruby.so
139
- - lib/3.2/libxml_ruby.so
140
139
  - lib/libxml-ruby.rb
141
140
  - lib/libxml.rb
142
141
  - lib/libxml/attr.rb
@@ -275,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
274
  - !ruby/object:Gem::Version
276
275
  version: '0'
277
276
  requirements: []
278
- rubygems_version: 3.3.26
277
+ rubygems_version: 3.4.21
279
278
  signing_key:
280
279
  specification_version: 4
281
280
  summary: Ruby Bindings for LibXML2
Binary file