libxml-ruby 3.2.0 → 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,9 +5,9 @@
5
5
  #
6
6
  namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"
7
7
 
8
- start = shiporder
8
+ start = shiporderType
9
9
 
10
- shiporder = element shiporder { attribute orderid { text },
10
+ shiporderType = element shiporder { attribute orderid { text },
11
11
  attribute xsi:noNamespaceSchemaLocation { text },
12
12
  orderperson, shipto, item* }
13
13
 
@@ -7,9 +7,9 @@
7
7
  -->
8
8
  <grammar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://relaxng.org/ns/structure/1.0">
9
9
  <start>
10
- <ref name="shiporder"/>
10
+ <ref name="shiporderType"/>
11
11
  </start>
12
- <define name="shiporder">
12
+ <define name="shiporderType">
13
13
  <element name="shiporder">
14
14
  <attribute name="orderid"/>
15
15
  <attribute name="xsi:noNamespaceSchemaLocation"/>
@@ -1,8 +1,12 @@
1
1
  <?xml version="1.0" encoding="iso-8859-1" ?>
2
2
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
- <xs:element name="shiporder" type="shiporder"/>
4
3
 
5
- <xs:complexType name="shiporder">
4
+ <xs:import namespace="http://xml4r.org/ibxml-ruby/test/shiporder"
5
+ schemaLocation="shiporder_import.xsd"/>
6
+
7
+ <xs:element name="shiporder" type="shiporderType"/>
8
+
9
+ <xs:complexType name="shiporderType">
6
10
  <xs:annotation>
7
11
  <xs:documentation>Shiporder type documentation</xs:documentation>
8
12
  </xs:annotation>
@@ -37,4 +41,4 @@
37
41
  <xs:attribute name="foo" default="1" type="xs:integer" use="optional"/>
38
42
  <xs:attribute name="bar" use="prohibited"/>
39
43
  </xs:complexType>
40
- </xs:schema>
44
+ </xs:schema>
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="iso-8859-1" ?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
+ <xs:element name="shiporder" type="shiporderType"/>
4
+
5
+ <xs:complexType name="shiporderType">
6
+ <xs:anntation>
7
+ <xs:documentation>Shiporder type documentation</xs:documentation>
8
+ </xs:anntation>
9
+ <xs:sequence>
10
+ <xs:element name="orderperson" type="xs:string">
11
+ <xs:annotation>
12
+ <xs:documentation>orderperson element documentation</xs:documentation>
13
+ </xs:annotation>
14
+ </xs:element>
15
+ <xs:element name="shipto">
16
+ <xs:complexType>
17
+ <xs:sequence>
18
+ <xs:element name="name" type="xs:string"/>
19
+ <xs:element name="address" type="xs:string"/>
20
+ <xs:element name="city" type="xs:string"/>
21
+ <xs:element name="country" type="xs:string"/>
22
+ </xs:sequence>
23
+ </xs:complexType>
24
+ </xs:element>
25
+ <xs:element name="item" maxOccurs="unbounded">
26
+ <xs:complexType>
27
+ <xs:seq>
28
+ <xs:element name="title" type="xs:string"/>
29
+ <xs:element name="note" type="xs:string" minOccurs="0"/>
30
+ <xs:element name="quantity" type="xs:positiveInteger"/>
31
+ <xs:element name="price" type="xs:decimal"/>
32
+ </xs:seq>
33
+ </xs:complexType>
34
+ </xs:element>
35
+ </xs:sequence>
36
+ <xs:attribute name="orderid" type="xs:string" use="required"/>
37
+ <xs:attribute name="foo" default="1" type="xs:integer" use="optional"/>
38
+ <xs:attribute name="bar" use="prohibited"/>
39
+ </xs:complexType>
40
+ </xs:schema>
@@ -0,0 +1,45 @@
1
+ <?xml version="1.0" encoding="iso-8859-1" ?>
2
+ <xs:schema xmlns="http://xml4r.org/libxml-ruby/test/shiporder"
3
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
+ targetNamespace="http://xml4r.org/libxml-ruby/test/shiporder">
5
+
6
+ <xs:element name="shiporder" type="shiporderFooType"/>
7
+ <xs:complexType name="shiporderFooType">
8
+ <xs:annotation>
9
+ <xs:documentation>Shiporder type documentation for Testing of imported schema</xs:documentation>
10
+ </xs:annotation>
11
+ <xs:sequence>
12
+ <xs:element name="orderperson" type="xs:string">
13
+ <xs:annotation>
14
+ <xs:documentation>orderperson element documentation</xs:documentation>
15
+ </xs:annotation>
16
+ </xs:element>
17
+ <xs:element name="shipto">
18
+ <xs:complexType>
19
+ <xs:sequence>
20
+ <xs:element name="name" type="xs:string"/>
21
+ <xs:element name="address" type="xs:string"/>
22
+ <xs:element name="city" type="xs:string"/>
23
+ <xs:element name="country" type="xs:string"/>
24
+ <xs:element name="phone" type="xs:string"/>
25
+ </xs:sequence>
26
+ </xs:complexType>
27
+ </xs:element>
28
+ <xs:element name="item" maxOccurs="unbounded">
29
+ <xs:complexType>
30
+ <xs:sequence>
31
+ <xs:element name="title" type="xs:string"/>
32
+ <xs:element name="note" type="xs:string" minOccurs="0"/>
33
+ <xs:element name="quantity" type="xs:positiveInteger"/>
34
+ <xs:element name="price" type="xs:decimal"/>
35
+ <xs:element name="discount" type="xs:decimal"/>
36
+ </xs:sequence>
37
+ </xs:complexType>
38
+ </xs:element>
39
+ </xs:sequence>
40
+ <xs:attribute name="orderid" type="xs:string" use="required"/>
41
+ <xs:attribute name="foo" default="1" type="xs:integer" use="optional"/>
42
+ <xs:attribute name="bar" type="xs:string" use="optional"/>
43
+ <xs:attribute name="xyzzy" type="xs:string" use="prohibited"/>
44
+ </xs:complexType>
45
+ </xs:schema>
@@ -13,119 +13,120 @@ class TestDocument < Minitest::Test
13
13
  @doc = nil
14
14
  end
15
15
 
16
- # def test_klass
17
- # assert_instance_of(LibXML::XML::Document, @doc)
18
- # end
19
- #
20
- # def test_context
21
- # context = @doc.context
22
- # assert_instance_of(LibXML::XML::XPath::Context, context)
23
- # end
24
- #
25
- # def test_find
26
- # set = @doc.find('/ruby_array/fixnum')
27
- # assert_instance_of(LibXML::XML::XPath::Object, set)
28
- # assert_raises(NoMethodError) {
29
- # set.xpath
30
- # }
31
- # end
32
- #
33
- # def test_compression
34
- # if LibXML::XML.enabled_zlib?
35
- # 0.upto(9) do |i|
36
- # assert_equal(i, @doc.compression = i)
37
- # assert_equal(i, @doc.compression)
38
- # end
39
- #
40
- # 9.downto(0) do |i|
41
- # assert_equal(i, @doc.compression = i)
42
- # assert_equal(i, @doc.compression)
43
- # end
44
- #
45
- # 10.upto(20) do |i|
46
- # # assert_equal(9, @doc.compression = i)
47
- # assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
48
- # assert_equal(9, @doc.compression)
49
- # end
50
- #
51
- # -1.downto(-10) do |i|
52
- # # assert_equal(0, @doc.compression = i)
53
- # assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
54
- # assert_equal(0, @doc.compression)
55
- # end
56
- # end
57
- # end
58
- #
59
- # def test_version
60
- # assert_equal('1.0', @doc.version)
61
- #
62
- # doc = LibXML::XML::Document.new('6.9')
63
- # assert_equal('6.9', doc.version)
64
- # end
65
- #
66
- # def test_write_root
67
- # @doc.root = LibXML::XML::Node.new('rubynet')
68
- # assert_instance_of(LibXML::XML::Node, @doc.root)
69
- # assert_instance_of(LibXML::XML::Document, @doc.root.doc)
70
- # assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
71
- # @doc.to_s(:indent => false))
72
- # end
73
- #
74
- # def test_doc_node_type
75
- # assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
76
- # end
77
- #
78
- # def test_doc_node_type_name
79
- # assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
80
- # end
81
- #
82
- # def test_xhtml
83
- # doc = LibXML::XML::Document.new
84
- # assert(!doc.xhtml?)
85
- # LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
86
- # assert(doc.xhtml?)
87
- # end
88
- #
89
- # def test_document_root
90
- # doc1 = LibXML::XML::Document.string("<one/>")
91
- # doc2 = LibXML::XML::Document.string("<two/>")
92
- #
93
- # error = assert_raises(LibXML::XML::Error) do
94
- # doc1.root = doc2.root
95
- # end
96
- # assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
97
- # error.to_s)
98
- #
99
- # doc2.root << doc2.import(doc1.root)
100
- # assert_equal('<one/>', doc1.root.to_s)
101
- # assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
102
- #
103
- # assert(!doc1.root.equal?(doc2.root))
104
- # assert(doc1.root.doc != doc2.root.doc)
105
- # end
106
- #
107
- # def test_import_node
108
- # doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
109
- # doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
110
- #
111
- # node = doc1.root.child
112
- #
113
- # error = assert_raises(LibXML::XML::Error) do
114
- # doc2.root << node
115
- # end
116
- #
117
- # assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
118
- # error.to_s)
119
- #
120
- # doc2.root << doc2.import(node)
121
- #
122
- # assert_equal("<nums><two/><one/></nums>",
123
- # doc2.root.to_s(:indent => false))
124
- # end
16
+ def test_klass
17
+ assert_instance_of(LibXML::XML::Document, @doc)
18
+ end
19
+
20
+ def test_context
21
+ context = @doc.context
22
+ assert_instance_of(LibXML::XML::XPath::Context, context)
23
+ end
24
+
25
+ def test_find
26
+ set = @doc.find('/ruby_array/fixnum')
27
+ assert_instance_of(LibXML::XML::XPath::Object, set)
28
+ assert_raises(NoMethodError) {
29
+ set.xpath
30
+ }
31
+ end
32
+
33
+ def test_compression
34
+ if LibXML::XML.enabled_zlib?
35
+ 0.upto(9) do |i|
36
+ assert_equal(i, @doc.compression = i)
37
+ assert_equal(i, @doc.compression)
38
+ end
39
+
40
+ 9.downto(0) do |i|
41
+ assert_equal(i, @doc.compression = i)
42
+ assert_equal(i, @doc.compression)
43
+ end
44
+
45
+ 10.upto(20) do |i|
46
+ # assert_equal(9, @doc.compression = i)
47
+ assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
48
+ assert_equal(9, @doc.compression)
49
+ end
50
+
51
+ -1.downto(-10) do |i|
52
+ # assert_equal(0, @doc.compression = i)
53
+ assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
54
+ assert_equal(0, @doc.compression)
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_version
60
+ assert_equal('1.0', @doc.version)
61
+
62
+ doc = LibXML::XML::Document.new('6.9')
63
+ assert_equal('6.9', doc.version)
64
+ end
65
+
66
+ def test_write_root
67
+ @doc.root = LibXML::XML::Node.new('rubynet')
68
+ assert_instance_of(LibXML::XML::Node, @doc.root)
69
+ assert_instance_of(LibXML::XML::Document, @doc.root.doc)
70
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
71
+ @doc.to_s(:indent => false))
72
+ end
73
+
74
+ def test_doc_node_type
75
+ assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
76
+ end
77
+
78
+ def test_doc_node_type_name
79
+ assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
80
+ end
81
+
82
+ def test_xhtml
83
+ doc = LibXML::XML::Document.new
84
+ assert(!doc.xhtml?)
85
+ LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
86
+ assert(doc.xhtml?)
87
+ end
88
+
89
+ def test_document_root
90
+ doc1 = LibXML::XML::Document.string("<one/>")
91
+ doc2 = LibXML::XML::Document.string("<two/>")
92
+
93
+ error = assert_raises(LibXML::XML::Error) do
94
+ doc1.root = doc2.root
95
+ end
96
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
97
+ error.to_s)
98
+
99
+ doc2.root << doc2.import(doc1.root)
100
+ assert_equal('<one/>', doc1.root.to_s)
101
+ assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
102
+
103
+ assert(!doc1.root.equal?(doc2.root))
104
+ assert(doc1.root.doc != doc2.root.doc)
105
+ end
106
+
107
+ def test_import_node
108
+ doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
109
+ doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
110
+
111
+ node = doc1.root.child
112
+
113
+ error = assert_raises(LibXML::XML::Error) do
114
+ doc2.root << node
115
+ end
116
+
117
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
118
+ error.to_s)
119
+
120
+ doc2.root << doc2.import(node)
121
+
122
+ assert_equal("<nums><two/><one/></nums>",
123
+ doc2.root.to_s(:indent => false))
124
+ end
125
125
 
