libxml-ruby 3.2.1 → 4.1.1

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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +37 -0
  3. data/Rakefile +24 -16
  4. data/ext/libxml/libxml.c +0 -1
  5. data/ext/libxml/libxml_ruby.def +0 -1
  6. data/ext/libxml/ruby_libxml.h +0 -23
  7. data/ext/libxml/ruby_xml.c +3 -37
  8. data/ext/libxml/ruby_xml.h +1 -1
  9. data/ext/libxml/ruby_xml_cbg.c +1 -1
  10. data/ext/libxml/ruby_xml_document.c +6 -0
  11. data/ext/libxml/ruby_xml_dtd.c +1 -1
  12. data/ext/libxml/ruby_xml_encoding.c +2 -2
  13. data/ext/libxml/ruby_xml_encoding.h +2 -0
  14. data/ext/libxml/ruby_xml_error.c +3 -3
  15. data/ext/libxml/ruby_xml_error.h +3 -1
  16. data/ext/libxml/ruby_xml_html_parser.c +2 -0
  17. data/ext/libxml/ruby_xml_html_parser_context.c +1 -1
  18. data/ext/libxml/ruby_xml_html_parser_options.c +2 -0
  19. data/ext/libxml/ruby_xml_input_cbg.c +4 -7
  20. data/ext/libxml/ruby_xml_io.c +1 -1
  21. data/ext/libxml/ruby_xml_namespace.c +1 -0
  22. data/ext/libxml/ruby_xml_node.c +11 -15
  23. data/ext/libxml/ruby_xml_parser.h +0 -2
  24. data/ext/libxml/ruby_xml_parser_context.c +2 -0
  25. data/ext/libxml/ruby_xml_parser_options.h +0 -2
  26. data/ext/libxml/ruby_xml_reader.c +3 -0
  27. data/ext/libxml/ruby_xml_reader.h +0 -3
  28. data/ext/libxml/ruby_xml_relaxng.c +2 -0
  29. data/ext/libxml/ruby_xml_relaxng.h +0 -2
  30. data/ext/libxml/ruby_xml_schema.c +223 -81
  31. data/ext/libxml/ruby_xml_schema.h +4 -788
  32. data/ext/libxml/ruby_xml_schema_attribute.c +69 -71
  33. data/ext/libxml/ruby_xml_schema_attribute.h +25 -3
  34. data/ext/libxml/ruby_xml_schema_element.c +28 -54
  35. data/ext/libxml/ruby_xml_schema_element.h +0 -3
  36. data/ext/libxml/ruby_xml_schema_facet.c +19 -21
  37. data/ext/libxml/ruby_xml_schema_facet.h +0 -4
  38. data/ext/libxml/ruby_xml_schema_type.c +56 -37
  39. data/ext/libxml/ruby_xml_version.h +4 -4
  40. data/ext/libxml/ruby_xml_writer.c +4 -0
  41. data/ext/libxml/ruby_xml_writer.h +0 -4
  42. data/ext/libxml/ruby_xml_xinclude.c +4 -0
  43. data/ext/libxml/ruby_xml_xpath.c +1 -0
  44. data/ext/libxml/ruby_xml_xpath.h +2 -0
  45. data/ext/libxml/ruby_xml_xpath_context.c +2 -0
  46. data/ext/libxml/ruby_xml_xpath_object.c +1 -0
  47. data/lib/libxml/error.rb +7 -7
  48. data/libxml-ruby.gemspec +1 -1
  49. data/test/model/shiporder.rnc +2 -2
  50. data/test/model/shiporder.rng +2 -2
  51. data/test/model/shiporder.xsd +7 -3
  52. data/test/model/shiporder_bad.xsd +40 -0
  53. data/test/model/shiporder_import.xsd +45 -0
  54. data/test/test_document.rb +2 -1
  55. data/test/test_dtd.rb +2 -1
  56. data/test/test_error.rb +173 -157
  57. data/test/test_helper.rb +6 -0
  58. data/test/test_parser.rb +1 -1
  59. data/test/test_parser_context.rb +1 -7
  60. data/test/test_reader.rb +2 -1
  61. data/test/test_sax_parser.rb +13 -6
  62. data/test/test_schema.rb +92 -29
  63. data/test/test_xml.rb +12 -7
  64. metadata +11 -18
  65. data/MANIFEST +0 -166
  66. data/ext/libxml/ruby_xml_xpointer.c +0 -99
  67. data/ext/libxml/ruby_xml_xpointer.h +0 -11
  68. data/setup.rb +0 -1584
  69. data/test/test.xml +0 -2
  70. data/test/test_suite.rb +0 -48
  71. data/test/test_xpointer.rb +0 -72
