libxml-ruby 2.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +516 -0
- data/LICENSE +23 -0
- data/MANIFEST +165 -0
- data/README.rdoc +161 -0
- data/Rakefile +82 -0
- data/ext/libxml/extconf.rb +122 -0
- data/ext/libxml/libxml.c +93 -0
- data/ext/libxml/ruby_libxml.h +101 -0
- data/ext/libxml/ruby_xml.c +893 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml_attr.c +352 -0
- data/ext/libxml/ruby_xml_attr.h +14 -0
- data/ext/libxml/ruby_xml_attr_decl.c +171 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +277 -0
- data/ext/libxml/ruby_xml_attributes.h +17 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +958 -0
- data/ext/libxml/ruby_xml_document.h +17 -0
- data/ext/libxml/ruby_xml_dtd.c +257 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +221 -0
- data/ext/libxml/ruby_xml_encoding.h +16 -0
- data/ext/libxml/ruby_xml_error.c +1004 -0
- data/ext/libxml/ruby_xml_error.h +14 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- 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 +170 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespaces.c +295 -0
- data/ext/libxml/ruby_xml_namespaces.h +11 -0
- data/ext/libxml/ruby_xml_node.c +1386 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +14 -0
- data/ext/libxml/ruby_xml_parser_context.c +982 -0
- data/ext/libxml/ruby_xml_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_parser_options.c +68 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +1057 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_relaxng.c +111 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
- data/ext/libxml/ruby_xml_sax_parser.c +136 -0
- data/ext/libxml/ruby_xml_sax_parser.h +12 -0
- data/ext/libxml/ruby_xml_schema.c +159 -0
- data/ext/libxml/ruby_xml_schema.h +11 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_xinclude.c +18 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xpath.c +107 -0
- data/ext/libxml/ruby_xml_xpath.h +12 -0
- data/ext/libxml/ruby_xml_xpath_context.c +390 -0
- data/ext/libxml/ruby_xml_xpath_context.h +11 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
- data/ext/libxml/ruby_xml_xpath_object.c +336 -0
- data/ext/libxml/ruby_xml_xpath_object.h +19 -0
- data/ext/libxml/ruby_xml_xpointer.c +101 -0
- data/ext/libxml/ruby_xml_xpointer.h +13 -0
- data/ext/mingw/Rakefile +34 -0
- data/ext/mingw/build.rake +41 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/1.8/libxml_ruby.so +0 -0
- data/lib/1.9/libxml_ruby.so +0 -0
- data/lib/libxml.rb +30 -0
- data/lib/libxml/attr.rb +113 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +192 -0
- data/lib/libxml/error.rb +90 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +399 -0
- data/lib/libxml/ns.rb +22 -0
- data/lib/libxml/parser.rb +367 -0
- data/lib/libxml/properties.rb +23 -0
- data/lib/libxml/reader.rb +29 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +58 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml/xpath_object.rb +16 -0
- data/lib/xml.rb +16 -0
- data/lib/xml/libxml.rb +10 -0
- data/libxml-ruby.gemspec +50 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1585 -0
- data/test/etc_doc_to_s.rb +21 -0
- data/test/ets_doc_file.rb +17 -0
- data/test/ets_doc_to_s.rb +23 -0
- data/test/ets_gpx.rb +28 -0
- data/test/ets_node_gc.rb +23 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +11 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +146 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +31 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/rb-magic-comment.rb +33 -0
- data/test/tc_attr.rb +181 -0
- data/test/tc_attr_decl.rb +133 -0
- data/test/tc_attributes.rb +135 -0
- data/test/tc_deprecated_require.rb +13 -0
- data/test/tc_document.rb +119 -0
- data/test/tc_document_write.rb +187 -0
- data/test/tc_dtd.rb +125 -0
- data/test/tc_error.rb +138 -0
- data/test/tc_html_parser.rb +140 -0
- data/test/tc_namespace.rb +62 -0
- data/test/tc_namespaces.rb +177 -0
- data/test/tc_node.rb +258 -0
- data/test/tc_node_cdata.rb +51 -0
- data/test/tc_node_comment.rb +33 -0
- data/test/tc_node_copy.rb +42 -0
- data/test/tc_node_edit.rb +160 -0
- data/test/tc_node_text.rb +71 -0
- data/test/tc_node_write.rb +108 -0
- data/test/tc_node_xlink.rb +29 -0
- data/test/tc_parser.rb +336 -0
- data/test/tc_parser_context.rb +189 -0
- data/test/tc_properties.rb +39 -0
- data/test/tc_reader.rb +298 -0
- data/test/tc_relaxng.rb +54 -0
- data/test/tc_sax_parser.rb +276 -0
- data/test/tc_schema.rb +53 -0
- data/test/tc_traversal.rb +222 -0
- data/test/tc_xinclude.rb +21 -0
- data/test/tc_xml.rb +226 -0
- data/test/tc_xpath.rb +195 -0
- data/test/tc_xpath_context.rb +80 -0
- data/test/tc_xpath_expression.rb +38 -0
- data/test/tc_xpointer.rb +74 -0
- data/test/test_helper.rb +14 -0
- data/test/test_suite.rb +39 -0
- metadata +254 -0
data/test/tc_dtd.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestDtd < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
xp = XML::Parser.string(<<-EOS)
|
10
|
+
<root>
|
11
|
+
<head a="ee" id="1">Colorado</head>
|
12
|
+
<descr>Lots of nice mountains</descr>
|
13
|
+
</root>
|
14
|
+
EOS
|
15
|
+
@doc = xp.parse
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
@doc = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def dtd
|
23
|
+
XML::Dtd.new(<<-EOS)
|
24
|
+
<!ELEMENT root (head, descr)>
|
25
|
+
<!ELEMENT head (#PCDATA)>
|
26
|
+
<!ATTLIST head
|
27
|
+
id NMTOKEN #REQUIRED
|
28
|
+
a CDATA #IMPLIED
|
29
|
+
>
|
30
|
+
<!ELEMENT descr (#PCDATA)>
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_internal_subset
|
35
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true
|
36
|
+
assert xhtml_dtd.name.nil?
|
37
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
38
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
39
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
40
|
+
|
41
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true
|
42
|
+
assert_equal "xhtml1", xhtml_dtd.name
|
43
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
44
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
45
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_external_subset
|
49
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil
|
50
|
+
assert xhtml_dtd.name.nil?
|
51
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
52
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
53
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
54
|
+
|
55
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1"
|
56
|
+
assert_equal "xhtml1", xhtml_dtd.name
|
57
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
58
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
59
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_valid
|
63
|
+
assert(@doc.validate(dtd))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_invalid
|
67
|
+
new_node = XML::Node.new('invalid', 'this will mess up validation')
|
68
|
+
@doc.root << new_node
|
69
|
+
|
70
|
+
error = assert_raise(XML::Error) do
|
71
|
+
@doc.validate(dtd)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Check the error worked
|
75
|
+
assert_not_nil(error)
|
76
|
+
assert_kind_of(XML::Error, error)
|
77
|
+
assert_equal("Error: No declaration for element invalid.", error.message)
|
78
|
+
assert_equal(XML::Error::VALID, error.domain)
|
79
|
+
assert_equal(XML::Error::DTD_UNKNOWN_ELEM, error.code)
|
80
|
+
assert_equal(XML::Error::ERROR, error.level)
|
81
|
+
assert_nil(error.file)
|
82
|
+
assert_nil(error.line)
|
83
|
+
assert_equal('invalid', error.str1)
|
84
|
+
assert_equal('invalid', error.str2)
|
85
|
+
assert_nil(error.str3)
|
86
|
+
assert_equal(0, error.int1)
|
87
|
+
assert_equal(0, error.int2)
|
88
|
+
assert_not_nil(error.node)
|
89
|
+
assert_equal('invalid', error.node.name)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_external_dtd
|
93
|
+
xml = <<-EOS
|
94
|
+
<!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []>
|
95
|
+
<test>
|
96
|
+
<title>T1</title>
|
97
|
+
</test>
|
98
|
+
EOS
|
99
|
+
|
100
|
+
errors = Array.new
|
101
|
+
XML::Error.set_handler do |error|
|
102
|
+
errors << error
|
103
|
+
end
|
104
|
+
|
105
|
+
XML.default_load_external_dtd = false
|
106
|
+
doc = XML::Parser.string(xml).parse
|
107
|
+
assert_equal(0, errors.length)
|
108
|
+
|
109
|
+
errors.clear
|
110
|
+
XML.default_load_external_dtd = true
|
111
|
+
doc = XML::Parser.string(xml).parse
|
112
|
+
assert_equal(1, errors.length)
|
113
|
+
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
114
|
+
errors[0].to_s)
|
115
|
+
|
116
|
+
errors = Array.new
|
117
|
+
doc = XML::Parser.string(xml, :options => XML::Parser::Options::DTDLOAD).parse
|
118
|
+
assert_equal(1, errors.length)
|
119
|
+
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
120
|
+
errors[0].to_s)
|
121
|
+
ensure
|
122
|
+
XML.default_load_external_dtd = false
|
123
|
+
XML::Error.reset_handler
|
124
|
+
end
|
125
|
+
end
|
data/test/tc_error.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
class TestError < Test::Unit::TestCase
|
8
|
+
def test_invalid_handler
|
9
|
+
assert_raises(RuntimeError) do
|
10
|
+
XML::Error.set_handler
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_handler
|
15
|
+
exception = nil
|
16
|
+
XML::Error.set_handler do |error|
|
17
|
+
exception = error
|
18
|
+
end
|
19
|
+
|
20
|
+
# Raise the error
|
21
|
+
XML::Reader.new('<foo').read
|
22
|
+
|
23
|
+
# Check the handler worked
|
24
|
+
assert_not_nil(exception)
|
25
|
+
assert_kind_of(XML::Error, exception)
|
26
|
+
assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
|
27
|
+
assert_equal(XML::Error::XML_FROM_PARSER, exception.domain)
|
28
|
+
assert_equal(XML::Error::XML_ERR_GT_REQUIRED, exception.code)
|
29
|
+
assert_equal(XML::Error::XML_ERR_FATAL, exception.level)
|
30
|
+
assert_nil(exception.file)
|
31
|
+
assert_equal(1, exception.line)
|
32
|
+
assert_equal('foo', exception.str1)
|
33
|
+
assert_nil(exception.str2)
|
34
|
+
assert_nil(exception.str3)
|
35
|
+
assert_equal(0, exception.int1)
|
36
|
+
assert_equal(5, exception.int2)
|
37
|
+
assert_nil(exception.node)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_reset_handler
|
41
|
+
exception = nil
|
42
|
+
XML::Error.set_handler do |error|
|
43
|
+
exception = error
|
44
|
+
end
|
45
|
+
|
46
|
+
XML::Error.reset_handler
|
47
|
+
reader = XML::Reader.new('<foo')
|
48
|
+
assert_nil(exception)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_verbose_handler
|
52
|
+
XML::Error.set_handler(&XML::Error::VERBOSE_HANDLER)
|
53
|
+
output = StringIO.new
|
54
|
+
original_stderr = Object::STDERR
|
55
|
+
|
56
|
+
Object.const_set(:STDERR, output)
|
57
|
+
begin
|
58
|
+
assert_raise(XML::Error) do
|
59
|
+
XML::Parser.string('<foo><bar/></foz>').parse
|
60
|
+
end
|
61
|
+
ensure
|
62
|
+
Object.const_set(:STDERR, original_stderr)
|
63
|
+
end
|
64
|
+
assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_no_hanlder
|
68
|
+
XML::Error.reset_handler
|
69
|
+
output = StringIO.new
|
70
|
+
original_stderr = Object::STDERR
|
71
|
+
|
72
|
+
Object.const_set(:STDERR, output)
|
73
|
+
begin
|
74
|
+
assert_raise(XML::Error) do
|
75
|
+
XML::Parser.string('<foo><bar/></foz>').parse
|
76
|
+
end
|
77
|
+
ensure
|
78
|
+
Object.const_set(:STDERR, original_stderr)
|
79
|
+
end
|
80
|
+
assert_equal('', output.string)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_parse_error
|
84
|
+
exception = assert_raise(XML::Error) do
|
85
|
+
XML::Parser.string('<foo><bar/></foz>').parse
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_instance_of(XML::Error, exception)
|
89
|
+
assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
|
90
|
+
assert_equal(XML::Error::XML_FROM_PARSER, exception.domain)
|
91
|
+
assert_equal(XML::Error::XML_ERR_TAG_NAME_MISMATCH, exception.code)
|
92
|
+
assert_equal(XML::Error::XML_ERR_FATAL, exception.level)
|
93
|
+
assert_nil(exception.file)
|
94
|
+
assert_equal(1, exception.line)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_xpath_error
|
98
|
+
doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
|
99
|
+
|
100
|
+
exception = assert_raise(XML::Error) do
|
101
|
+
elements = doc.find('/foo[bar=test')
|
102
|
+
end
|
103
|
+
|
104
|
+
assert_instance_of(XML::Error, exception)
|
105
|
+
assert_equal("Error: Invalid predicate at :0.", exception.message)
|
106
|
+
assert_equal(XML::Error::XML_FROM_XPATH, exception.domain)
|
107
|
+
assert_equal(XML::Error::XML_XPATH_INVALID_PREDICATE_ERROR, exception.code)
|
108
|
+
assert_equal(XML::Error::XML_ERR_ERROR, exception.level)
|
109
|
+
assert_nil(exception.file)
|
110
|
+
assert_nil(nil)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_double_parse
|
114
|
+
XML::Parser.register_error_handler(lambda {|msg| nil })
|
115
|
+
parser = XML::Parser.string("<test>something</test>")
|
116
|
+
doc = parser.parse
|
117
|
+
|
118
|
+
error = assert_raise(RuntimeError) do
|
119
|
+
# Try parsing a second time
|
120
|
+
parser.parse
|
121
|
+
end
|
122
|
+
|
123
|
+
assert_equal("You cannot parse a data source twice", error.to_s)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_libxml_parser_empty_string
|
127
|
+
xp = XML::Parser.new
|
128
|
+
|
129
|
+
assert_raise(TypeError) do
|
130
|
+
xp.string = nil
|
131
|
+
end
|
132
|
+
|
133
|
+
xp.string = ''
|
134
|
+
assert_raise(XML::Error) do
|
135
|
+
xp.parse
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class HTMLParserTest < Test::Unit::TestCase
|
8
|
+
def html_file
|
9
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
|
10
|
+
end
|
11
|
+
|
12
|
+
# ----- Sources ------
|
13
|
+
def test_file
|
14
|
+
xp = XML::HTMLParser.file(html_file)
|
15
|
+
assert_instance_of(XML::HTMLParser, xp)
|
16
|
+
doc = xp.parse
|
17
|
+
assert_not_nil(doc)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_noexistent_file
|
21
|
+
error = assert_raise(XML::Error) do
|
22
|
+
XML::HTMLParser.file('i_dont_exist.xml')
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_nil_file
|
29
|
+
error = assert_raise(TypeError) do
|
30
|
+
XML::HTMLParser.file(nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_equal("can't convert nil into String", error.to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_io
|
37
|
+
File.open(html_file) do |io|
|
38
|
+
xp = XML::HTMLParser.io(io)
|
39
|
+
assert_instance_of(XML::HTMLParser, xp)
|
40
|
+
|
41
|
+
doc = xp.parse
|
42
|
+
assert_instance_of(XML::Document, doc)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_io_gc
|
47
|
+
# Test that the reader keeps a reference
|
48
|
+
# to the io object
|
49
|
+
file = File.open(html_file)
|
50
|
+
parser = XML::HTMLParser.io(file)
|
51
|
+
file = nil
|
52
|
+
GC.start
|
53
|
+
assert(parser.parse)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_nil_io
|
57
|
+
error = assert_raise(TypeError) do
|
58
|
+
XML::HTMLParser.io(nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_equal("Must pass in an IO object", error.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_string_io
|
65
|
+
data = File.read(html_file)
|
66
|
+
io = StringIO.new(data)
|
67
|
+
xp = XML::HTMLParser.io(io)
|
68
|
+
assert_instance_of(XML::HTMLParser, xp)
|
69
|
+
|
70
|
+
doc = xp.parse
|
71
|
+
assert_instance_of(XML::Document, doc)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_string
|
75
|
+
str = '<html><body><p>hi</p></body></html>'
|
76
|
+
xp = XML::HTMLParser.string(str)
|
77
|
+
|
78
|
+
assert_instance_of(XML::HTMLParser, xp)
|
79
|
+
assert_instance_of(XML::HTMLParser, xp)
|
80
|
+
|
81
|
+
doc = xp.parse
|
82
|
+
assert_instance_of(XML::Document, doc)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_nil_string
|
86
|
+
error = assert_raise(TypeError) do
|
87
|
+
XML::HTMLParser.string(nil)
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_parse
|
94
|
+
html = <<-EOS
|
95
|
+
<html>
|
96
|
+
<head>
|
97
|
+
<meta name=keywords content=nasty>
|
98
|
+
</head>
|
99
|
+
<body>Hello<br>World</html>
|
100
|
+
EOS
|
101
|
+
|
102
|
+
parser = XML::HTMLParser.string(html)
|
103
|
+
doc = parser.parse
|
104
|
+
assert_instance_of XML::Document, doc
|
105
|
+
|
106
|
+
root = doc.root
|
107
|
+
assert_instance_of XML::Node, root
|
108
|
+
assert_equal 'html', root.name
|
109
|
+
|
110
|
+
head = root.child
|
111
|
+
assert_instance_of XML::Node, head
|
112
|
+
assert_equal 'head', head.name
|
113
|
+
|
114
|
+
meta = head.child
|
115
|
+
assert_instance_of XML::Node, meta
|
116
|
+
assert_equal 'meta', meta.name
|
117
|
+
assert_equal 'keywords', meta[:name]
|
118
|
+
assert_equal 'nasty', meta[:content]
|
119
|
+
|
120
|
+
body = head.next
|
121
|
+
assert_instance_of XML::Node, body
|
122
|
+
assert_equal 'body', body.name
|
123
|
+
|
124
|
+
hello = body.child
|
125
|
+
# It appears that some versions of libxml2 add a layer of <p>
|
126
|
+
# cant figure our why or how, so this skips it if there
|
127
|
+
hello = hello.child if hello.name == "p"
|
128
|
+
|
129
|
+
assert_instance_of XML::Node, hello
|
130
|
+
assert_equal 'Hello', hello.content
|
131
|
+
|
132
|
+
br = hello.next
|
133
|
+
assert_instance_of XML::Node, br
|
134
|
+
assert_equal 'br', br.name
|
135
|
+
|
136
|
+
world = br.next
|
137
|
+
assert_instance_of XML::Node, world
|
138
|
+
assert_equal 'World', world.content
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestNS < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
10
|
+
@doc = XML::Document.file(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@doc = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_ns
|
18
|
+
node = XML::Node.new('foo')
|
19
|
+
ns = XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com')
|
20
|
+
assert_equal(ns.prefix, 'my_namepace')
|
21
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_default_ns
|
25
|
+
node = XML::Node.new('foo')
|
26
|
+
ns = XML::Namespace.new(node, nil, 'http://www.mynamespace.com')
|
27
|
+
assert_equal(ns.prefix, nil)
|
28
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_unbound_ns
|
32
|
+
error = assert_raise(TypeError) do
|
33
|
+
XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
|
34
|
+
end
|
35
|
+
assert_equal('wrong argument type nil (expected Data)', error.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_duplicate_ns
|
39
|
+
node = XML::Node.new('foo')
|
40
|
+
XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
41
|
+
assert_raises(XML::Error) do
|
42
|
+
XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_eql
|
47
|
+
node = XML::Node.new('Envelope')
|
48
|
+
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
49
|
+
|
50
|
+
assert(node.namespaces.namespace.eql?(node.namespaces.namespace))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_equal
|
54
|
+
node1 = XML::Node.new('Envelope')
|
55
|
+
ns1 = XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
56
|
+
|
57
|
+
node2 = XML::Node.new('Envelope')
|
58
|
+
ns2 = XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
59
|
+
|
60
|
+
assert(ns1 == ns2)
|
61
|
+
end
|
62
|
+
end
|