126
126
  def test_nonet
127
127
  xml_string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
128
128
  xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
129
- schema_document = LibXML::XML::Document.file('d:/src/libxml-ruby/test/model/atom.xml', options: LibXML::XML::Parser::Options::NONET)
129
+ file = File.join(File.dirname(__FILE__), 'model/atom.xml')
130
+ schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET)
130
131
  end
131
132
  end
data/test/test_dtd.rb CHANGED
@@ -84,7 +84,8 @@ class TestDtd < Minitest::Test
84
84
  assert_nil(error.file)
85
85
  assert_nil(error.line)
86
86
  assert_equal('invalid', error.str1)
87
- assert_nil(error.str2)
87
+ # Different answers across operating systems
88
+ # assert_nil(error.str2)
88
89
  assert_nil(error.str3)
89
90
  assert_equal(0, error.int1)
90
91
  assert_equal(0, error.int2)
data/test/test_helper.rb CHANGED
@@ -5,3 +5,5 @@
5
5
  require 'bundler/setup'
6
6
  require 'minitest/autorun'
7
7
  require 'libxml-ruby'
8
+
9
+ STDOUT.write "\nlibxml2: #{LibXML::XML::LIBXML_VERSION}\n#{RUBY_DESCRIPTION}\n\n"
data/test/test_parser.rb CHANGED
@@ -271,7 +271,7 @@ class TestParser < Minitest::Test
271
271
  assert_equal('foz', error.str2)