data/lib/libxml/error.rb CHANGED
@@ -3,24 +3,24 @@
3
3
  module LibXML
4
4
  module XML
5
5
  class Error
6
- # Create mapping from domain constant value to keys
6
+ # Create mapping from domain constant values to keys
7
7
  DOMAIN_CODE_MAP = [:NO_ERROR, :PARSER, :TREE, :NAMESPACE, :DTD, :HTML, :MEMORY,
8
8
  :OUTPUT, :IO, :FTP, :HTTP, :XINCLUDE, :XPATH, :XPOINTER, :REGEXP,
9
9
  :DATATYPE, :SCHEMASP, :SCHEMASV, :RELAXNGP, :RELAXNGV, :CATALOG,
10
10
  :C14N, :XSLT, :VALID, :CHECK, :WRITER, :MODULE, :I18N, :SCHEMATRONV].inject(Hash.new) do |hash, code|
11
11
  if const_defined?(code)
12
- hash[const_get(code)] = code.to_s
12
+ hash[const_get(code)] = code
13
13
  end
14
14
  hash
15
15
  end
16
16
 
17
- # Create mapping from domain constant value to keys
17
+ # Create mapping from error constant values (so need to remove domain_codes) to keys
18
18
  ERROR_CODE_MAP = Hash.new.tap do |map|
19
19
  (constants -
20
20
  DOMAIN_CODE_MAP.values - #Domains
21
21
  [:NONE, :WARNING, :ERROR, :FATAL] # Levels
22
22
  ).each do |code|
23
- map[const_get(code)] = code.to_s
23
+ map[const_get(code)] = code
24
24
  end
25
25
  end
26
26
 
@@ -70,11 +70,11 @@ module LibXML
70
70
  end
71
71
 
72
72
  def domain_to_s
73
- DOMAIN_CODE_MAP[self.domain]
73
+ DOMAIN_CODE_MAP[self.domain].to_s
74
74
  end
75
75
 
76
76
  def code_to_s
77
- ERROR_CODE_MAP[self.code]
77
+ ERROR_CODE_MAP[self.code].to_s
78
78
  end
79
79
 
80
80
  def to_s
@@ -92,4 +92,4 @@ module LibXML
92
92
  end
93
93
  end
94
94
 
95
- LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
95
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
data/libxml-ruby.gemspec CHANGED
@@ -7,7 +7,7 @@ version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSI
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'libxml-ruby'
9
9
  spec.version = version
10
- spec.homepage = 'http://xml4r.github.com/libxml-ruby'
10
+ spec.homepage = 'https://xml4r.github.io/libxml-ruby/'
11
11
  spec.summary = 'Ruby Bindings for LibXML2'
12
12
  spec.description = <<-EOS
13
13
  The Libxml-Ruby project provides Ruby language bindings for the GNOME
@@ -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>
@@ -126,6 +126,7 @@ class TestDocument < Minitest::Test
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_error.rb CHANGED
@@ -4,135 +4,153 @@ require_relative './test_helper'
4
4
  require 'stringio'
5
5
 
6
6
  class TestError < Minitest::Test
