libxml-ruby 0.9.8-x86-mswin32-60 → 0.9.9-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +41 -1
- data/LICENSE +3 -4
- data/README +37 -24
- data/Rakefile +2 -2
- data/ext/libxml/extconf.rb +31 -12
- data/ext/libxml/libxml.c +56 -858
- data/ext/libxml/ruby_libxml.h +93 -96
- data/ext/libxml/ruby_xml.c +855 -0
- data/ext/libxml/ruby_xml.h +9 -0
- data/ext/libxml/ruby_xml_attr.c +3 -9
- data/ext/libxml/ruby_xml_attr.h +2 -2
- data/ext/libxml/ruby_xml_attr_decl.c +2 -8
- data/ext/libxml/ruby_xml_attr_decl.h +1 -1
- data/ext/libxml/ruby_xml_attributes.c +6 -8
- data/ext/libxml/ruby_xml_attributes.h +1 -1
- data/ext/libxml/ruby_xml_document.c +915 -895
- data/ext/libxml/ruby_xml_document.h +2 -2
- data/ext/libxml/ruby_xml_dtd.c +257 -136
- data/ext/libxml/ruby_xml_dtd.h +1 -1
- data/ext/libxml/ruby_xml_encoding.c +55 -37
- data/ext/libxml/ruby_xml_encoding.h +1 -1
- data/ext/libxml/ruby_xml_error.c +526 -1058
- data/ext/libxml/ruby_xml_error.h +1 -1
- data/ext/libxml/ruby_xml_html_parser.c +2 -8
- data/ext/libxml/ruby_xml_html_parser.h +2 -2
- data/ext/libxml/ruby_xml_html_parser_context.c +175 -145
- data/ext/libxml/ruby_xml_html_parser_context.h +1 -1
- data/ext/libxml/ruby_xml_html_parser_options.c +12 -20
- data/ext/libxml/ruby_xml_html_parser_options.h +1 -1
- data/ext/libxml/ruby_xml_input_cbg.c +2 -8
- data/ext/libxml/ruby_xml_input_cbg.h +1 -1
- data/ext/libxml/ruby_xml_namespace.c +2 -8
- data/ext/libxml/ruby_xml_namespace.h +2 -2
- data/ext/libxml/ruby_xml_namespaces.c +1 -9
- data/ext/libxml/ruby_xml_namespaces.h +1 -1
- data/ext/libxml/ruby_xml_node.c +182 -121
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_parser.c +2 -8
- data/ext/libxml/ruby_xml_parser.h +2 -2
- data/ext/libxml/ruby_xml_parser_context.c +952 -901
- data/ext/libxml/ruby_xml_parser_context.h +2 -2
- data/ext/libxml/ruby_xml_parser_options.c +2 -9
- data/ext/libxml/ruby_xml_parser_options.h +1 -1
- data/ext/libxml/ruby_xml_reader.c +1002 -993
- data/ext/libxml/ruby_xml_reader.h +1 -1
- data/ext/libxml/ruby_xml_relaxng.c +1 -7
- data/ext/libxml/ruby_xml_relaxng.h +1 -1
- data/ext/libxml/ruby_xml_sax2_handler.c +2 -2
- data/ext/libxml/ruby_xml_sax2_handler.h +1 -1
- data/ext/libxml/ruby_xml_sax_parser.c +2 -8
- data/ext/libxml/ruby_xml_sax_parser.h +2 -2
- data/ext/libxml/ruby_xml_schema.c +1 -7
- data/ext/libxml/ruby_xml_schema.h +1 -1
- data/ext/libxml/{version.h → ruby_xml_version.h} +2 -2
- data/ext/libxml/ruby_xml_xinclude.c +2 -8
- data/ext/libxml/ruby_xml_xinclude.h +2 -2
- data/ext/libxml/ruby_xml_xpath.c +17 -18
- data/ext/libxml/ruby_xml_xpath.h +2 -2
- data/ext/libxml/ruby_xml_xpath_context.c +387 -389
- data/ext/libxml/ruby_xml_xpath_context.h +2 -2
- data/ext/libxml/ruby_xml_xpath_expression.c +18 -8
- data/ext/libxml/ruby_xml_xpath_expression.h +1 -1
- data/ext/libxml/ruby_xml_xpath_object.c +19 -8
- data/ext/libxml/ruby_xml_xpath_object.h +1 -1
- data/ext/libxml/ruby_xml_xpointer.c +2 -8
- data/ext/libxml/ruby_xml_xpointer.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.sln +7 -1
- data/lib/libxml.rb +1 -12
- data/lib/libxml/attr.rb +0 -3
- data/lib/libxml/attr_decl.rb +0 -3
- data/lib/libxml/attributes.rb +0 -3
- data/lib/libxml/document.rb +31 -5
- data/lib/libxml/error.rb +8 -4
- data/lib/libxml/properties.rb +0 -5
- data/lib/libxml/sax_callbacks.rb +30 -19
- data/lib/libxml/tree.rb +0 -1
- data/lib/libxml/xpath_object.rb +0 -13
- data/test/model/definition.dtd +8 -0
- data/test/tc_attributes.rb +4 -1
- data/test/tc_document.rb +16 -0
- data/test/tc_dtd.rb +30 -2
- data/test/tc_html_parser.rb +55 -10
- data/test/tc_node.rb +67 -1
- data/test/tc_node_edit.rb +26 -6
- data/test/tc_node_text.rb +41 -23
- data/test/tc_parser.rb +50 -0
- data/test/tc_reader.rb +15 -0
- data/test/tc_relaxng.rb +1 -1
- data/test/tc_sax_parser.rb +37 -5
- data/test/tc_schema.rb +1 -1
- data/test/tc_xpath.rb +1 -0
- data/test/tc_xpath_expression.rb +4 -2
- metadata +6 -6
- data/ext/libxml/ruby_xml_state.c +0 -51
- data/ext/libxml/ruby_xml_state.h +0 -11
- data/ext/vc/libxml_ruby.vcproj +0 -460
@@ -0,0 +1,8 @@
|
|
1
|
+
<!ELEMENT definition (primary_key|body|reasoning|products)* >
|
2
|
+
<!ATTLIST definition target_entity CDATA #REQUIRED>
|
3
|
+
<!ELEMENT primary_key (#PCDATA)>
|
4
|
+
<!ATTLIST primary_key name CDATA #REQUIRED>
|
5
|
+
<!ELEMENT body (#PCDATA)>
|
6
|
+
<!ELEMENT reasoning (#PCDATA)>
|
7
|
+
<!ELEMENT products (product*)>
|
8
|
+
<!ENTITY % product SYSTEM "lib/dtds/product.dtd"> %product;
|
data/test/tc_attributes.rb
CHANGED
@@ -122,9 +122,12 @@ class AttributesTest < Test::Unit::TestCase
|
|
122
122
|
node = @doc.find_first('/city:CityModel/city:cityMember')
|
123
123
|
assert_equal(5, node.attributes.length)
|
124
124
|
|
125
|
-
|
125
|
+
attrs = Array.new
|
126
|
+
node.attributes.each do |attr|
|
127
|
+
attrs << attr
|
126
128
|
attr.remove!
|
127
129
|
end
|
130
|
+
assert_equal(5, attrs.length)
|
128
131
|
assert_equal(0, node.attributes.length)
|
129
132
|
end
|
130
133
|
end
|
data/test/tc_document.rb
CHANGED
@@ -83,4 +83,20 @@ class TestDocument < Test::Unit::TestCase
|
|
83
83
|
doc.encoding = XML::Encoding::ISO_8859_1
|
84
84
|
assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
|
85
85
|
end
|
86
|
+
|
87
|
+
def test_doc_node_type
|
88
|
+
assert_equal XML::Node::DOCUMENT_NODE, XML::Document.new.node_type
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_doc_node_type_name
|
92
|
+
assert_equal 'document_xml', XML::Document.new.node_type_name
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_xhtml
|
96
|
+
doc = XML::Document.new
|
97
|
+
assert ! doc.xhtml?
|
98
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
|
99
|
+
assert doc.xhtml?
|
100
|
+
end
|
101
|
+
|
86
102
|
end
|
data/test/tc_dtd.rb
CHANGED
@@ -28,6 +28,34 @@ class TestDtd < Test::Unit::TestCase
|
|
28
28
|
EOS
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_internal_subset
|
32
|
+
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
|
33
|
+
assert xhtml_dtd.name.nil?
|
34
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
35
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
36
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
37
|
+
|
38
|
+
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
|
39
|
+
assert_equal "xhtml1", xhtml_dtd.name
|
40
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
41
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
42
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_external_subset
|
46
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil
|
47
|
+
assert xhtml_dtd.name.nil?
|
48
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
49
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
50
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
51
|
+
|
52
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1"
|
53
|
+
assert_equal "xhtml1", xhtml_dtd.name
|
54
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
55
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
56
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
57
|
+
end
|
58
|
+
|
31
59
|
def test_valid
|
32
60
|
assert(@doc.validate(dtd))
|
33
61
|
end
|
@@ -44,7 +72,7 @@ class TestDtd < Test::Unit::TestCase
|
|
44
72
|
# Check the error worked
|
45
73
|
assert_not_nil(error)
|
46
74
|
assert_kind_of(XML::Error, error)
|
47
|
-
assert_equal("Error: No declaration for element invalid
|
75
|
+
assert_equal("Error: No declaration for element invalid.", error.message)
|
48
76
|
assert_equal(XML::Error::VALID, error.domain)
|
49
77
|
assert_equal(XML::Error::DTD_UNKNOWN_ELEM, error.code)
|
50
78
|
assert_equal(XML::Error::ERROR, error.level)
|
@@ -91,4 +119,4 @@ class TestDtd < Test::Unit::TestCase
|
|
91
119
|
ensure
|
92
120
|
XML::Error.reset_handler
|
93
121
|
end
|
94
|
-
end
|
122
|
+
end
|
data/test/tc_html_parser.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'xml'
|
2
|
+
require 'stringio'
|
2
3
|
require 'test/unit'
|
3
4
|
|
4
5
|
class HTMLParserTest < Test::Unit::TestCase
|
@@ -10,29 +11,54 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
10
11
|
def test_file
|
11
12
|
xp = XML::HTMLParser.file(html_file)
|
12
13
|
assert_instance_of(XML::HTMLParser, xp)
|
14
|
+
doc = xp.parse
|
15
|
+
assert_not_nil(doc)
|
13
16
|
end
|
14
17
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
+
def test_noexistent_file
|
19
|
+
error = assert_raise(XML::Error) do
|
20
|
+
XML::HTMLParser.file('i_dont_exist.xml')
|
21
|
+
end
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
26
|
+
def test_nil_file
|
27
|
+
error = assert_raise(TypeError) do
|
28
|
+
XML::HTMLParser.file(nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_equal("can't convert nil into String", error.to_s)
|
24
32
|
end
|
25
33
|
|
26
34
|
def test_io
|
27
35
|
File.open(html_file) do |io|
|
28
36
|
xp = XML::HTMLParser.io(io)
|
29
37
|
assert_instance_of(XML::HTMLParser, xp)
|
30
|
-
|
38
|
+
|
31
39
|
doc = xp.parse
|
32
40
|
assert_instance_of(XML::Document, doc)
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
44
|
+
def test_io_gc
|
45
|
+
# Test that the reader keeps a reference
|
46
|
+
# to the io object
|
47
|
+
file = File.open(html_file)
|
48
|
+
parser = XML::HTMLParser.io(file)
|
49
|
+
file = nil
|
50
|
+
GC.start
|
51
|
+
assert(parser.parse)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_nil_io
|
55
|
+
error = assert_raise(TypeError) do
|
56
|
+
XML::HTMLParser.io(nil)
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_equal("Must pass in an IO object", error.to_s)
|
60
|
+
end
|
61
|
+
|
36
62
|
def test_string_io
|
37
63
|
data = File.read(html_file)
|
38
64
|
io = StringIO.new(data)
|
@@ -43,6 +69,25 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
43
69
|
assert_instance_of(XML::Document, doc)
|
44
70
|
end
|
45
71
|
|
72
|
+
def test_string
|
73
|
+
str = '<html><body><p>hi</p></body></html>'
|
74
|
+
xp = XML::HTMLParser.string(str)
|
75
|
+
|
76
|
+
assert_instance_of(XML::HTMLParser, xp)
|
77
|
+
assert_instance_of(XML::HTMLParser, xp)
|
78
|
+
|
79
|
+
doc = xp.parse
|
80
|
+
assert_instance_of(XML::Document, doc)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_nil_string
|
84
|
+
error = assert_raise(TypeError) do
|
85
|
+
XML::HTMLParser.string(nil)
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
89
|
+
end
|
90
|
+
|
46
91
|
def test_parse
|
47
92
|
html = <<-EOS
|
48
93
|
<html>
|
@@ -90,4 +135,4 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
90
135
|
assert_instance_of XML::Node, world
|
91
136
|
assert_equal 'World', world.content
|
92
137
|
end
|
93
|
-
end
|
138
|
+
end
|
data/test/tc_node.rb
CHANGED
@@ -23,10 +23,18 @@ class TestNode < Test::Unit::TestCase
|
|
23
23
|
assert_instance_of(XML::Document, @doc)
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_doc_node_type
|
27
|
+
assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type
|
28
|
+
end
|
29
|
+
|
26
30
|
def test_root_class
|
27
31
|
assert_instance_of(XML::Node, @doc.root)
|
28
32
|
end
|
29
33
|
|
34
|
+
def test_root_node_type
|
35
|
+
assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type
|
36
|
+
end
|
37
|
+
|
30
38
|
def test_node_class
|
31
39
|
for n in nodes
|
32
40
|
assert_instance_of(XML::Node, n)
|
@@ -112,4 +120,62 @@ class TestNode < Test::Unit::TestCase
|
|
112
120
|
doc = XML::Parser.string('<person />').parse
|
113
121
|
assert_nil(doc.root.base)
|
114
122
|
end
|
115
|
-
|
123
|
+
|
124
|
+
# We use the same facility that libXSLT does here to disable output escaping.
|
125
|
+
# This lets you specify that the node's content should be rendered unaltered
|
126
|
+
# whenever it is being output. This is useful for things like <script> and
|
127
|
+
# <style> nodes in HTML documents if you don't want to be forced to wrap them
|
128
|
+
# in CDATA nodes. Or if you are sanitizing existing HTML documents and want
|
129
|
+
# to preserve the content of any of the text nodes.
|
130
|
+
#
|
131
|
+
def test_output_escaping
|
132
|
+
text = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
133
|
+
node = XML::Parser.string(text).parse.root
|
134
|
+
assert_equal text, node.to_s
|
135
|
+
|
136
|
+
text_noenc = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
137
|
+
node.output_escaping = false
|
138
|
+
assert_equal text_noenc, node.to_s
|
139
|
+
|
140
|
+
node.output_escaping = true
|
141
|
+
assert_equal text, node.to_s
|
142
|
+
|
143
|
+
node.output_escaping = nil
|
144
|
+
assert_equal text_noenc, node.to_s
|
145
|
+
|
146
|
+
node.output_escaping = true
|
147
|
+
assert_equal text, node.to_s
|
148
|
+
end
|
149
|
+
|
150
|
+
# Just a sanity check for output escaping.
|
151
|
+
def test_output_escaping_sanity
|
152
|
+
text = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
153
|
+
node = XML::Parser.string(text).parse.root
|
154
|
+
affected = node.find('//text()')
|
155
|
+
|
156
|
+
check_escaping = lambda do |flag|
|
157
|
+
assert_equal('bad-script', node.name)
|
158
|
+
assert_equal(flag, node.output_escaping?)
|
159
|
+
affected.each do |x|
|
160
|
+
assert_equal(flag ? 'text' : 'textnoenc', x.name)
|
161
|
+
assert_equal(flag, x.output_escaping?)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
node.output_escaping = false
|
166
|
+
check_escaping[false]
|
167
|
+
|
168
|
+
node.output_escaping = true
|
169
|
+
check_escaping[true]
|
170
|
+
|
171
|
+
node.output_escaping = nil
|
172
|
+
check_escaping[false]
|
173
|
+
|
174
|
+
node.output_escaping = true
|
175
|
+
check_escaping[true]
|
176
|
+
|
177
|
+
affected.first.output_escaping = true
|
178
|
+
affected.last.output_escaping = false
|
179
|
+
assert node.output_escaping?.nil?
|
180
|
+
end
|
181
|
+
end
|
data/test/tc_node_edit.rb
CHANGED
@@ -58,13 +58,33 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
58
58
|
assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
59
59
|
@doc.root.to_s.gsub(/\n\s*/,'')
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_remove_node
|
63
63
|
first_node.remove!
|
64
64
|
assert_equal('<test><num>two</num><num>three</num></test>',
|
65
65
|
@doc.root.to_s.gsub(/\n\s*/,''))
|
66
66
|
end
|
67
67
|
|
68
|
+
def test_remove_node_gc
|
69
|
+
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
70
|
+
doc = xp.parse
|
71
|
+
node = doc.root.child.remove!
|
72
|
+
node = nil
|
73
|
+
GC.start
|
74
|
+
assert_not_nil(doc)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_remove_node_iteration
|
78
|
+
nodes = Array.new
|
79
|
+
@doc.root.each_element do |node|
|
80
|
+
if node.name == 'num'
|
81
|
+
nodes << node
|
82
|
+
node.remove!
|
83
|
+
end
|
84
|
+
end
|
85
|
+
assert_equal(3, nodes.length)
|
86
|
+
end
|
87
|
+
|
68
88
|
def test_reuse_removed_node
|
69
89
|
# Remove the node
|
70
90
|
node = @doc.root.first.remove!
|
@@ -77,7 +97,7 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
77
97
|
@doc.root.to_s.gsub(/\n\s*/,''))
|
78
98
|
end
|
79
99
|
|
80
|
-
# This test is to verify that an earlier reported bug has been fixed
|
100
|
+
# This test is to verify that an earlier reported bug has been fixed
|
81
101
|
def test_merge
|
82
102
|
documents = []
|
83
103
|
|
@@ -90,16 +110,16 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
90
110
|
documents.inject(master_doc) do |master_doc, child_doc|
|
91
111
|
master_body = master_doc.find("//body").first
|
92
112
|
child_body = child_doc.find("//body").first
|
93
|
-
|
113
|
+
|
94
114
|
child_element = child_body.detect do |node|
|
95
115
|
node.element?
|
96
116
|
end
|
97
|
-
|
117
|
+
|
98
118
|
master_body << child_element.copy(true)
|
99
119
|
master_doc
|
100
120
|
end
|
101
121
|
end
|
102
|
-
|
122
|
+
|
103
123
|
def test_append_chain
|
104
124
|
node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
|
105
125
|
assert_equal('<foo><bar/>bars contents</foo>',
|
@@ -111,4 +131,4 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
111
131
|
assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
|
112
132
|
@doc.root.to_s)
|
113
133
|
end
|
114
|
-
end
|
134
|
+
end
|
data/test/tc_node_text.rb
CHANGED
@@ -15,23 +15,6 @@ class TestTextNode < Test::Unit::TestCase
|
|
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
18
|
# We use the same facility that libXSLT does here to disable output escaping.
|
36
19
|
# This lets you specify that the node's content should be rendered unaltered
|
37
20
|
# whenever it is being output. This is useful for things like <script> and
|
@@ -40,12 +23,47 @@ class TestTextNode < Test::Unit::TestCase
|
|
40
23
|
# to preserve the content of any of the text nodes.
|
41
24
|
#
|
42
25
|
def test_output_escaping
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
assert_equal
|
26
|
+
textnoenc = 'if (a < b || c > d) return "e";'
|
27
|
+
text = "if (a < b || c > d) return \"e\";"
|
28
|
+
|
29
|
+
node = XML::Node.new_text(textnoenc)
|
30
|
+
assert node.output_escaping?
|
31
|
+
assert_equal text, node.to_s
|
32
|
+
|
33
|
+
node.output_escaping = false
|
34
|
+
assert_equal textnoenc, node.to_s
|
35
|
+
|
36
|
+
node.output_escaping = true
|
37
|
+
assert_equal text, node.to_s
|
38
|
+
|
39
|
+
node.output_escaping = nil
|
40
|
+
assert_equal textnoenc, node.to_s
|
41
|
+
|
42
|
+
node.output_escaping = true
|
43
|
+
assert_equal text, node.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
# Just a sanity check for output escaping.
|
47
|
+
def test_output_escaping_sanity
|
48
|
+
node = XML::Node.new_text('testdata')
|
49
|
+
assert_equal 'text', node.name
|
50
|
+
assert node.output_escaping?
|
51
|
+
|
52
|
+
node.output_escaping = false
|
53
|
+
assert_equal 'textnoenc', node.name
|
54
|
+
assert ! node.output_escaping?
|
55
|
+
|
56
|
+
node.output_escaping = true
|
57
|
+
assert_equal 'text', node.name
|
58
|
+
assert node.output_escaping?
|
59
|
+
|
60
|
+
node.output_escaping = nil
|
61
|
+
assert_equal 'textnoenc', node.name
|
62
|
+
assert ! node.output_escaping?
|
63
|
+
|
64
|
+
node.output_escaping = true
|
65
|
+
assert_equal 'text', node.name
|
66
|
+
assert node.output_escaping?
|
49
67
|
end
|
50
68
|
|
51
69
|
end
|
data/test/tc_parser.rb
CHANGED
@@ -27,6 +27,14 @@ class TestParser < Test::Unit::TestCase
|
|
27
27
|
assert_instance_of(XML::Parser::Context, parser.context)
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_nil_document
|
31
|
+
error = assert_raise(TypeError) do
|
32
|
+
XML::Parser.document(nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_equal("Must pass an XML::Document object", error.to_s)
|
36
|
+
end
|
37
|
+
|
30
38
|
def test_file
|
31
39
|
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
32
40
|
|
@@ -36,6 +44,22 @@ class TestParser < Test::Unit::TestCase
|
|
36
44
|
assert_instance_of(XML::Parser::Context, parser.context)
|
37
45
|
end
|
38
46
|
|
47
|
+
def test_noexistent_file
|
48
|
+
error = assert_raise(XML::Error) do
|
49
|
+
XML::Parser.file('i_dont_exist.xml')
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_nil_file
|
56
|
+
error = assert_raise(TypeError) do
|
57
|
+
XML::Parser.file(nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_equal("can't convert nil into String", error.to_s)
|
61
|
+
end
|
62
|
+
|
39
63
|
def test_file_encoding
|
40
64
|
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
41
65
|
parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
|
@@ -74,6 +98,24 @@ class TestParser < Test::Unit::TestCase
|
|
74
98
|
end
|
75
99
|
end
|
76
100
|
|
101
|
+
def test_io_gc
|
102
|
+
# Test that the reader keeps a reference
|
103
|
+
# to the io object
|
104
|
+
file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
105
|
+
parser = XML::Parser.io(file)
|
106
|
+
file = nil
|
107
|
+
GC.start
|
108
|
+
assert(parser.parse)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_nil_io
|
112
|
+
error = assert_raise(TypeError) do
|
113
|
+
XML::Parser.io(nil)
|
114
|
+
end
|
115
|
+
|
116
|
+
assert_equal("Must pass in an IO object", error.to_s)
|
117
|
+
end
|
118
|
+
|
77
119
|
def test_string_io
|
78
120
|
data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
79
121
|
string_io = StringIO.new(data)
|
@@ -95,6 +137,14 @@ class TestParser < Test::Unit::TestCase
|
|
95
137
|
assert_instance_of(XML::Parser::Context, parser.context)
|
96
138
|
end
|
97
139
|
|
140
|
+
def test_nil_string
|
141
|
+
error = assert_raise(TypeError) do
|
142
|
+
XML::Parser.string(nil)
|
143
|
+
end
|
144
|
+
|
145
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
146
|
+
end
|
147
|
+
|
98
148
|
def test_string_options
|
99
149
|
xml = <<-EOS
|
100
150
|
<!DOCTYPE foo [<!ENTITY foo 'bar'>]>
|