libxml-ruby 1.1.3-x86-mswin32-60 → 1.1.4-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +1 -1
- data/LICENSE +22 -22
- data/README +160 -160
- data/Rakefile +0 -9
- data/ext/libxml/Makefile +156 -0
- data/ext/libxml/extconf.h +5 -0
- data/ext/libxml/extconf.rb +4 -160
- data/ext/libxml/libxml-ruby.so.a +0 -0
- data/ext/libxml/libxml.o +0 -0
- data/ext/libxml/libxml_ruby.so +0 -0
- data/ext/libxml/mkmf.log +129 -0
- data/ext/libxml/ruby_xml.o +0 -0
- data/ext/libxml/ruby_xml_attr.c +1 -1
- data/ext/libxml/ruby_xml_attr.h +1 -1
- data/ext/libxml/ruby_xml_attr.o +0 -0
- data/ext/libxml/ruby_xml_attr_decl.o +0 -0
- data/ext/libxml/ruby_xml_attributes.o +0 -0
- data/ext/libxml/ruby_xml_cbg.o +0 -0
- data/ext/libxml/ruby_xml_document.c +936 -936
- data/ext/libxml/ruby_xml_document.h +1 -1
- data/ext/libxml/ruby_xml_document.o +0 -0
- data/ext/libxml/ruby_xml_dtd.o +0 -0
- data/ext/libxml/ruby_xml_encoding.o +0 -0
- data/ext/libxml/ruby_xml_error.o +0 -0
- data/ext/libxml/ruby_xml_html_parser.c +1 -1
- data/ext/libxml/ruby_xml_html_parser.h +1 -1
- data/ext/libxml/ruby_xml_html_parser.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_input_cbg.o +0 -0
- data/ext/libxml/ruby_xml_io.o +0 -0
- data/ext/libxml/ruby_xml_namespace.c +1 -1
- data/ext/libxml/ruby_xml_namespace.h +1 -1
- data/ext/libxml/ruby_xml_namespace.o +0 -0
- data/ext/libxml/ruby_xml_namespaces.o +0 -0
- data/ext/libxml/ruby_xml_node.c +1386 -1386
- data/ext/libxml/ruby_xml_node.h +1 -1
- data/ext/libxml/ruby_xml_node.o +0 -0
- data/ext/libxml/ruby_xml_parser.c +1 -1
- data/ext/libxml/ruby_xml_parser.h +1 -1
- data/ext/libxml/ruby_xml_parser.o +0 -0
- data/ext/libxml/ruby_xml_parser_context.c +1 -1
- data/ext/libxml/ruby_xml_parser_context.h +1 -1
- data/ext/libxml/ruby_xml_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_reader.o +0 -0
- data/ext/libxml/ruby_xml_relaxng.o +0 -0
- data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
- data/ext/libxml/ruby_xml_sax_parser.c +1 -1
- data/ext/libxml/ruby_xml_sax_parser.h +1 -1
- data/ext/libxml/ruby_xml_sax_parser.o +0 -0
- data/ext/libxml/ruby_xml_schema.o +0 -0
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_xinclude.c +1 -1
- data/ext/libxml/ruby_xml_xinclude.h +1 -1
- data/ext/libxml/ruby_xml_xinclude.o +0 -0
- data/ext/libxml/ruby_xml_xpath.c +1 -1
- data/ext/libxml/ruby_xml_xpath.h +1 -1
- data/ext/libxml/ruby_xml_xpath.o +0 -0
- data/ext/libxml/ruby_xml_xpath_context.c +1 -1
- data/ext/libxml/ruby_xml_xpath_context.h +1 -1
- data/ext/libxml/ruby_xml_xpath_context.o +0 -0
- data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
- data/ext/libxml/ruby_xml_xpath_object.o +0 -0
- data/ext/libxml/ruby_xml_xpointer.c +1 -1
- data/ext/libxml/ruby_xml_xpointer.h +1 -1
- data/ext/libxml/ruby_xml_xpointer.o +0 -0
- data/ext/mingw/build.rake +3 -3
- data/ext/mingw/libiconv-2.dll +0 -0
- data/ext/mingw/libxml2-2.dll +0 -0
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/lib/libxml.rb +29 -29
- data/test/model/merge_bug_data.xml +58 -58
- data/test/model/rubynet.xml +79 -79
- data/test/model/xinclude.xml +4 -4
- data/test/tc_attr.rb +170 -170
- data/test/tc_document.rb +113 -113
- data/test/tc_document_write.rb +117 -117
- data/test/tc_dtd.rb +123 -123
- data/test/tc_html_parser.rb +137 -137
- data/test/tc_node.rb +180 -180
- data/test/tc_node_cdata.rb +49 -49
- data/test/tc_node_comment.rb +30 -30
- data/test/tc_node_edit.rb +157 -157
- data/test/tc_node_xlink.rb +26 -26
- data/test/tc_parser.rb +329 -329
- data/test/tc_parser_context.rb +185 -185
- data/test/tc_reader.rb +283 -283
- data/test/tc_sax_parser.rb +273 -273
- data/test/tc_schema.rb +51 -51
- data/test/tc_xinclude.rb +19 -19
- data/test/tc_xpath.rb +193 -193
- data/test/tc_xpointer.rb +72 -72
- metadata +55 -14
- data/ext/libxml/build.log +0 -4
data/test/tc_html_parser.rb
CHANGED
@@ -1,138 +1,138 @@
|
|
1
|
-
require 'xml'
|
2
|
-
require 'stringio'
|
3
|
-
require 'test/unit'
|
4
|
-
|
5
|
-
class HTMLParserTest < Test::Unit::TestCase
|
6
|
-
def html_file
|
7
|
-
File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
|
8
|
-
end
|
9
|
-
|
10
|
-
# ----- Sources ------
|
11
|
-
def test_file
|
12
|
-
xp = XML::HTMLParser.file(html_file)
|
13
|
-
assert_instance_of(XML::HTMLParser, xp)
|
14
|
-
doc = xp.parse
|
15
|
-
assert_not_nil(doc)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_noexistent_file
|
19
|
-
error = assert_raise(XML::Error) do
|
20
|
-
XML::HTMLParser.file('i_dont_exist.xml')
|
21
|
-
end
|
22
|
-
|
23
|
-
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
24
|
-
end
|
25
|
-
|
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)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_io
|
35
|
-
File.open(html_file) do |io|
|
36
|
-
xp = XML::HTMLParser.io(io)
|
37
|
-
assert_instance_of(XML::HTMLParser, xp)
|
38
|
-
|
39
|
-
doc = xp.parse
|
40
|
-
assert_instance_of(XML::Document, doc)
|
41
|
-
end
|
42
|
-
end
|
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
|
-
|
62
|
-
def test_string_io
|
63
|
-
data = File.read(html_file)
|
64
|
-
io = StringIO.new(data)
|
65
|
-
xp = XML::HTMLParser.io(io)
|
66
|
-
assert_instance_of(XML::HTMLParser, xp)
|
67
|
-
|
68
|
-
doc = xp.parse
|
69
|
-
assert_instance_of(XML::Document, doc)
|
70
|
-
end
|
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
|
-
|
91
|
-
def test_parse
|
92
|
-
html = <<-EOS
|
93
|
-
<html>
|
94
|
-
<head>
|
95
|
-
<meta name=keywords content=nasty>
|
96
|
-
</head>
|
97
|
-
<body>Hello<br>World</html>
|
98
|
-
EOS
|
99
|
-
|
100
|
-
parser = XML::HTMLParser.string(html)
|
101
|
-
doc = parser.parse
|
102
|
-
assert_instance_of XML::Document, doc
|
103
|
-
|
104
|
-
root = doc.root
|
105
|
-
assert_instance_of XML::Node, root
|
106
|
-
assert_equal 'html', root.name
|
107
|
-
|
108
|
-
head = root.child
|
109
|
-
assert_instance_of XML::Node, head
|
110
|
-
assert_equal 'head', head.name
|
111
|
-
|
112
|
-
meta = head.child
|
113
|
-
assert_instance_of XML::Node, meta
|
114
|
-
assert_equal 'meta', meta.name
|
115
|
-
assert_equal 'keywords', meta[:name]
|
116
|
-
assert_equal 'nasty', meta[:content]
|
117
|
-
|
118
|
-
body = head.next
|
119
|
-
assert_instance_of XML::Node, body
|
120
|
-
assert_equal 'body', body.name
|
121
|
-
|
122
|
-
hello = body.child
|
123
|
-
# It appears that some versions of libxml2 add a layer of <p>
|
124
|
-
# cant figure our why or how, so this skips it if there
|
125
|
-
hello = hello.child if hello.name == "p"
|
126
|
-
|
127
|
-
assert_instance_of XML::Node, hello
|
128
|
-
assert_equal 'Hello', hello.content
|
129
|
-
|
130
|
-
br = hello.next
|
131
|
-
assert_instance_of XML::Node, br
|
132
|
-
assert_equal 'br', br.name
|
133
|
-
|
134
|
-
world = br.next
|
135
|
-
assert_instance_of XML::Node, world
|
136
|
-
assert_equal 'World', world.content
|
137
|
-
end
|
1
|
+
require 'xml'
|
2
|
+
require 'stringio'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class HTMLParserTest < Test::Unit::TestCase
|
6
|
+
def html_file
|
7
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
|
8
|
+
end
|
9
|
+
|
10
|
+
# ----- Sources ------
|
11
|
+
def test_file
|
12
|
+
xp = XML::HTMLParser.file(html_file)
|
13
|
+
assert_instance_of(XML::HTMLParser, xp)
|
14
|
+
doc = xp.parse
|
15
|
+
assert_not_nil(doc)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_noexistent_file
|
19
|
+
error = assert_raise(XML::Error) do
|
20
|
+
XML::HTMLParser.file('i_dont_exist.xml')
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
24
|
+
end
|
25
|
+
|
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)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_io
|
35
|
+
File.open(html_file) do |io|
|
36
|
+
xp = XML::HTMLParser.io(io)
|
37
|
+
assert_instance_of(XML::HTMLParser, xp)
|
38
|
+
|
39
|
+
doc = xp.parse
|
40
|
+
assert_instance_of(XML::Document, doc)
|
41
|
+
end
|
42
|
+
end
|
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
|
+
|
62
|
+
def test_string_io
|
63
|
+
data = File.read(html_file)
|
64
|
+
io = StringIO.new(data)
|
65
|
+
xp = XML::HTMLParser.io(io)
|
66
|
+
assert_instance_of(XML::HTMLParser, xp)
|
67
|
+
|
68
|
+
doc = xp.parse
|
69
|
+
assert_instance_of(XML::Document, doc)
|
70
|
+
end
|
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
|
+
|
91
|
+
def test_parse
|
92
|
+
html = <<-EOS
|
93
|
+
<html>
|
94
|
+
<head>
|
95
|
+
<meta name=keywords content=nasty>
|
96
|
+
</head>
|
97
|
+
<body>Hello<br>World</html>
|
98
|
+
EOS
|
99
|
+
|
100
|
+
parser = XML::HTMLParser.string(html)
|
101
|
+
doc = parser.parse
|
102
|
+
assert_instance_of XML::Document, doc
|
103
|
+
|
104
|
+
root = doc.root
|
105
|
+
assert_instance_of XML::Node, root
|
106
|
+
assert_equal 'html', root.name
|
107
|
+
|
108
|
+
head = root.child
|
109
|
+
assert_instance_of XML::Node, head
|
110
|
+
assert_equal 'head', head.name
|
111
|
+
|
112
|
+
meta = head.child
|
113
|
+
assert_instance_of XML::Node, meta
|
114
|
+
assert_equal 'meta', meta.name
|
115
|
+
assert_equal 'keywords', meta[:name]
|
116
|
+
assert_equal 'nasty', meta[:content]
|
117
|
+
|
118
|
+
body = head.next
|
119
|
+
assert_instance_of XML::Node, body
|
120
|
+
assert_equal 'body', body.name
|
121
|
+
|
122
|
+
hello = body.child
|
123
|
+
# It appears that some versions of libxml2 add a layer of <p>
|
124
|
+
# cant figure our why or how, so this skips it if there
|
125
|
+
hello = hello.child if hello.name == "p"
|
126
|
+
|
127
|
+
assert_instance_of XML::Node, hello
|
128
|
+
assert_equal 'Hello', hello.content
|
129
|
+
|
130
|
+
br = hello.next
|
131
|
+
assert_instance_of XML::Node, br
|
132
|
+
assert_equal 'br', br.name
|
133
|
+
|
134
|
+
world = br.next
|
135
|
+
assert_instance_of XML::Node, world
|
136
|
+
assert_equal 'World', world.content
|
137
|
+
end
|
138
138
|
end
|
data/test/tc_node.rb
CHANGED
@@ -1,181 +1,181 @@
|
|
1
|
-
require 'xml'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TestNode < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
# Strip spaces to make testing easier
|
7
|
-
XML.default_keep_blanks = false
|
8
|
-
file = File.join(File.dirname(__FILE__), 'model/bands.xml')
|
9
|
-
@doc = XML::Document.file(file)
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
XML.default_keep_blanks = true
|
14
|
-
@doc = nil
|
15
|
-
end
|
16
|
-
|
17
|
-
def nodes
|
18
|
-
# Find all nodes with a country attributes
|
19
|
-
@doc.find('*[@country]')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_doc_class
|
23
|
-
assert_instance_of(XML::Document, @doc)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_doc_node_type
|
27
|
-
assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_root_class
|
31
|
-
assert_instance_of(XML::Node, @doc.root)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_root_node_type
|
35
|
-
assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_node_class
|
39
|
-
for n in nodes
|
40
|
-
assert_instance_of(XML::Node, n)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_context
|
45
|
-
node = @doc.root
|
46
|
-
context = node.context
|
47
|
-
assert_instance_of(XML::XPath::Context, context)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_find
|
51
|
-
assert_instance_of(XML::XPath::Object, self.nodes)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_node_child_get
|
55
|
-
assert_instance_of(TrueClass, @doc.root.child?)
|
56
|
-
assert_instance_of(XML::Node, @doc.root.child)
|
57
|
-
assert_equal("m\303\266tley_cr\303\274e", @doc.root.child.name)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_node_doc
|
61
|
-
for n in nodes
|
62
|
-
assert_instance_of(XML::Document, n.doc) if n.document?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_name
|
67
|
-
assert_equal("m\303\266tley_cr\303\274e", nodes[0].name)
|
68
|
-
assert_equal("iron_maiden", nodes[1].name)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_node_find
|
72
|
-
nodes = @doc.root.find('./fixnum')
|
73
|
-
for node in nodes
|
74
|
-
assert_instance_of(XML::Node, node)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_equality
|
79
|
-
node_a = @doc.find_first('*[@country]')
|
80
|
-
node_b = @doc.root.child
|
81
|
-
|
82
|
-
assert(node_a == node_b)
|
83
|
-
assert(node_a.eql?(node_b))
|
84
|
-
assert(node_a.equal?(node_b))
|
85
|
-
|
86
|
-
file = File.join(File.dirname(__FILE__), 'model/bands.xml')
|
87
|
-
doc2 = XML::Document.file(file)
|
88
|
-
|
89
|
-
node_a2 = doc2.find_first('*[@country]')
|
90
|
-
|
91
|
-
assert(node_a.to_s == node_a2.to_s)
|
92
|
-
assert(node_a == node_a2)
|
93
|
-
assert(node_a.eql?(node_a2))
|
94
|
-
assert(!node_a.equal?(node_a2))
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_equality_nil
|
98
|
-
node = @doc.root
|
99
|
-
assert(node != nil)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_equality_wrong_type
|
103
|
-
node = @doc.root
|
104
|
-
|
105
|
-
assert_raises(TypeError) do
|
106
|
-
assert(node != 'abc')
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_content
|
111
|
-
assert_equal("An American heavy metal band formed in Los Angeles, California in 1981.British heavy metal band formed in 1975.",
|
112
|
-
@doc.root.content)
|
113
|
-
|
114
|
-
first = @doc.root.child
|
115
|
-
assert_equal('An American heavy metal band formed in Los Angeles, California in 1981.', first.content)
|
116
|
-
assert_equal('British heavy metal band formed in 1975.', first.next.content)
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_base
|
120
|
-
doc = XML::Parser.string('<person />').parse
|
121
|
-
assert_nil(doc.root.base)
|
122
|
-
end
|
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
|
1
|
+
require 'xml'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestNode < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
# Strip spaces to make testing easier
|
7
|
+
XML.default_keep_blanks = false
|
8
|
+
file = File.join(File.dirname(__FILE__), 'model/bands.xml')
|
9
|
+
@doc = XML::Document.file(file)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
XML.default_keep_blanks = true
|
14
|
+
@doc = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def nodes
|
18
|
+
# Find all nodes with a country attributes
|
19
|
+
@doc.find('*[@country]')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_doc_class
|
23
|
+
assert_instance_of(XML::Document, @doc)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_doc_node_type
|
27
|
+
assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_root_class
|
31
|
+
assert_instance_of(XML::Node, @doc.root)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_root_node_type
|
35
|
+
assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_node_class
|
39
|
+
for n in nodes
|
40
|
+
assert_instance_of(XML::Node, n)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_context
|
45
|
+
node = @doc.root
|
46
|
+
context = node.context
|
47
|
+
assert_instance_of(XML::XPath::Context, context)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_find
|
51
|
+
assert_instance_of(XML::XPath::Object, self.nodes)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_node_child_get
|
55
|
+
assert_instance_of(TrueClass, @doc.root.child?)
|
56
|
+
assert_instance_of(XML::Node, @doc.root.child)
|
57
|
+
assert_equal("m\303\266tley_cr\303\274e", @doc.root.child.name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_node_doc
|
61
|
+
for n in nodes
|
62
|
+
assert_instance_of(XML::Document, n.doc) if n.document?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_name
|
67
|
+
assert_equal("m\303\266tley_cr\303\274e", nodes[0].name)
|
68
|
+
assert_equal("iron_maiden", nodes[1].name)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_node_find
|
72
|
+
nodes = @doc.root.find('./fixnum')
|
73
|
+
for node in nodes
|
74
|
+
assert_instance_of(XML::Node, node)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_equality
|
79
|
+
node_a = @doc.find_first('*[@country]')
|
80
|
+
node_b = @doc.root.child
|
81
|
+
|
82
|
+
assert(node_a == node_b)
|
83
|
+
assert(node_a.eql?(node_b))
|
84
|
+
assert(node_a.equal?(node_b))
|
85
|
+
|
86
|
+
file = File.join(File.dirname(__FILE__), 'model/bands.xml')
|
87
|
+
doc2 = XML::Document.file(file)
|
88
|
+
|
89
|
+
node_a2 = doc2.find_first('*[@country]')
|
90
|
+
|
91
|
+
assert(node_a.to_s == node_a2.to_s)
|
92
|
+
assert(node_a == node_a2)
|
93
|
+
assert(node_a.eql?(node_a2))
|
94
|
+
assert(!node_a.equal?(node_a2))
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_equality_nil
|
98
|
+
node = @doc.root
|
99
|
+
assert(node != nil)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_equality_wrong_type
|
103
|
+
node = @doc.root
|
104
|
+
|
105
|
+
assert_raises(TypeError) do
|
106
|
+
assert(node != 'abc')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_content
|
111
|
+
assert_equal("An American heavy metal band formed in Los Angeles, California in 1981.British heavy metal band formed in 1975.",
|
112
|
+
@doc.root.content)
|
113
|
+
|
114
|
+
first = @doc.root.child
|
115
|
+
assert_equal('An American heavy metal band formed in Los Angeles, California in 1981.', first.content)
|
116
|
+
assert_equal('British heavy metal band formed in 1975.', first.next.content)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_base
|
120
|
+
doc = XML::Parser.string('<person />').parse
|
121
|
+
assert_nil(doc.root.base)
|
122
|
+
end
|
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
181
|
end
|