7
- # def test_error_codes
8
- # assert_equal(4, LibXML::XML::Error::DTD)
9
- # assert_equal(4, LibXML::XML::Error.const_get('DTD'))
10
- #
11
- # assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY)
12
- # assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY'))
13
- # end
14
- #
15
- # def test_invalid_handler
16
- # assert_raises(RuntimeError) do
17
- # LibXML::XML::Error.set_handler
18
- # end
19
- # end
20
- #
21
- # def test_handler
22
- # exception = nil
23
- # LibXML::XML::Error.set_handler do |error|
24
- # exception = error
25
- # end
26
- #
27
- # # Raise the error
28
- # error = assert_raises(LibXML::XML::Error) do
29
- # LibXML::XML::Reader.string('<foo').read
30
- # end
31
- # assert_equal(exception, error)
32
- #
33
- # # Check the handler worked
34
- # refute_nil(exception)
35
- # assert_kind_of(LibXML::XML::Error, exception)
36
- # assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
37
- # assert_equal(LibXML::XML::Error::PARSER, exception.domain)
38
- # assert_equal(LibXML::XML::Error::GT_REQUIRED, exception.code)
39
- # assert_equal(LibXML::XML::Error::FATAL, exception.level)
40
- # assert_nil(exception.file)
41
- # assert_equal(1, exception.line)
42
- # assert_equal('foo', exception.str1)
43
- # assert_nil(exception.str2)
44
- # assert_nil(exception.str3)
45
- # assert_equal(0, exception.int1)
46
- # assert_equal(5, exception.int2)
47
- # assert_nil(exception.node)
48
- # end
49
- #
50
- # def test_reset_handler
51
- # exception = nil
52
- # LibXML::XML::Error.set_handler do |error|
53
- # exception = error
54
- # end
55
- #
56
- # LibXML::XML::Error.reset_handler
57
- # LibXML::XML::Reader.string('<foo')
58
- # assert_nil(exception)
59
- # end
60
- #
61
- # def test_get_handler
62
- # assert_respond_to(LibXML::XML::Error, :get_handler)
63
- # assert_equal(0, LibXML::XML::Error.method(:get_handler).arity)
64
- #
65
- # saved_handler = LibXML::XML::Error.get_handler
66
- # LibXML::XML::Error.set_handler{ puts "New handler" }
67
- # refute_equal(LibXML::XML::Error.get_handler, saved_handler)
68
- #
69
- # LibXML::XML::Error.set_handler(&saved_handler)
70
- # assert_equal(LibXML::XML::Error.get_handler, saved_handler)
71
- # end
72
- #
73
- # def test_verbose_handler
74
- # LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
75
- # output = StringIO.new
76
- # original_stderr = Object::STDERR
77
- #
78
- # Object.const_set(:STDERR, output)
79
- # begin
80
- # assert_raises(LibXML::XML::Error) do
81
- # LibXML::XML::Parser.string('<foo><bar/></foz>').parse
82
- # end
83
- # ensure
84
- # Object.const_set(:STDERR, original_stderr)
85
- # end
86
- # assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string)
87
- # end
88
- #
89
- # def test_no_hanlder
90
- # LibXML::XML::Error.reset_handler
91
- # output = StringIO.new
92
- # original_stderr = Object::STDERR
93
- #
94
- # Object.const_set(:STDERR, output)
95
- # begin
96
- # assert_raises(LibXML::XML::Error) do
97
- # LibXML::XML::Parser.string('<foo><bar/></foz>').parse
98
- # end
99
- # ensure
100
- # Object.const_set(:STDERR, original_stderr)
101
- # end
102
- # assert_equal('', output.string)
103
- # end
104
- #
105
- # def test_parse_error
106
- # exception = assert_raises(LibXML::XML::Error) do
107
- # LibXML::XML::Parser.string('<foo><bar/></foz>').parse
108
- # end
109
- #
110
- # assert_instance_of(LibXML::XML::Error, exception)
111
- # assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
112
- # assert_equal(LibXML::XML::Error::PARSER, exception.domain)
113
- # assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, exception.code)
114
- # assert_equal(LibXML::XML::Error::FATAL, exception.level)
115
- # assert_nil(exception.file)
116
- # assert_equal(1, exception.line)
117
- # end
118
- #
119
- # def test_xpath_error
120
- # doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
121
- #
122
- # exception = assert_raises(LibXML::XML::Error) do
123
- # doc.find('/foo[bar=test')
124
- # end
125
- #
126
- # assert_instance_of(LibXML::XML::Error, exception)
127
- # assert_equal("Error: Invalid predicate.", exception.message)
128
- # assert_equal(LibXML::XML::Error::XPATH, exception.domain)
129
- # assert_equal(LibXML::XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code)
130
- # assert_equal(LibXML::XML::Error::ERROR, exception.level)
131
- # assert_nil(exception.file)
132
- # assert_nil(nil)
133
- # end
7
+ def test_error_codes
8
+ assert_equal(4, LibXML::XML::Error::DTD)
9
+ assert_equal(4, LibXML::XML::Error.const_get('DTD'))
10
+
11
+ assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY)
12
+ assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY'))
13
+ end
14
+
15
+ def test_invalid_handler
16
+ assert_raises(RuntimeError) do
17
+ LibXML::XML::Error.set_handler
18
+ end
19
+ end
20
+
21
+ def test_handler
22
+ exception = nil
23
+ LibXML::XML::Error.set_handler do |error|
24
+ exception = error
25
+ end
26
+
27
+ # Raise the error
28
+ error = assert_raises(LibXML::XML::Error) do
29
+ LibXML::XML::Reader.string('<foo').read
30
+ end
31
+ assert_equal(exception, error)
32
+
33
+ # Check the handler worked
34
+ refute_nil(exception)
35
+ assert_kind_of(LibXML::XML::Error, exception)
36
+ assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
37
+ assert_equal(LibXML::XML::Error::PARSER, exception.domain)
38
+ assert_equal(LibXML::XML::Error::GT_REQUIRED, exception.code)
39
+ assert_equal(LibXML::XML::Error::FATAL, exception.level)
40
+ assert_nil(exception.file)
41
+ assert_equal(1, exception.line)
42
+ assert_equal('foo', exception.str1)
43
+ assert_nil(exception.str2)
44
+ assert_nil(exception.str3)
45
+ assert_equal(0, exception.int1)
46
+ assert_equal(5, exception.int2)
47
+ assert_nil(exception.node)
48
+ end
49
+
50
+ def test_reset_handler
51
+ exception = nil
52
+ LibXML::XML::Error.set_handler do |error|
53
+ exception = error
54
+ end
55
+
56
+ LibXML::XML::Error.reset_handler
57
+ LibXML::XML::Reader.string('<foo')
58
+ assert_nil(exception)
59
+ end
60
+
61
+ def test_get_handler
62
+ assert_respond_to(LibXML::XML::Error, :get_handler)
63
+ assert_equal(0, LibXML::XML::Error.method(:get_handler).arity)
64
+
65
+ saved_handler = LibXML::XML::Error.get_handler
66
+ LibXML::XML::Error.set_handler { puts "New handler" }
67
+ refute_equal(LibXML::XML::Error.get_handler, saved_handler)
68
+
69
+ if saved_handler
70
+ LibXML::XML::Error.set_handler &saved_handler
71
+ else
72
+ LibXML::XML::Error.reset_handler
73
+ end
74
+
75
+ assert_equal(LibXML::XML::Error.get_handler, saved_handler)
76
+ end
77
+
78
+ def test_verbose_handler
79
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
80
+ output = StringIO.new
81
+ original_stderr = Object::STDERR
82
+
83
+ Object.const_set(:STDERR, output)
84
+ begin
85
+ assert_raises(LibXML::XML::Error) do
86
+ LibXML::XML::Parser.string('<foo><bar/></foz>').parse
87
+ end
88
+ ensure
89
+ Object.const_set(:STDERR, original_stderr)
90
+ end
91
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string)
92
+ end
93
+
94
+ def test_no_handler
95
+ LibXML::XML::Error.reset_handler
96
+ output = StringIO.new
97
+ original_stderr = Object::STDERR
98
+
99
+ Object.const_set(:STDERR, output)
100
+ begin
101
+ assert_raises(LibXML::XML::Error) do
102
+ LibXML::XML::Parser.string('<foo><bar/></foz>').parse
103
+ end
104
+ ensure
105
+ Object.const_set(:STDERR, original_stderr)
106
+ end
107
+ assert_equal('', output.string)
108
+ end
109
+
110
+ def test_parse_error
111
+ exception = assert_raises(LibXML::XML::Error) do
112
+ LibXML::XML::Parser.string('<foo><bar/></foz>').parse
113
+ end
114
+
115
+ assert_instance_of(LibXML::XML::Error, exception)
116
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
117
+ assert_equal(LibXML::XML::Error::PARSER, exception.domain)
118
+ assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, exception.code)
119
+ assert_equal(LibXML::XML::Error::FATAL, exception.level)
120
+ assert_nil(exception.file)
121
+ assert_equal(1, exception.line)
122
+ end
123
+
124
+ def test_xpath_error
125
+ doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
126
+
127
+ exception = assert_raises(LibXML::XML::Error) do
128
+ doc.find('/foo[bar=test')
129
+ end
130
+
131
+ assert_instance_of(LibXML::XML::Error, exception)
132
+ assert_equal("Error: Invalid predicate.", exception.message)
133
+ assert_equal(LibXML::XML::Error::XPATH, exception.domain)
134
+ assert_equal(LibXML::XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code)
135
+ assert_equal(LibXML::XML::Error::ERROR, exception.level)
136
+ assert_nil(exception.file)
137
+ assert_nil(nil)
138
+ end
134
139
 
