libxml-ruby 4.0.0-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.
- checksums.yaml +4 -4
- data/HISTORY +18 -0
- data/ext/libxml/extconf.rb +67 -61
- data/ext/libxml/ruby_xml.c +0 -40
- data/ext/libxml/ruby_xml_attr_decl.c +154 -153
- data/ext/libxml/ruby_xml_attributes.c +276 -275
- data/ext/libxml/ruby_xml_encoding.c +1 -1
- data/ext/libxml/ruby_xml_error.c +2 -2
- data/ext/libxml/ruby_xml_html_parser_context.c +0 -1
- data/ext/libxml/ruby_xml_input_cbg.c +4 -7
- data/ext/libxml/ruby_xml_parser.h +0 -2
- data/ext/libxml/ruby_xml_parser_options.h +0 -2
- data/ext/libxml/ruby_xml_reader.c +1245 -1242
- data/ext/libxml/ruby_xml_relaxng.c +113 -112
- data/ext/libxml/ruby_xml_schema.c +422 -420
- data/ext/libxml/ruby_xml_schema_attribute.c +108 -107
- data/ext/libxml/ruby_xml_schema_element.c +70 -69
- data/ext/libxml/ruby_xml_schema_type.c +252 -251
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +1138 -1137
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -81
- data/ext/libxml/ruby_xml_xpath_object.c +340 -339
- data/lib/3.1/libxml_ruby.so +0 -0
- data/lib/libxml/error.rb +7 -7
- data/lib/libxml/schema/element.rb +27 -19
- data/test/test_error.rb +173 -157
- data/test/test_schema.rb +237 -231
- data/test/test_xml.rb +0 -8
- metadata +3 -4
- data/lib/3.2/libxml_ruby.so +0 -0
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
|
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
|
12
|
+
hash[const_get(code)] = code
|
13
13
|
end
|
14
14
|
hash
|
15
15
|
end
|
16
16
|
|
17
|
-
# Create mapping from
|
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
|
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)
|
@@ -1,19 +1,27 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module LibXML
|
4
|
-
module XML
|
5
|
-
class Schema::Element
|
6
|
-
def
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
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_error.rb
CHANGED
@@ -4,135 +4,153 @@ require_relative './test_helper'
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
class TestError < Minitest::Test
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|