libxml-ruby 0.7.0-x86-mswin32-60 → 0.8.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +24 -1
- data/README +48 -3
- data/benchmark/depixelate.rb +632 -0
- data/benchmark/hamlet.xml +9055 -0
- data/benchmark/sock_entries.xml +507 -0
- data/benchmark/throughput.rb +39 -0
- data/benchmark/xml_benchmarks.rb +222 -0
- data/doc/classes/LibXML.html +237 -0
- data/doc/classes/LibXML/XML.html +178 -0
- data/doc/classes/{XML → LibXML/XML}/Attr.html +213 -182
- data/doc/classes/{XML → LibXML/XML}/Attributes.html +126 -54
- data/doc/classes/{XML → LibXML/XML}/Document.html +299 -297
- data/doc/classes/{XML → LibXML/XML}/Dtd.html +10 -10
- data/doc/classes/{XML/XInclude → LibXML/XML}/Error.html +4 -4
- data/doc/classes/{XML → LibXML/XML}/HTMLParser.html +40 -40
- data/doc/classes/{XML → LibXML/XML}/InputCallbacks.html +10 -10
- data/doc/classes/{XML → LibXML/XML}/NS.html +46 -46
- data/doc/classes/{XML → LibXML/XML}/Node.html +935 -788
- data/doc/classes/LibXML/XML/Node/FailedModify.html +111 -0
- data/doc/classes/{XML → LibXML/XML}/Node/Set.html +69 -68
- data/doc/classes/{XML → LibXML/XML}/Node/SetNamespace.html +4 -4
- data/doc/classes/{XML/Node/FailedModify.html → LibXML/XML/Node/UnknownType.html} +4 -4
- data/doc/classes/{XML → LibXML/XML}/Parser.html +426 -389
- data/doc/classes/{XML → LibXML/XML}/Parser/Context.html +208 -208
- data/doc/classes/{XML → LibXML/XML}/Parser/ParseError.html +4 -4
- data/doc/classes/{XML → LibXML/XML}/Reader.html +288 -287
- data/doc/classes/{XML → LibXML/XML}/SaxParser.html +52 -52
- data/doc/classes/{XML/XPath/Context.html → LibXML/XML/Schema.html} +60 -32
- data/doc/classes/{XML → LibXML/XML}/State.html +4 -4
- data/doc/classes/{XML/Node/UnknownType.html → LibXML/XML/Tree.html} +5 -5
- data/doc/classes/{XML → LibXML/XML}/XInclude.html +5 -5
- data/doc/classes/{XML → LibXML/XML/XInclude}/Error.html +5 -5
- data/doc/classes/{XML → LibXML/XML}/XMLParserOptions.html +5 -5
- data/doc/classes/{XML → LibXML/XML}/XPath.html +23 -64
- data/doc/classes/LibXML/XML/XPath/Context.html +403 -0
- data/doc/classes/{XML/XPointer/Context → LibXML/XML/XPath}/InvalidPath.html +4 -4
- data/doc/classes/LibXML/XML/XPath/Object.html +623 -0
- data/doc/classes/{XML → LibXML/XML}/XPointer.html +12 -12
- data/doc/classes/{XML → LibXML/XML}/XPointer/Context.html +5 -5
- data/doc/classes/{XML/XPath → LibXML/XML/XPointer/Context}/InvalidPath.html +5 -5
- data/doc/classes/{XML → LibXML/XML}/XPointer/InvalidExpression.html +4 -4
- data/doc/classes/XML.html +17 -123
- data/doc/created.rid +1 -1
- data/doc/files/CHANGES.html +49 -25
- data/doc/files/LICENSE.html +1 -1
- data/doc/files/README.html +79 -4
- data/doc/files/VERSION.html +2 -2
- data/doc/files/ext/libxml/cbg_c.html +1 -1
- data/doc/files/ext/libxml/libxml_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_document_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_node_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_state_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
- data/doc/files/lib/libxml/attr_rb.html +108 -0
- data/doc/files/lib/libxml/attributes_rb.html +108 -0
- data/doc/files/lib/libxml/document_rb.html +108 -0
- data/doc/files/lib/libxml/node_rb.html +108 -0
- data/doc/files/lib/libxml/node_set_rb.html +108 -0
- data/doc/files/lib/libxml/parser_options_rb.html +107 -0
- data/doc/files/{ext/libxml/ruby_xml_tree_c.html → lib/libxml/parser_rb.html} +4 -4
- data/doc/files/lib/libxml/properties_rb.html +108 -0
- data/doc/files/lib/libxml/tree_rb.html +107 -0
- data/doc/files/lib/libxml_rb.html +12 -3
- data/doc/fr_class_index.html +34 -32
- data/doc/fr_file_index.html +9 -1
- data/doc/fr_method_index.html +362 -347
- data/ext/libxml/cbg.c +76 -76
- data/ext/libxml/libxml.c +4 -3
- data/ext/libxml/ruby_libxml.h +1 -1
- data/ext/libxml/ruby_xml_attr.c +4 -3
- data/ext/libxml/ruby_xml_attr.h +16 -16
- data/ext/libxml/ruby_xml_attributes.c +267 -266
- data/ext/libxml/ruby_xml_attributes.h +17 -17
- data/ext/libxml/ruby_xml_document.c +30 -59
- data/ext/libxml/ruby_xml_document.h +27 -27
- data/ext/libxml/ruby_xml_dtd.c +2 -1
- data/ext/libxml/ruby_xml_dtd.h +17 -17
- data/ext/libxml/ruby_xml_html_parser.c +3 -2
- data/ext/libxml/ruby_xml_html_parser.h +29 -29
- data/ext/libxml/ruby_xml_input_cbg.c +2 -1
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_node.c +127 -470
- data/ext/libxml/ruby_xml_node.h +17 -17
- data/ext/libxml/ruby_xml_node_set.c +5 -4
- data/ext/libxml/ruby_xml_node_set.h +20 -20
- data/ext/libxml/ruby_xml_ns.c +3 -2
- data/ext/libxml/ruby_xml_ns.h +12 -12
- data/ext/libxml/ruby_xml_parser.c +20 -48
- data/ext/libxml/ruby_xml_parser.h +31 -31
- data/ext/libxml/ruby_xml_parser_context.c +3 -2
- data/ext/libxml/ruby_xml_parser_context.h +20 -20
- data/ext/libxml/ruby_xml_reader.c +2 -1
- data/ext/libxml/ruby_xml_sax_parser.c +3 -2
- data/ext/libxml/ruby_xml_sax_parser.h +56 -56
- data/ext/libxml/ruby_xml_schema.c +6 -0
- data/ext/libxml/ruby_xml_schema.h +16 -16
- data/ext/libxml/ruby_xml_state.c +13 -12
- data/ext/libxml/ruby_xml_state.h +1 -1
- data/ext/libxml/ruby_xml_xinclude.c +3 -2
- data/ext/libxml/ruby_xml_xinclude.h +13 -13
- data/ext/libxml/ruby_xml_xpath.c +35 -228
- data/ext/libxml/ruby_xml_xpath.h +22 -23
- data/ext/libxml/ruby_xml_xpath_context.c +223 -62
- data/ext/libxml/ruby_xml_xpath_context.h +15 -20
- data/ext/libxml/ruby_xml_xpath_object.c +63 -19
- data/ext/libxml/ruby_xml_xpointer.c +19 -15
- data/ext/libxml/ruby_xml_xpointer.h +27 -27
- data/ext/libxml/ruby_xml_xpointer_context.c +3 -2
- data/ext/libxml/ruby_xml_xpointer_context.h +18 -18
- data/ext/libxml/version.h +9 -9
- data/lib/libxml.rb +16 -128
- data/lib/libxml/attr.rb +45 -0
- data/lib/libxml/attributes.rb +15 -0
- data/lib/libxml/document.rb +54 -0
- data/lib/libxml/node.rb +132 -0
- data/lib/libxml/node_set.rb +27 -0
- data/lib/libxml/parser.rb +42 -0
- data/lib/libxml/parser_options.rb +25 -0
- data/lib/libxml/properties.rb +19 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml_ruby.so +0 -0
- data/mingw/libxml_ruby.so +0 -0
- data/{work/task/setup → setup.rb} +1585 -1616
- data/test/gc.log +0 -0
- data/test/model/books.xml +147 -0
- data/{work/test/runner.rb → test/model/default_validation_bug.rb} +0 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/rubynet.xml +78 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/saxtest.xml +5 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +31 -0
- data/test/model/simple.xml +7 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/tc_deprecated_require.rb +13 -0
- data/test/tc_xml_document.rb +57 -16
- data/test/tc_xml_document_write.rb +125 -10
- data/test/tc_xml_dtd.rb +22 -1
- data/test/tc_xml_node.rb +13 -0
- data/test/tc_xml_node_edit.rb +1 -1
- data/test/tc_xml_node_xlink.rb +1 -1
- data/test/tc_xml_parser.rb +64 -7
- data/test/tc_xml_properties.rb +42 -0
- data/test/tc_xml_reader.rb +4 -4
- data/test/tc_xml_sax_parser.rb +50 -50
- data/test/tc_xml_schema.rb +2 -2
- data/test/tc_xml_traversal.rb +220 -0
- data/test/tc_xml_xinclude.rb +12 -15
- data/test/tc_xml_xpath.rb +74 -6
- data/test/tc_xml_xpath_context.rb +72 -0
- data/test/test_suite.rb +6 -4
- data/vc/libxml_ruby.vcproj +1 -9
- metadata +92 -65
- data/doc/classes/XML/SiblingEnum.html +0 -142
- data/doc/classes/XML/Tree.html +0 -224
- data/doc/classes/XML/XPath/Object.html +0 -439
- data/ext/libxml/ruby_xml_tree.c +0 -43
- data/ext/libxml/ruby_xml_tree.h +0 -12
- data/test/ets_copy_bug2.rb +0 -21
- data/test/tc_xml_document_write2.rb +0 -54
- data/test/tc_xml_document_write3.rb +0 -96
- data/test/tc_xml_sax_parser2.rb +0 -51
- data/work/Rakefile +0 -247
- data/work/task/make +0 -26
- data/work/task/memory +0 -37
- data/work/task/rdoc +0 -39
- data/work/task/test +0 -29
- data/work/test/ets_runner.rb +0 -33
- data/work/test/libxml_test.rb +0 -3
- data/work/test/runner_ets.rb +0 -33
@@ -2,23 +2,138 @@ require "libxml"
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TC_XML_Document_Write < Test::Unit::TestCase
|
5
|
-
def setup
|
5
|
+
def setup
|
6
6
|
@doc = XML::Document.new('1.0')
|
7
|
-
assert_instance_of(XML::Document, @doc)
|
8
7
|
end
|
9
8
|
|
10
|
-
def teardown
|
9
|
+
def teardown
|
11
10
|
@doc = nil
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
assert_instance_of(XML::Document,
|
13
|
+
def test_klass
|
14
|
+
assert_instance_of(XML::Document, @doc)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_version
|
16
18
|
assert_equal('1.0', @doc.version)
|
17
|
-
end # def test_ruby_xml_document_initialize()
|
18
19
|
|
19
|
-
def test_ruby_xml_document_write_initialize2()
|
20
20
|
doc = XML::Document.new('6.9')
|
21
|
-
assert_instance_of(XML::Document, doc)
|
22
21
|
assert_equal('6.9', doc.version)
|
23
|
-
end
|
24
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_write_root
|
25
|
+
@doc.root = XML::Node.new('rubynet')
|
26
|
+
assert_instance_of(XML::Node, @doc.root)
|
27
|
+
assert_instance_of(XML::Document, @doc.root.doc)
|
28
|
+
assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_write_root
|
32
|
+
@doc.root = XML::Node.new('rubynet')
|
33
|
+
assert_instance_of(XML::Node, @doc.root)
|
34
|
+
assert_instance_of(XML::Document, @doc.root.doc)
|
35
|
+
assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s(false))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_encoding
|
39
|
+
@doc.root = XML::Node.new('rubynet')
|
40
|
+
@doc.encoding = 'UTF-8'
|
41
|
+
assert_instance_of(XML::Node, @doc.root)
|
42
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n", @doc.to_s)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_child()
|
46
|
+
xml = "<?xml version=\"1.0\"?>\n<rubynet>\n <pkg/>\n</rubynet>\n"
|
47
|
+
@doc.root = XML::Node.new('rubynet')
|
48
|
+
@doc.root.child = XML::Node.new('pkg')
|
49
|
+
assert_equal(xml, @doc.to_s)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_append
|
53
|
+
xml = "<?xml version=\"1.0\"?>\n"
|
54
|
+
xml << "<rubynet>\n"
|
55
|
+
xml << " <pkg>\n"
|
56
|
+
xml << " <meta>\n"
|
57
|
+
xml << " <pkgname>libxml</pkgname>\n"
|
58
|
+
xml << " </meta>\n"
|
59
|
+
xml << " </pkg>\n"
|
60
|
+
xml << "</rubynet>\n"
|
61
|
+
|
62
|
+
@doc.root = XML::Node.new('rubynet')
|
63
|
+
pkg = @doc.root.child = XML::Node.new('pkg')
|
64
|
+
meta = pkg.child = XML::Node.new('meta')
|
65
|
+
assert_equal(meta, meta << (pkgname = XML::Node.new('pkgname')))
|
66
|
+
pkgname << 'libxml'
|
67
|
+
assert_equal(xml, @doc.to_s)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_node_search_href
|
71
|
+
prefix = 'xlink'
|
72
|
+
uri = 'http://www.rubynet.org'
|
73
|
+
xml = "<?xml version=\"1.0\"?>\n"
|
74
|
+
xml << "<rubynet xmlns:#{prefix}=\"#{uri}\">\n"
|
75
|
+
xml << " <pkg/>\n"
|
76
|
+
xml << "</rubynet>\n"
|
77
|
+
|
78
|
+
@doc.root = XML::Node.new('rubynet')
|
79
|
+
@doc = XML::Parser.string(xml).parse
|
80
|
+
assert_equal(xml, @doc.to_s)
|
81
|
+
ns = @doc.root.search_href(uri)
|
82
|
+
assert_instance_of(XML::NS, ns)
|
83
|
+
assert_equal(uri, ns.href)
|
84
|
+
assert_equal(prefix, ns.prefix)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_sibling
|
88
|
+
xml = "<?xml version=\"1.0\"?>\n<rubynet>\n <pkg/>\n <pkg2/>\n</rubynet>\n"
|
89
|
+
|
90
|
+
@doc.root = XML::Node.new('rubynet')
|
91
|
+
child = @doc.root.child = XML::Node.new('pkg')
|
92
|
+
assert_instance_of(XML::Node, child)
|
93
|
+
child.sibling = XML::Node.new('pkg2')
|
94
|
+
assert_equal(xml, @doc.to_s)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_set_doc_property
|
98
|
+
xml = "<?xml version=\"1.0\"?>\n"
|
99
|
+
xml << "<rubynet xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
|
100
|
+
xml << " <pkg/>\n"
|
101
|
+
xml << "</rubynet>\n"
|
102
|
+
|
103
|
+
@doc.root = XML::Node.new('rubynet')
|
104
|
+
@doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"
|
105
|
+
pkg = @doc.root.child = XML::Node.new('pkg')
|
106
|
+
assert_equal(xml, @doc.to_s)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_set_node_base
|
110
|
+
xml = "<?xml version=\"1.0\"?>\n"
|
111
|
+
xml << "<rubynet>\n"
|
112
|
+
xml << " <pkg xml:base=\"http://www.rubynet.org/\"/>\n"
|
113
|
+
xml << "</rubynet>\n"
|
114
|
+
|
115
|
+
@doc.root = XML::Node.new('rubynet')
|
116
|
+
pkg = @doc.root.child = XML::Node.new('pkg')
|
117
|
+
pkg.base = 'http://www.rubynet.org/'
|
118
|
+
assert_equal(xml, @doc.to_s)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_set_node_property
|
122
|
+
xml = "<?xml version=\"1.0\"?>\n"
|
123
|
+
xml << "<rubynet xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
|
124
|
+
xml << " <pkg version=\"1.0\">\n"
|
125
|
+
xml << " <meta>\n"
|
126
|
+
xml << " <pkgname>libxml</pkgname>\n"
|
127
|
+
xml << " </meta>\n"
|
128
|
+
xml << " </pkg>\n"
|
129
|
+
xml << "</rubynet>\n"
|
130
|
+
|
131
|
+
@doc.root = XML::Node.new('rubynet')
|
132
|
+
@doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"
|
133
|
+
pkg = @doc.root.child = XML::Node.new('pkg')
|
134
|
+
pkg['version'] = '1.0'
|
135
|
+
meta = pkg.child = XML::Node.new('meta')
|
136
|
+
pkgname = meta.child = XML::Node.new('pkgname', 'libxml')
|
137
|
+
assert_equal(xml, @doc.to_s)
|
138
|
+
end
|
139
|
+
end
|
data/test/tc_xml_dtd.rb
CHANGED
@@ -46,4 +46,25 @@ class TestDtd < Test::Unit::TestCase
|
|
46
46
|
|
47
47
|
assert_equal(expected, messages)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
|
+
def test_external_dtd
|
51
|
+
xml = <<-EOS
|
52
|
+
<!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []>
|
53
|
+
<test>
|
54
|
+
<title>T1</title>
|
55
|
+
</test>
|
56
|
+
EOS
|
57
|
+
|
58
|
+
messages = Array.new
|
59
|
+
XML::Parser.register_error_handler(lambda { |msg| messages << msg })
|
60
|
+
|
61
|
+
XML::Parser.default_load_external_dtd = false
|
62
|
+
doc = XML::Parser.string(xml).parse
|
63
|
+
assert_equal(Array.new, messages)
|
64
|
+
|
65
|
+
XML::Parser.default_load_external_dtd = true
|
66
|
+
doc = XML::Parser.string(xml).parse
|
67
|
+
assert_equal('I/O warning : failed to load external entity "test.dtd" <!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []> ^',
|
68
|
+
messages.map{|msg| msg.strip}.join(' '))
|
69
|
+
end
|
70
|
+
end
|
data/test/tc_xml_node.rb
CHANGED
@@ -80,6 +80,19 @@ class TestNode < Test::Unit::TestCase
|
|
80
80
|
assert(!node_a.equal?(node_a2))
|
81
81
|
end
|
82
82
|
|
83
|
+
def test_equality_nil
|
84
|
+
node = @doc.root
|
85
|
+
assert(node != nil)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_equality_wrong_type
|
89
|
+
node = @doc.root
|
90
|
+
|
91
|
+
assert_raises(TypeError) do
|
92
|
+
assert(node != 'abc')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
83
96
|
def test_content()
|
84
97
|
assert_equal('onetwo', @doc.root.content)
|
85
98
|
|
data/test/tc_xml_node_edit.rb
CHANGED
data/test/tc_xml_node_xlink.rb
CHANGED
data/test/tc_xml_parser.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require "libxml"
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestParser < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
+
XML::Parser.register_error_handler(nil)
|
6
7
|
@xp = XML::Parser.new
|
7
|
-
assert_not_nil(@xp)
|
8
8
|
end
|
9
9
|
|
10
10
|
def teardown
|
11
11
|
@xp = nil
|
12
|
+
XML::Parser.register_error_handler(nil)
|
13
|
+
# Clear out all the files we opened up in
|
14
|
+
# the test_fd_gc test
|
15
|
+
GC.start
|
12
16
|
end
|
13
17
|
|
14
18
|
# ----- Constants ------
|
@@ -157,7 +161,7 @@ class TextParser < Test::Unit::TestCase
|
|
157
161
|
end
|
158
162
|
|
159
163
|
def test_file
|
160
|
-
file = File.expand_path('model/rubynet.xml')
|
164
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
161
165
|
|
162
166
|
@xp.filename = file
|
163
167
|
assert_equal(file, @xp.filename)
|
@@ -167,21 +171,71 @@ class TextParser < Test::Unit::TestCase
|
|
167
171
|
end
|
168
172
|
|
169
173
|
def test_io
|
170
|
-
File.open('model/rubynet.xml') do |f|
|
174
|
+
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |f|
|
171
175
|
assert_kind_of(IO, f)
|
172
176
|
assert_kind_of(IO, @xp.io = f)
|
173
177
|
assert_instance_of(XML::Document, @xp.parse)
|
174
178
|
end # File.open
|
175
179
|
end # def test_libxml_parser_io
|
176
180
|
|
181
|
+
def test_fd_gc
|
182
|
+
# Test opening # of documents up to the file limit for the OS.
|
183
|
+
# Ideally it should run until libxml emits a warning,
|
184
|
+
# thereby knowing we've done a GC sweep. For the time being,
|
185
|
+
# re-open the same doc `limit descriptors` times.
|
186
|
+
# If we make it to the end, then we've succeeded,
|
187
|
+
# otherwise an exception will be thrown.
|
188
|
+
XML::Parser.register_error_handler(lambda {|msg| nil })
|
189
|
+
|
190
|
+
max_fd = if RUBY_PLATFORM.match(/mswin32/i)
|
191
|
+
500
|
192
|
+
else
|
193
|
+
(`ulimit -n`.chomp.to_i) + 1
|
194
|
+
end
|
195
|
+
|
196
|
+
filename = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
|
197
|
+
max_fd.times do
|
198
|
+
XML::Document.file(filename)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
177
202
|
def test_libxml_parser_features
|
178
203
|
assert_instance_of(Array, XML::Parser::features)
|
179
204
|
end
|
180
|
-
|
205
|
+
|
181
206
|
# ----- Errors ------
|
182
207
|
def test_error_handler
|
183
|
-
|
184
|
-
|
208
|
+
assert_raise(XML::Parser::ParseError) do
|
209
|
+
XML::Parser.string('<foo><bar/></foz>').parse
|
210
|
+
end
|
211
|
+
|
212
|
+
ary = []
|
213
|
+
XML::Parser.register_error_handler do |msg|
|
214
|
+
ary << msg
|
215
|
+
end
|
216
|
+
|
217
|
+
# this will use our error handler
|
218
|
+
assert_raise(XML::Parser::ParseError) do
|
219
|
+
XML::Parser.string('<foo><bar/></foz>').parse
|
220
|
+
end
|
221
|
+
|
222
|
+
assert_equal(["Entity: line 1: ",
|
223
|
+
"parser ",
|
224
|
+
"error : ",
|
225
|
+
"Opening and ending tag mismatch: foo line 1 and foz\n",
|
226
|
+
"<foo><bar/></foz>\n",
|
227
|
+
" ^\n"], ary)
|
228
|
+
|
229
|
+
assert_instance_of(Proc, XML::Parser.register_error_handler(nil))
|
230
|
+
|
231
|
+
# this will go to stderr again
|
232
|
+
assert_raise(XML::Parser::ParseError) do
|
233
|
+
d = XML::Parser.string('<foo><bar/></foz>').parse
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_error_handler_lambda
|
238
|
+
XML::Parser.register_error_handler(nil)
|
185
239
|
assert_raise(XML::Parser::ParseError) do
|
186
240
|
XML::Parser.string('<foo><bar/></foz>').parse
|
187
241
|
end
|
@@ -211,12 +265,14 @@ class TextParser < Test::Unit::TestCase
|
|
211
265
|
|
212
266
|
def test_bad_xml
|
213
267
|
@xp.string = '<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
268
|
+
XML::Parser.register_error_handler(lambda {|msg| nil })
|
214
269
|
assert_raise(XML::Parser::ParseError) do
|
215
270
|
assert_not_nil(@xp.parse)
|
216
271
|
end
|
217
272
|
end
|
218
273
|
|
219
274
|
def test_double_parse
|
275
|
+
XML::Parser.register_error_handler(lambda {|msg| nil })
|
220
276
|
parser = XML::Parser.string("<test>something</test>")
|
221
277
|
doc = parser.parse
|
222
278
|
|
@@ -228,6 +284,7 @@ class TextParser < Test::Unit::TestCase
|
|
228
284
|
def test_libxml_parser_empty_string
|
229
285
|
assert_raise(XML::Parser::ParseError) do
|
230
286
|
@xp.string = ''
|
287
|
+
@xp.parse
|
231
288
|
end
|
232
289
|
|
233
290
|
assert_raise(TypeError) do
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "libxml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
# Properties is deprecated - use attributes instead.
|
5
|
+
# Tests for backwards compatibility
|
6
|
+
|
7
|
+
class TestProperties < Test::Unit::TestCase
|
8
|
+
def setup()
|
9
|
+
xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
10
|
+
@doc = xp.parse
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown()
|
14
|
+
@doc = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_traversal
|
18
|
+
properties = @doc.root.properties
|
19
|
+
|
20
|
+
assert_instance_of(XML::Attributes, properties)
|
21
|
+
attribute = properties.first
|
22
|
+
assert_equal('uga', attribute.name)
|
23
|
+
assert_equal('booga', attribute.value)
|
24
|
+
|
25
|
+
attribute = attribute.next
|
26
|
+
assert_instance_of(XML::Attr, attribute)
|
27
|
+
assert_equal('foo', attribute.name)
|
28
|
+
assert_equal('bar', attribute.value)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_each_attr
|
32
|
+
@doc.root.properties.each_attr do |attribute|
|
33
|
+
assert_instance_of(XML::Attr, attribute)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_no_properties
|
38
|
+
properties = @doc.root.child.properties
|
39
|
+
assert_instance_of(XML::Attributes, properties)
|
40
|
+
assert_equal(0, properties.length)
|
41
|
+
end
|
42
|
+
end
|
data/test/tc_xml_reader.rb
CHANGED
@@ -7,18 +7,18 @@ class TC_XML_Reader < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def test_new_file
|
9
9
|
reader = XML::Reader.file(SIMPLE_XML)
|
10
|
-
|
10
|
+
verify_simple(reader)
|
11
11
|
assert_raises(RuntimeError) { XML::Reader.file('/does/not/exist') }
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_new_data
|
15
15
|
reader = XML::Reader.new(File.read(SIMPLE_XML))
|
16
|
-
|
16
|
+
verify_simple(reader)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_new_walker
|
20
20
|
reader = XML::Reader.walker(XML::Document.file(SIMPLE_XML))
|
21
|
-
|
21
|
+
verify_simple(reader)
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_reader_error
|
@@ -81,7 +81,7 @@ class TC_XML_Reader < Test::Unit::TestCase
|
|
81
81
|
doc.standalone?
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
84
|
+
def verify_simple(reader)
|
85
85
|
node_types = []
|
86
86
|
19.times do
|
87
87
|
assert_equal(1, reader.read)
|
data/test/tc_xml_sax_parser.rb
CHANGED
@@ -3,58 +3,72 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
# TODO this is woefully inadequate
|
5
5
|
|
6
|
-
class
|
7
|
-
|
8
|
-
include XML::SaxParser::Callbacks
|
6
|
+
class TestCaseCallbacks
|
7
|
+
include XML::SaxParser::Callbacks
|
9
8
|
|
10
|
-
|
9
|
+
attr_accessor :test
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def initialize
|
12
|
+
@test = Hash.new { |h,k| h[k] = [] }
|
13
|
+
@i = 0
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def on_start_document
|
17
|
+
@test[:startdoc] << @i+=1
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def on_start_element(name, attr_hash)
|
21
|
+
@test[:startel] << [@i+=1,name,attr_hash]
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def on_characters(chars)
|
25
|
+
@test[:chars] << [@i+=1,chars]
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def on_comment(msg)
|
29
|
+
@test[:comment] << [@i+=1,msg]
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def on_processing_instruction(target, data)
|
33
|
+
@test[:pinstr] << [@i+=1, target, data]
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def on_cdata_block(cdata)
|
37
|
+
@test[:cdata] << [@i+=1,cdata]
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def on_end_element(name)
|
41
|
+
@test[:endel] << [@i+=1,name]
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
44
|
+
def on_end_document
|
45
|
+
@test[:enddoc] << @i+=1
|
48
46
|
end
|
47
|
+
end
|
49
48
|
|
50
|
-
|
49
|
+
class TestSaxParser < Test::Unit::TestCase
|
50
|
+
def setup
|
51
51
|
@xp = XML::SaxParser.new
|
52
52
|
end
|
53
53
|
|
54
|
-
def teardown
|
54
|
+
def teardown
|
55
55
|
@xp = nil
|
56
56
|
end
|
57
57
|
|
58
|
+
def verify
|
59
|
+
@xp.parse
|
60
|
+
assert_equal [1], @xp.callbacks.test[:startdoc]
|
61
|
+
assert_equal [[2,'test',{'uga'=>'booga','foo'=>'bar'}],[3,'fixnum',{}],[6,'fixnum',{}]],
|
62
|
+
@xp.callbacks.test[:startel]
|
63
|
+
assert_equal [[4,'one'],[7,'two'],[9,"\n "],[11,"\n "],[13,"\n "],[15,"\n"]],
|
64
|
+
@xp.callbacks.test[:chars]
|
65
|
+
assert_equal [[10, ' msg ']], @xp.callbacks.test[:comment]
|
66
|
+
assert_equal [[12, 'custom', 'foo="bar"']], @xp.callbacks.test[:pinstr]
|
67
|
+
assert_equal [[14, 'here it goes']], @xp.callbacks.test[:cdata]
|
68
|
+
assert_equal [[5,'fixnum'],[8,'fixnum'],[16,'test']], @xp.callbacks.test[:endel]
|
69
|
+
assert_equal [17], @xp.callbacks.test[:enddoc]
|
70
|
+
end
|
71
|
+
|
58
72
|
def test_string_without_callbacks
|
59
73
|
@xp.string = File.read(File.join(File.dirname(__FILE__), 'model/saxtest.xml'))
|
60
74
|
assert_equal true, @xp.parse
|
@@ -68,29 +82,15 @@ class TC_XML_SaxParser2 < Test::Unit::TestCase
|
|
68
82
|
def test_callbacks_with_string
|
69
83
|
@xp.callbacks = TestCaseCallbacks.new
|
70
84
|
@xp.string = File.read(File.join(File.dirname(__FILE__), 'model/saxtest.xml'))
|
71
|
-
|
85
|
+
verify
|
72
86
|
end
|
73
87
|
|
74
88
|
def test_callbacks_with_file
|
75
89
|
@xp.callbacks = TestCaseCallbacks.new
|
76
90
|
@xp.filename = File.join(File.dirname(__FILE__), 'model/saxtest.xml')
|
77
|
-
|
91
|
+
verify
|
78
92
|
end
|
79
93
|
|
80
|
-
def do_test
|
81
|
-
@xp.parse
|
82
|
-
assert_equal [1], @xp.callbacks.test[:startdoc]
|
83
|
-
assert_equal [[2,'test',{'uga'=>'booga','foo'=>'bar'}],[3,'fixnum',{}],[6,'fixnum',{}]],
|
84
|
-
@xp.callbacks.test[:startel]
|
85
|
-
assert_equal [[4,'one'],[7,'two'],[9,"\n "],[11,"\n "],[13,"\n "],[15,"\n"]],
|
86
|
-
@xp.callbacks.test[:chars]
|
87
|
-
assert_equal [[10, ' msg ']], @xp.callbacks.test[:comment]
|
88
|
-
assert_equal [[12, 'custom', 'foo="bar"']], @xp.callbacks.test[:pinstr]
|
89
|
-
assert_equal [[14, 'here it goes']], @xp.callbacks.test[:cdata]
|
90
|
-
assert_equal [[5,'fixnum'],[8,'fixnum'],[16,'test']], @xp.callbacks.test[:endel]
|
91
|
-
assert_equal [17], @xp.callbacks.test[:enddoc]
|
92
|
-
end
|
93
|
-
|
94
94
|
def test_doctype
|
95
95
|
@xp.callbacks = TestCaseCallbacks.new
|
96
96
|
@xp.string = <<-EOS
|