libxml-ruby 0.9.7-x86-mswin32-60 → 0.9.8-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +53 -0
- data/Rakefile +1 -0
- data/ext/libxml/build.log +4 -0
- data/ext/libxml/cbg.c +86 -86
- data/ext/libxml/libxml.c +878 -876
- data/ext/libxml/ruby_libxml.h +8 -4
- data/ext/libxml/ruby_xml_attr.c +36 -168
- data/ext/libxml/ruby_xml_attr.h +2 -4
- data/ext/libxml/ruby_xml_attr_decl.c +177 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +29 -20
- data/ext/libxml/ruby_xml_document.c +895 -898
- data/ext/libxml/ruby_xml_dtd.c +18 -1
- data/ext/libxml/ruby_xml_dtd.h +1 -0
- data/ext/libxml/ruby_xml_encoding.c +116 -0
- data/ext/libxml/ruby_xml_encoding.h +12 -0
- data/ext/libxml/ruby_xml_error.c +8 -2
- data/ext/libxml/ruby_xml_html_parser.c +53 -74
- data/ext/libxml/ruby_xml_html_parser.h +2 -3
- data/ext/libxml/ruby_xml_html_parser_context.c +145 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +48 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +1 -1
- data/ext/libxml/ruby_xml_io.c +30 -0
- data/ext/libxml/ruby_xml_io.h +9 -0
- data/ext/libxml/ruby_xml_namespace.c +34 -16
- data/ext/libxml/ruby_xml_namespace.h +2 -2
- data/ext/libxml/ruby_xml_namespaces.c +6 -6
- data/ext/libxml/ruby_xml_node.c +1367 -1324
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_parser.c +26 -78
- data/ext/libxml/ruby_xml_parser.h +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +284 -13
- data/ext/libxml/ruby_xml_parser_context.h +1 -2
- data/ext/libxml/ruby_xml_parser_options.c +75 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +277 -183
- data/ext/libxml/ruby_xml_sax_parser.c +60 -57
- data/ext/libxml/ruby_xml_xpath_context.c +43 -8
- data/ext/libxml/ruby_xml_xpath_expression.c +6 -0
- data/ext/libxml/ruby_xml_xpath_object.c +107 -95
- data/ext/libxml/ruby_xml_xpath_object.h +9 -1
- data/ext/libxml/ruby_xml_xpointer.c +107 -107
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +43 -3
- data/lib/libxml.rb +2 -3
- data/lib/libxml/attr.rb +71 -2
- data/lib/libxml/attr_decl.rb +81 -0
- data/lib/libxml/document.rb +78 -14
- data/lib/libxml/html_parser.rb +75 -42
- data/lib/libxml/node.rb +11 -0
- data/lib/libxml/parser.rb +106 -62
- data/lib/libxml/reader.rb +12 -0
- data/lib/libxml/sax_parser.rb +42 -52
- data/lib/libxml/xpath_object.rb +15 -0
- data/test/model/atom.xml +12 -12
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +146 -147
- data/test/model/merge_bug_data.xml +1 -1
- data/test/model/rubynet.xml +1 -0
- data/test/model/shiporder.rng +1 -1
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +30 -30
- data/test/model/xinclude.xml +1 -1
- data/test/{tc_node_attr.rb → tc_attr.rb} +1 -1
- data/test/tc_attr_decl.rb +131 -0
- data/test/tc_deprecated_require.rb +1 -3
- data/test/tc_document.rb +13 -3
- data/test/tc_document_write.rb +5 -5
- data/test/tc_dtd.rb +13 -5
- data/test/tc_html_parser.rb +14 -26
- data/test/tc_node_cdata.rb +1 -3
- data/test/tc_node_comment.rb +2 -4
- data/test/tc_node_edit.rb +2 -3
- data/test/tc_node_text.rb +35 -1
- data/test/tc_node_write.rb +3 -3
- data/test/tc_node_xlink.rb +2 -4
- data/test/tc_parser.rb +163 -70
- data/test/tc_parser_context.rb +103 -42
- data/test/tc_reader.rb +173 -45
- data/test/tc_relaxng.rb +2 -2
- data/test/tc_sax_parser.rb +48 -52
- data/test/tc_schema.rb +2 -2
- data/test/tc_xpath.rb +37 -6
- data/test/tc_xpath_context.rb +7 -1
- data/test/tc_xpath_expression.rb +1 -3
- data/test/tc_xpointer.rb +1 -3
- data/test/test_suite.rb +2 -3
- metadata +20 -13
- data/ext/libxml/ruby_xml_input.c +0 -329
- data/ext/libxml/ruby_xml_input.h +0 -20
- data/lib/libxml/parser_context.rb +0 -17
- data/lib/libxml/parser_options.rb +0 -25
- data/test/model/simple.xml +0 -7
- data/test/tc_input.rb +0 -13
- data/test/tc_well_formed.rb +0 -11
data/test/tc_node_cdata.rb
CHANGED
@@ -3,9 +3,7 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
class CDataCommentTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
xp = XML::Parser.
|
7
|
-
str = '<root></root>'
|
8
|
-
assert_equal(str, xp.string = str)
|
6
|
+
xp = XML::Parser.string('<root></root>')
|
9
7
|
@doc = xp.parse
|
10
8
|
assert_instance_of(XML::Document, @doc)
|
11
9
|
@root = @doc.root
|
data/test/tc_node_comment.rb
CHANGED
@@ -2,10 +2,8 @@ require "xml"
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class NodeCommentTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
xp = XML::Parser.
|
7
|
-
str = '<root></root>'
|
8
|
-
assert_equal(str, xp.string = str)
|
5
|
+
def setup
|
6
|
+
xp = XML::Parser.string('<root></root>')
|
9
7
|
@doc = xp.parse
|
10
8
|
assert_instance_of(XML::Document, @doc)
|
11
9
|
@root = @doc.root
|
data/test/tc_node_edit.rb
CHANGED
@@ -3,8 +3,7 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
class TestNodeEdit < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
xp = XML::Parser.
|
7
|
-
xp.string = '<test><num>one</num><num>two</num><num>three</num></test>'
|
6
|
+
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
8
7
|
@doc = xp.parse
|
9
8
|
end
|
10
9
|
|
@@ -108,7 +107,7 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
108
107
|
end
|
109
108
|
|
110
109
|
def test_set_base
|
111
|
-
@doc.root.
|
110
|
+
@doc.root.base_uri = 'http://www.rubynet.org/'
|
112
111
|
assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
|
113
112
|
@doc.root.to_s)
|
114
113
|
end
|
data/test/tc_node_text.rb
CHANGED
@@ -14,4 +14,38 @@ class TestTextNode < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
assert_equal('wrong argument type nil (expected String)', error.to_s)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
# Disabling output escaping can't work without this test passing.
|
19
|
+
def test_text_node_name_sanity
|
20
|
+
node = XML::Node.new_text('testdata')
|
21
|
+
assert_equal XML::Node::XML_STRING_TEXT.object_id, node.name.object_id
|
22
|
+
node.name = 'ignore-me'
|
23
|
+
assert_equal XML::Node::XML_STRING_TEXT.object_id, node.name.object_id
|
24
|
+
node.name = XML::Node::XML_STRING_TEXT_NOENC
|
25
|
+
assert_equal XML::Node::XML_STRING_TEXT_NOENC.object_id, node.name.object_id
|
26
|
+
node.name = 'ignore-me'
|
27
|
+
assert_equal XML::Node::XML_STRING_TEXT_NOENC.object_id, node.name.object_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_text_node_name_singletons_frozen
|
31
|
+
assert XML::Node::XML_STRING_TEXT.frozen?
|
32
|
+
assert XML::Node::XML_STRING_TEXT_NOENC.frozen?
|
33
|
+
end
|
34
|
+
|
35
|
+
# We use the same facility that libXSLT does here to disable output escaping.
|
36
|
+
# This lets you specify that the node's content should be rendered unaltered
|
37
|
+
# whenever it is being output. This is useful for things like <script> and
|
38
|
+
# <style> nodes in HTML documents if you don't want to be forced to wrap them
|
39
|
+
# in CDATA nodes. Or if you are sanitizing existing HTML documents and want
|
40
|
+
# to preserve the content of any of the text nodes.
|
41
|
+
#
|
42
|
+
def test_output_escaping
|
43
|
+
node = XML::Node.new_text('<my> "entity"')
|
44
|
+
assert_equal '<my> "entity"', node.to_s
|
45
|
+
node.name = XML::Node::XML_STRING_TEXT_NOENC
|
46
|
+
assert_equal '<my> "entity"', node.to_s
|
47
|
+
node.name = XML::Node::XML_STRING_TEXT
|
48
|
+
assert_equal '<my> "entity"', node.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/test/tc_node_write.rb
CHANGED
@@ -53,20 +53,20 @@ class TestNodeWrite < Test::Unit::TestCase
|
|
53
53
|
# ö - c3 b6 in hex, \303\266 in octal
|
54
54
|
# ü - c3 bc in hex, \303\274 in octal
|
55
55
|
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
56
|
-
node.to_s(:encoding => XML::
|
56
|
+
node.to_s(:encoding => XML::Encoding::UTF_8))
|
57
57
|
|
58
58
|
# ISO_8859_1:
|
59
59
|
# ö - f6 in hex, \366 in octal
|
60
60
|
# ü - fc in hex, \374 in octal
|
61
61
|
assert_equal("<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
62
|
-
node.to_s(:encoding => XML::
|
62
|
+
node.to_s(:encoding => XML::Encoding::ISO_8859_1))
|
63
63
|
|
64
64
|
|
65
65
|
# Invalid encoding
|
66
66
|
error = assert_raise(ArgumentError) do
|
67
67
|
node.to_s(:encoding => -9999)
|
68
68
|
end
|
69
|
-
assert_equal('Unknown encoding
|
69
|
+
assert_equal('Unknown encoding value: -9999', error.to_s)
|
70
70
|
end
|
71
71
|
|
72
72
|
# --- Debug ---
|
data/test/tc_node_xlink.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
# $Id: tc_node_xlink.rb
|
1
|
+
# $Id: tc_node_xlink.rb 710 2009-01-20 05:30:51Z cfis $
|
2
2
|
require "xml"
|
3
3
|
require 'test/unit'
|
4
4
|
|
5
5
|
class TC_XML_Node_XLink < Test::Unit::TestCase
|
6
6
|
def setup()
|
7
|
-
xp = XML::Parser.
|
8
|
-
str = '<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>'
|
9
|
-
assert_equal(str, xp.string = str)
|
7
|
+
xp = XML::Parser.string('<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>')
|
10
8
|
doc = xp.parse
|
11
9
|
assert_instance_of(XML::Document, doc)
|
12
10
|
@root = doc.root
|
data/test/tc_parser.rb
CHANGED
@@ -5,110 +5,164 @@ require 'stringio'
|
|
5
5
|
class TestParser < Test::Unit::TestCase
|
6
6
|
def setup
|
7
7
|
XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
|
8
|
-
@xp = XML::Parser.new
|
9
8
|
end
|
10
9
|
|
11
10
|
def teardown
|
12
|
-
@xp = nil
|
13
11
|
GC.start
|
14
12
|
GC.start
|
15
13
|
GC.start
|
16
14
|
end
|
17
15
|
|
18
16
|
# ----- Sources ------
|
19
|
-
def
|
20
|
-
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/
|
17
|
+
def test_document
|
18
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
19
|
+
parser = XML::Parser.file(file)
|
20
|
+
doc = parser.parse
|
21
21
|
|
22
|
-
|
23
|
-
assert_equal(file, @xp.file)
|
24
|
-
assert_equal(file, @xp.input.file)
|
22
|
+
parser = XML::Parser.document(doc)
|
25
23
|
|
26
|
-
doc =
|
27
|
-
assert_instance_of(XML::Document, doc)
|
28
|
-
assert_instance_of(XML::Parser::Context, @xp.context)
|
29
|
-
GC.start
|
30
|
-
GC.start
|
31
|
-
GC.start
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_file_class
|
35
|
-
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
24
|
+
doc = parser.parse
|
36
25
|
|
37
|
-
|
38
|
-
assert_instance_of(XML::Parser,
|
39
|
-
assert_equal(file, xp.file)
|
40
|
-
assert_equal(file, xp.input.file)
|
26
|
+
assert_instance_of(XML::Document, doc)
|
27
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
41
28
|
end
|
42
29
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
@xp.string = str
|
47
|
-
assert_equal(str, @xp.string)
|
48
|
-
assert_equal(str, @xp.input.string)
|
30
|
+
def test_file
|
31
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
49
32
|
|
50
|
-
|
33
|
+
parser = XML::Parser.file(file)
|
34
|
+
doc = parser.parse
|
51
35
|
assert_instance_of(XML::Document, doc)
|
52
|
-
assert_instance_of(XML::Parser::Context,
|
36
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
53
37
|
end
|
54
38
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
@xp.parse
|
59
|
-
end
|
39
|
+
def test_file_encoding
|
40
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
41
|
+
parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
|
60
42
|
|
61
|
-
assert_raise(
|
62
|
-
|
43
|
+
error = assert_raise(XML::Error) do
|
44
|
+
doc = parser.parse
|
63
45
|
end
|
64
|
-
end
|
65
46
|
|
66
|
-
|
67
|
-
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
47
|
+
assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
|
68
48
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
assert_equal(str, xp.input.string)
|
49
|
+
parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
|
50
|
+
doc = parser.parse
|
51
|
+
assert_not_nil(doc)
|
73
52
|
end
|
74
53
|
|
75
|
-
def
|
76
|
-
File.
|
77
|
-
@xp.io = io
|
78
|
-
assert_equal(io, @xp.io)
|
79
|
-
assert_equal(io, @xp.input.io)
|
54
|
+
def test_file_base_uri
|
55
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
80
56
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
57
|
+
parser = XML::Parser.file(file)
|
58
|
+
doc = parser.parse
|
59
|
+
assert(doc.child.base.match(/test\/model\/bands.xml/))
|
60
|
+
|
61
|
+
parser = XML::Parser.file(file, :base_uri => "http://libxml.org")
|
62
|
+
doc = parser.parse
|
63
|
+
assert(doc.child.base.match(/test\/model\/bands.xml/))
|
85
64
|
end
|
86
65
|
|
87
|
-
def
|
66
|
+
def test_io
|
88
67
|
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
|
89
|
-
|
90
|
-
assert_instance_of(XML::Parser,
|
91
|
-
assert_equal(io, xp.io)
|
92
|
-
assert_equal(io, xp.input.io)
|
68
|
+
parser = XML::Parser.io(io)
|
69
|
+
assert_instance_of(XML::Parser, parser)
|
93
70
|
|
94
|
-
doc =
|
71
|
+
doc = parser.parse
|
95
72
|
assert_instance_of(XML::Document, doc)
|
96
|
-
assert_instance_of(XML::Parser::Context,
|
73
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
97
74
|
end
|
98
75
|
end
|
99
76
|
|
100
77
|
def test_string_io
|
101
78
|
data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
102
79
|
string_io = StringIO.new(data)
|
103
|
-
|
104
|
-
|
105
|
-
|
80
|
+
parser = XML::Parser.io(string_io)
|
81
|
+
|
82
|
+
doc = parser.parse
|
83
|
+
assert_instance_of(XML::Document, doc)
|
84
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_string
|
88
|
+
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
89
|
+
|
90
|
+
parser = XML::Parser.string(str)
|
91
|
+
assert_instance_of(XML::Parser, parser)
|
106
92
|
|
107
|
-
doc =
|
93
|
+
doc = parser.parse
|
108
94
|
assert_instance_of(XML::Document, doc)
|
109
|
-
assert_instance_of(XML::Parser::Context,
|
95
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_string_options
|
99
|
+
xml = <<-EOS
|
100
|
+
<!DOCTYPE foo [<!ENTITY foo 'bar'>]>
|
101
|
+
<test>
|
102
|
+
<cdata><![CDATA[something]]></cdata>
|
103
|
+
<entity>&foo;</entity>
|
104
|
+
</test>
|
105
|
+
EOS
|
106
|
+
|
107
|
+
XML::default_substitute_entities = false
|
108
|
+
|
109
|
+
# Parse normally
|
110
|
+
parser = XML::Parser.string(xml)
|
111
|
+
doc = parser.parse
|
112
|
+
assert_nil(doc.child.base)
|
113
|
+
|
114
|
+
# Cdata section should be cdata nodes
|
115
|
+
node = doc.find_first('/test/cdata').child
|
116
|
+
assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type)
|
117
|
+
|
118
|
+
# Entities should not be subtituted
|
119
|
+
node = doc.find_first('/test/entity')
|
120
|
+
assert_equal('&foo;', node.child.to_s)
|
121
|
+
|
122
|
+
# Parse with options
|
123
|
+
parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
|
124
|
+
:options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT)
|
125
|
+
doc = parser.parse
|
126
|
+
assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org')
|
127
|
+
|
128
|
+
# Cdata section should be text nodes
|
129
|
+
node = doc.find_first('/test/cdata').child
|
130
|
+
assert_equal(XML::Node::TEXT_NODE, node.node_type)
|
131
|
+
|
132
|
+
# Entities should be subtituted
|
133
|
+
node = doc.find_first('/test/entity')
|
134
|
+
assert_equal('bar', node.child.to_s)
|
110
135
|
end
|
111
136
|
|
137
|
+
def test_string_encoding
|
138
|
+
# ISO_8859_1:
|
139
|
+
# ö - f6 in hex, \366 in octal
|
140
|
+
# ü - fc in hex, \374 in octal
|
141
|
+
|
142
|
+
xml = <<-EOS
|
143
|
+
<bands>
|
144
|
+
<metal>m\366tley_cr\374e</metal>
|
145
|
+
</bands>
|
146
|
+
EOS
|
147
|
+
|
148
|
+
# Parse as UTF_8
|
149
|
+
parser = XML::Parser.string(xml)
|
150
|
+
|
151
|
+
error = assert_raise(XML::Error) do
|
152
|
+
doc = parser.parse
|
153
|
+
end
|
154
|
+
|
155
|
+
assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
|
156
|
+
error.to_s)
|
157
|
+
|
158
|
+
# Parse as ISO_8859_1:
|
159
|
+
parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1)
|
160
|
+
doc = parser.parse
|
161
|
+
node = doc.find_first('//metal')
|
162
|
+
assert_equal("m\303\266tley_cr\303\274e", node.content)
|
163
|
+
end
|
164
|
+
|
165
|
+
|
112
166
|
def test_fd_gc
|
113
167
|
# Test opening # of documents up to the file limit for the OS.
|
114
168
|
# Ideally it should run until libxml emits a warning,
|
@@ -155,9 +209,9 @@ class TestParser < Test::Unit::TestCase
|
|
155
209
|
end
|
156
210
|
|
157
211
|
def test_bad_xml
|
158
|
-
|
212
|
+
parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
159
213
|
error = assert_raise(XML::Error) do
|
160
|
-
assert_not_nil(
|
214
|
+
assert_not_nil(parser.parse)
|
161
215
|
end
|
162
216
|
|
163
217
|
assert_not_nil(error)
|
@@ -176,12 +230,51 @@ class TestParser < Test::Unit::TestCase
|
|
176
230
|
assert_nil(error.node)
|
177
231
|
end
|
178
232
|
|
179
|
-
|
180
|
-
|
233
|
+
# Deprecated methods
|
234
|
+
def test_document_deprecated
|
235
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
236
|
+
parser = XML::Parser.file(file)
|
181
237
|
doc = parser.parse
|
182
238
|
|
183
|
-
|
184
|
-
|
239
|
+
parser = XML::Parser.new
|
240
|
+
parser.document = doc
|
241
|
+
doc = parser.parse
|
242
|
+
|
243
|
+
assert_instance_of(XML::Document, doc)
|
244
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_file_deprecated
|
248
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
249
|
+
|
250
|
+
parser = XML::Parser.new
|
251
|
+
parser.file = file
|
252
|
+
doc = parser.parse
|
253
|
+
assert_instance_of(XML::Document, doc)
|
254
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_io_deprecated
|
258
|
+
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
|
259
|
+
parser = XML::Parser.new
|
260
|
+
assert_instance_of(XML::Parser, parser)
|
261
|
+
parser.io = io
|
262
|
+
|
263
|
+
doc = parser.parse
|
264
|
+
assert_instance_of(XML::Document, doc)
|
265
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
185
266
|
end
|
186
267
|
end
|
268
|
+
|
269
|
+
def test_string_deprecated
|
270
|
+
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
271
|
+
|
272
|
+
parser = XML::Parser.new
|
273
|
+
parser.string = str
|
274
|
+
assert_instance_of(XML::Parser, parser)
|
275
|
+
|
276
|
+
doc = parser.parse
|
277
|
+
assert_instance_of(XML::Document, doc)
|
278
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
279
|
+
end
|
187
280
|
end
|
data/test/tc_parser_context.rb
CHANGED
@@ -2,101 +2,162 @@ require "xml"
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TestParserContext < Test::Unit::TestCase
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
def test_string
|
6
|
+
# UTF8
|
7
|
+
xml = <<-EOS
|
8
|
+
<bands>
|
9
|
+
<metal>m\303\266tley_cr\303\274e</metal>
|
10
|
+
</bands>
|
11
|
+
EOS
|
12
|
+
|
13
|
+
context = XML::Parser::Context.string(xml)
|
14
|
+
assert_instance_of(XML::Parser::Context, context)
|
15
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
16
|
+
assert_nil(context.base_uri)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_encoding
|
20
|
+
# ISO_8859_1:
|
21
|
+
xml = <<-EOS
|
22
|
+
<bands>
|
23
|
+
<metal>m\366tley_cr\374e</metal>
|
24
|
+
</bands>
|
25
|
+
EOS
|
26
|
+
|
27
|
+
context = XML::Parser::Context.string(xml)
|
28
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
29
|
+
|
30
|
+
context.encoding = XML::Encoding::ISO_8859_1
|
31
|
+
assert_equal(XML::Encoding::ISO_8859_1, context.encoding)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_base_uri
|
35
|
+
# UTF8
|
36
|
+
xml = <<-EOS
|
37
|
+
<bands>
|
38
|
+
<metal>m\303\266tley_cr\303\274e</metal>
|
39
|
+
</bands>
|
40
|
+
EOS
|
41
|
+
|
42
|
+
context = XML::Parser::Context.string(xml)
|
43
|
+
assert_nil(context.base_uri)
|
44
|
+
|
45
|
+
context.base_uri = 'http://libxml.rubyforge.org'
|
46
|
+
assert_equal('http://libxml.rubyforge.org', context.base_uri)
|
13
47
|
end
|
14
48
|
|
15
|
-
def
|
16
|
-
|
49
|
+
def test_string_empty
|
50
|
+
error = assert_raise(TypeError) do
|
51
|
+
parser = XML::Parser::Context.string(nil)
|
52
|
+
end
|
53
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
54
|
+
|
55
|
+
error = assert_raise(ArgumentError) do
|
56
|
+
XML::Parser::Context.string('')
|
57
|
+
end
|
58
|
+
assert_equal("Must specify a string with one or more characters", error.to_s)
|
17
59
|
end
|
18
60
|
|
19
61
|
def test_well_formed
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
62
|
+
parser = XML::Parser.string("<abc/>")
|
63
|
+
parser.parse
|
64
|
+
assert(parser.context.well_formed?)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_not_well_formed
|
68
|
+
parser = XML::Parser.string("<abc>")
|
69
|
+
assert_raise(XML::Error) do
|
70
|
+
parser.parse
|
24
71
|
end
|
72
|
+
assert(!parser.context.well_formed?)
|
25
73
|
end
|
26
74
|
|
27
75
|
def test_version_info
|
28
|
-
|
76
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
77
|
+
parser = XML::Parser.file(file)
|
78
|
+
assert_nil(parser.context.version)
|
79
|
+
parser.parse
|
80
|
+
assert_equal("1.0", parser.context.version)
|
29
81
|
end
|
30
82
|
|
31
83
|
def test_depth
|
32
|
-
|
84
|
+
context = XML::Parser::Context.new
|
85
|
+
assert_instance_of(Fixnum, context.depth)
|
33
86
|
end
|
34
87
|
|
35
88
|
def test_disable_sax
|
36
|
-
|
89
|
+
context = XML::Parser::Context.new
|
90
|
+
assert(!context.disable_sax?)
|
37
91
|
end
|
38
92
|
|
39
93
|
def test_docbook
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def test_encoding
|
44
|
-
assert(!@ctxt.encoding)
|
94
|
+
context = XML::Parser::Context.new
|
95
|
+
assert(!context.docbook?)
|
45
96
|
end
|
46
97
|
|
47
98
|
def test_html
|
48
|
-
|
99
|
+
context = XML::Parser::Context.new
|
100
|
+
assert(!context.html?)
|
49
101
|
end
|
50
102
|
|
51
103
|
def test_keep_blanks
|
52
|
-
|
53
|
-
|
104
|
+
context = XML::Parser::Context.new
|
105
|
+
if context.keep_blanks?
|
106
|
+
assert_instance_of(TrueClass, context.keep_blanks?)
|
54
107
|
else
|
55
|
-
assert_instance_of(FalseClass,
|
108
|
+
assert_instance_of(FalseClass, context.keep_blanks?)
|
56
109
|
end
|
57
110
|
end
|
58
111
|
|
59
112
|
if ENV['NOTWORKING']
|
60
113
|
def test_num_chars
|
61
|
-
assert_equal(17,
|
114
|
+
assert_equal(17, context.num_chars)
|
62
115
|
end
|
63
116
|
end
|
64
117
|
|
65
118
|
def test_replace_entities
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
119
|
+
context = XML::Parser::Context.new
|
120
|
+
assert(!context.replace_entities?)
|
121
|
+
|
122
|
+
# context.options = 1
|
123
|
+
# assert(context.replace_entities?)
|
124
|
+
|
125
|
+
context.options = 0
|
126
|
+
assert(!context.replace_entities?)
|
127
|
+
|
128
|
+
context.replace_entities = true
|
129
|
+
assert(context.replace_entities?)
|
71
130
|
end
|
72
131
|
|
73
132
|
def test_space_depth
|
74
|
-
|
133
|
+
context = XML::Parser::Context.new
|
134
|
+
assert_equal(1, context.space_depth)
|
75
135
|
end
|
76
136
|
|
77
137
|
def test_subset_external
|
78
|
-
|
138
|
+
context = XML::Parser::Context.new
|
139
|
+
assert(!context.subset_external?)
|
79
140
|
end
|
80
141
|
|
81
142
|
def test_data_directory_get
|
82
|
-
|
143
|
+
context = XML::Parser::Context.new
|
144
|
+
assert_nil(context.data_directory)
|
83
145
|
end
|
84
146
|
|
85
147
|
def test_parse_error
|
86
|
-
xp = XML::Parser.
|
87
|
-
|
88
|
-
|
148
|
+
xp = XML::Parser.string('<foo><bar/></foz>')
|
149
|
+
|
89
150
|
assert_raise(XML::Error) do
|
90
151
|
xp.parse
|
91
152
|
end
|
92
|
-
|
153
|
+
|
93
154
|
# Now check context
|
94
155
|
context = xp.context
|
95
156
|
assert_equal(nil, context.data_directory)
|
96
157
|
assert_equal(0, context.depth)
|
97
158
|
assert_equal(true, context.disable_sax?)
|
98
159
|
assert_equal(false, context.docbook?)
|
99
|
-
assert_equal(
|
160
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
100
161
|
assert_equal(76, context.errno)
|
101
162
|
assert_equal(false, context.html?)
|
102
163
|
assert_equal(5, context.io_max_num_streams)
|
@@ -107,7 +168,7 @@ class TestParserContext < Test::Unit::TestCase
|
|
107
168
|
assert_equal(0, context.name_depth)
|
108
169
|
assert_equal(10, context.name_depth_max)
|
109
170
|
assert_equal(17, context.num_chars)
|
110
|
-
assert_equal(
|
171
|
+
assert_equal(false, context.replace_entities?)
|
111
172
|
assert_equal(1, context.space_depth)
|
112
173
|
assert_equal(10, context.space_depth_max)
|
113
174
|
assert_equal(false, context.subset_external?)
|
@@ -122,4 +183,4 @@ class TestParserContext < Test::Unit::TestCase
|
|
122
183
|
assert_equal('1.0', context.version)
|
123
184
|
assert_equal(false, context.well_formed?)
|
124
185
|
end
|
125
|
-
end
|
186
|
+
end
|