272
272
  assert_nil(error.str3)
273
273
  assert_equal(1, error.int1)
274
- assert_equal(20, error.int2)
274
+ assert([18, 20].include?(error.int2))
275
275
  assert_nil(error.node)
276
276
  end
277
277
 
@@ -127,18 +127,12 @@ class TestParserContext < Minitest::Test
127
127
  end
128
128
  end
129
129
 
130
- if ENV['NOTWORKING']
131
- def test_num_chars
132
- assert_equal(17, context.num_chars)
133
- end
134
- end
135
-
136
130
  def test_replace_entities
137
131
  context = LibXML::XML::Parser::Context.new
138
132
  assert(!context.replace_entities?)
139
133
 
140
- # context.options = 1
141
- # assert(context.replace_entities?)
134
+ context.options = LibXML::XML::Parser::Options::NOENT
135
+ assert(context.replace_entities?)
142
136
 
143
137
  context.options = 0
144
138
  assert(!context.replace_entities?)
@@ -185,7 +179,7 @@ class TestParserContext < Minitest::Test
185
179
  assert_nil(context.name_node)
186
180
  assert_equal(0, context.name_depth)
187
181
  assert_equal(10, context.name_depth_max)
188
- assert_equal(17, context.num_chars)
182
+ assert([0, 17].include?(context.num_chars))
189
183
  assert_equal(false, context.replace_entities?)