135
140
  def test_double_parse
141
+ LibXML::XML::Error.set_handler {|msg| nil }
142
+ parser = LibXML::XML::Parser.string("<test>something</test>")
143
+ parser.parse
144
+
145
+ error = assert_raises(LibXML::XML::Error) do
146
+ # Try parsing a second time
147
+ parser.parse
148
+ end
149
+
150
+ assert_equal(" LibXML::XML::Error.", error.to_s)
151
+ end
152
+
153
+ def test_double_parse_register_handler
136
154
  LibXML::XML::Parser.register_error_handler(lambda {|msg| nil })
137
155
  parser = LibXML::XML::Parser.string("<test>something</test>")
138
156
  parser.parse
@@ -145,34 +163,32 @@ class TestError < Minitest::Test
145
163
  assert_equal(" LibXML::XML::Error.", error.to_s)
146
164
  end
147
165
 
148
- # def test_libxml_parser_empty_string
149
- # xp = LibXML::XML::Parser.new
150
- #
151
- # error = assert_raises(TypeError) do
152
- # xp.string = nil
153
- # end
154
- # assert_equal('wrong argument type nil (expected String)', error.to_s)
155
- #
156
- # error = assert_raises(ArgumentError) do
157
- # xp.string = ''
158
- # end
159
- # assert_equal('Must specify a string with one or more characters', error.to_s)
160
- # end
161
- #
162
- # def test_error_domain_to_s
163
- # exception = assert_raises(LibXML::XML::Error) do
164
- # LibXML::XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
165
- # end
166
- #
167
- # assert_equal(LibXML::XML::Error::PARSER, exception.domain)
168
- # assert_equal("PARSER",exception.domain_to_s)
169
- # end
170
- #
171
- # def test_error_code_to_s
172
- # exception = assert_raises(LibXML::XML::Error) do
173
- # LibXML::XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
174
- # end
175
- # assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
176
- # assert_equal("ENTITYREF_SEMICOL_MISSING",exception.code_to_s)
177
- # end
166
+ def test_libxml_parser_empty_string
167
+ error = assert_raises(TypeError) do
168
+ LibXML::XML::Parser.string(nil)
169
+ end
170
+ assert_equal('wrong argument type nil (expected String)', error.to_s)
171
+
172
+ error = assert_raises(ArgumentError) do
173
+ LibXML::XML::Parser.string("")
174
+ end
175
+ assert_equal('Must specify a string with one or more characters', error.to_s)
176
+ end
177
+
178
+ def test_error_domain_to_s
179
+ exception = assert_raises(LibXML::XML::Error) do
180
+ LibXML::XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
181
+ end
182
+
183
+ assert_equal(LibXML::XML::Error::PARSER, exception.domain)
184
+ assert_equal("PARSER", exception.domain_to_s)
185
+ end
186
+
187
+ def test_error_code_to_s
188
+ exception = assert_raises(LibXML::XML::Error) do
189
+ LibXML::XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
190
+ end
191
+ assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
192
+ assert_equal("ENTITYREF_SEMICOL_MISSING", exception.code_to_s)
193
+ end
178
194
  end
data/test/test_helper.rb CHANGED
@@ -5,3 +5,9 @@
5
5
  require 'bundler/setup'
6
6
  require 'minitest/autorun'
7
7
  require 'libxml-ruby'
8
+
9
+ def windows?
10
+ !(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/).nil?
11
+ end
12
+
13
+ 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,12 +127,6 @@ 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?)
@@ -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