190
184
  assert_equal(1, context.space_depth)
191
185
  assert_equal(10, context.space_depth_max)
data/test/test_reader.rb CHANGED
@@ -249,9 +249,10 @@ class TestReader < Minitest::Test
249
249
  end
250
250
 
251
251
  def test_bytes_consumed
252
+ ending_are_rn = File.binread(XML_FILE).include? "\r\n"
252
253
  reader = LibXML::XML::Reader.file(XML_FILE)
253
254
  reader.read
254
- assert_equal(428, reader.byte_consumed)
255
+ assert_equal(ending_are_rn ? 428 : 416, reader.byte_consumed)
255
256
  end
256
257
 
257
258
  def test_node
@@ -181,7 +181,7 @@ class TestSaxParser < Minitest::Test
181
181
  xml = File.read(saxtest_file)
182
182
  io = StringIO.new(xml)
183
183
  parser = LibXML::XML::SaxParser.io(io)
184
-
184
+
185
185
  parser.callbacks = TestCaseCallbacks.new
186
186
  parser.parse
187
187
  verify(parser)
@@ -250,25 +250,32 @@ EOS
250
250
  result = parser.callbacks.result
251
251
 
252
252
  i = -1
253
+
254
+ base_err_msg = "Fatal error: (Premature end of data in tag Results line 1|EndTag: '<\\/' not found) at :2\\."
255
+ re_err_msg1 = /\A(error: )#{base_err_msg}\z/
256
+ re_err_msg2 = /\A#{base_err_msg}\z/
257
+
253
258
  assert_equal("startdoc", result[i+=1])
254
259
  assert_equal("start_element: Results, attr: {}", result[i+=1])
255
260
  assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
256
261
  assert_equal("characters: \n", result[i+=1])
257
- assert_equal("error: Fatal error: EndTag: '</' not found at :2.", result[i+=1])
262
+ assert_match(re_err_msg1, result[i+=1])
258
263
  assert_equal("end_document", result[i+=1])
259
264
 
260
265
  refute_nil(error)
261
266
  assert_kind_of(LibXML::XML::Error, error)
262
- assert_equal("Fatal error: EndTag: '</' not found at :2.", error.message)
267
+ assert_match(re_err_msg2, error.message)
263
268
  assert_equal(LibXML::XML::Error::PARSER, error.domain)
264
- assert_equal(LibXML::XML::Error::LTSLASH_REQUIRED, error.code)
269
+
270
+ assert([LibXML::XML::Error::TAG_NOT_FINISHED, LibXML::XML::Error::LTSLASH_REQUIRED].include?(error.code))
265
271
  assert_equal(LibXML::XML::Error::FATAL, error.level)
266
272
  assert_nil(error.file)
267
273
  assert_equal(2, error.line)
268
- assert_nil(error.str1)
274
+ # Sometimes this is nil and sometimes its not depending on OS and libxlm version
275
+ # assert_nil(error.str1)
269
276
  assert_nil(error.str2)
270
277
  assert_nil(error.str3)
271
- assert_equal(0, error.int1)
278
+ assert([0, 1].include?(error.int1))
272
279
  assert_equal(1, error.int2)
273
280
  assert_nil(error.node)
274
281
  end