nokogiri 1.0.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data/History.txt +6 -0
- data/Manifest.txt +120 -0
- data/README.ja.txt +86 -0
- data/README.txt +87 -0
- data/Rakefile +264 -0
- data/ext/nokogiri/extconf.rb +59 -0
- data/ext/nokogiri/html_document.c +83 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_sax_parser.c +32 -0
- data/ext/nokogiri/html_sax_parser.h +11 -0
- data/ext/nokogiri/iconv.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/native.c +40 -0
- data/ext/nokogiri/native.h +51 -0
- data/ext/nokogiri/native.so +0 -0
- data/ext/nokogiri/xml_cdata.c +52 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_document.c +159 -0
- data/ext/nokogiri/xml_document.h +10 -0
- data/ext/nokogiri/xml_dtd.c +117 -0
- data/ext/nokogiri/xml_dtd.h +8 -0
- data/ext/nokogiri/xml_node.c +709 -0
- data/ext/nokogiri/xml_node.h +15 -0
- data/ext/nokogiri/xml_node_set.c +124 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_reader.c +429 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_sax_parser.c +174 -0
- data/ext/nokogiri/xml_sax_parser.h +10 -0
- data/ext/nokogiri/xml_syntax_error.c +194 -0
- data/ext/nokogiri/xml_syntax_error.h +11 -0
- data/ext/nokogiri/xml_text.c +29 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +46 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +81 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +108 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/nokogiri.rb +51 -0
- data/lib/nokogiri/css.rb +6 -0
- data/lib/nokogiri/css/generated_parser.rb +653 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +159 -0
- data/lib/nokogiri/css/node.rb +95 -0
- data/lib/nokogiri/css/parser.rb +24 -0
- data/lib/nokogiri/css/parser.y +198 -0
- data/lib/nokogiri/css/tokenizer.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rex +63 -0
- data/lib/nokogiri/css/xpath_visitor.rb +165 -0
- data/lib/nokogiri/decorators.rb +1 -0
- data/lib/nokogiri/decorators/hpricot.rb +3 -0
- data/lib/nokogiri/decorators/hpricot/node.rb +58 -0
- data/lib/nokogiri/decorators/hpricot/node_set.rb +14 -0
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +17 -0
- data/lib/nokogiri/hpricot.rb +47 -0
- data/lib/nokogiri/html.rb +95 -0
- data/lib/nokogiri/html/builder.rb +9 -0
- data/lib/nokogiri/html/document.rb +9 -0
- data/lib/nokogiri/html/sax/parser.rb +21 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/xml.rb +67 -0
- data/lib/nokogiri/xml/after_handler.rb +18 -0
- data/lib/nokogiri/xml/before_handler.rb +32 -0
- data/lib/nokogiri/xml/builder.rb +79 -0
- data/lib/nokogiri/xml/cdata.rb +9 -0
- data/lib/nokogiri/xml/document.rb +30 -0
- data/lib/nokogiri/xml/dtd.rb +6 -0
- data/lib/nokogiri/xml/element.rb +6 -0
- data/lib/nokogiri/xml/entity_declaration.rb +9 -0
- data/lib/nokogiri/xml/node.rb +195 -0
- data/lib/nokogiri/xml/node_set.rb +183 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +14 -0
- data/lib/nokogiri/xml/sax.rb +9 -0
- data/lib/nokogiri/xml/sax/document.rb +59 -0
- data/lib/nokogiri/xml/sax/parser.rb +33 -0
- data/lib/nokogiri/xml/syntax_error.rb +21 -0
- data/lib/nokogiri/xml/text.rb +6 -0
- data/lib/nokogiri/xml/xpath.rb +6 -0
- data/lib/nokogiri/xml/xpath_context.rb +14 -0
- data/lib/nokogiri/xslt.rb +11 -0
- data/lib/nokogiri/xslt/stylesheet.rb +6 -0
- data/nokogiri.gemspec +34 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +224 -0
- data/test/css/test_tokenizer.rb +162 -0
- data/test/css/test_xpath_visitor.rb +54 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/helper.rb +70 -0
- data/test/hpricot/files/basic.xhtml +17 -0
- data/test/hpricot/files/boingboing.html +2266 -0
- data/test/hpricot/files/cy0.html +3653 -0
- data/test/hpricot/files/immob.html +400 -0
- data/test/hpricot/files/pace_application.html +1320 -0
- data/test/hpricot/files/tenderlove.html +16 -0
- data/test/hpricot/files/uswebgen.html +220 -0
- data/test/hpricot/files/utf8.html +1054 -0
- data/test/hpricot/files/week9.html +1723 -0
- data/test/hpricot/files/why.xml +19 -0
- data/test/hpricot/load_files.rb +7 -0
- data/test/hpricot/test_alter.rb +67 -0
- data/test/hpricot/test_builder.rb +27 -0
- data/test/hpricot/test_parser.rb +423 -0
- data/test/hpricot/test_paths.rb +15 -0
- data/test/hpricot/test_preserved.rb +78 -0
- data/test/hpricot/test_xml.rb +30 -0
- data/test/html/sax/test_parser.rb +27 -0
- data/test/html/test_builder.rb +78 -0
- data/test/html/test_document.rb +86 -0
- data/test/test_convert_xpath.rb +180 -0
- data/test/test_nokogiri.rb +36 -0
- data/test/test_reader.rb +222 -0
- data/test/test_xslt_transforms.rb +29 -0
- data/test/xml/sax/test_parser.rb +93 -0
- data/test/xml/test_builder.rb +16 -0
- data/test/xml/test_cdata.rb +18 -0
- data/test/xml/test_document.rb +171 -0
- data/test/xml/test_dtd.rb +43 -0
- data/test/xml/test_node.rb +223 -0
- data/test/xml/test_node_set.rb +116 -0
- data/test/xml/test_text.rb +13 -0
- metadata +217 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
|
+
|
3
|
+
class TestNokogiri < Nokogiri::TestCase
|
4
|
+
def test_xml?
|
5
|
+
doc = Nokogiri.parse(File.read(XML_FILE))
|
6
|
+
assert doc.xml?
|
7
|
+
assert !doc.html?
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_html?
|
11
|
+
doc = Nokogiri.parse(File.read(HTML_FILE))
|
12
|
+
assert !doc.xml?
|
13
|
+
assert doc.html?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_nokogiri_method_with_html
|
17
|
+
doc1 = Nokogiri(File.read(HTML_FILE))
|
18
|
+
doc2 = Nokogiri.parse(File.read(HTML_FILE))
|
19
|
+
assert_equal doc1.serialize, doc2.serialize
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_nokogiri_method_with_block
|
23
|
+
doc = Nokogiri { b "bold tag" }
|
24
|
+
assert_equal('<b>bold tag</b>', doc.to_html.chomp)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_make_with_html
|
28
|
+
doc = Nokogiri.make("<b>bold tag</b>")
|
29
|
+
assert_equal('<b>bold tag</b>', doc.to_html.chomp)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_make_with_block
|
33
|
+
doc = Nokogiri.make { b "bold tag" }
|
34
|
+
assert_equal('<b>bold tag</b>', doc.to_html.chomp)
|
35
|
+
end
|
36
|
+
end
|
data/test/test_reader.rb
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
3
|
+
|
4
|
+
class TestReader < Nokogiri::TestCase
|
5
|
+
def test_default?
|
6
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
7
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
8
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
9
|
+
</x>
|
10
|
+
eoxml
|
11
|
+
assert_equal false, reader.default?
|
12
|
+
assert_equal [false, false, false, false, false, false, false],
|
13
|
+
reader.map { |x| x.default? }
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_value?
|
17
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
18
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
19
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
20
|
+
</x>
|
21
|
+
eoxml
|
22
|
+
assert_equal false, reader.value?
|
23
|
+
assert_equal [false, true, false, true, false, true, false],
|
24
|
+
reader.map { |x| x.value? }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_attributes?
|
28
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
29
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
30
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
31
|
+
</x>
|
32
|
+
eoxml
|
33
|
+
assert_equal false, reader.attributes?
|
34
|
+
assert_equal [true, false, true, false, true, false, true],
|
35
|
+
reader.map { |x| x.attributes? }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_attributes
|
39
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
40
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
41
|
+
xmlns='http://mothership.connection.com/'
|
42
|
+
>
|
43
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
44
|
+
</x>
|
45
|
+
eoxml
|
46
|
+
assert_equal({}, reader.attributes)
|
47
|
+
assert_equal [{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
48
|
+
'xmlns'=>'http://mothership.connection.com/'},
|
49
|
+
{}, {"awesome"=>"true"}, {}, {"awesome"=>"true"}, {},
|
50
|
+
{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
51
|
+
'xmlns'=>'http://mothership.connection.com/'}],
|
52
|
+
reader.map { |x| x.attributes }
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_attribute_roundtrip
|
56
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
57
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
58
|
+
xmlns='http://mothership.connection.com/'
|
59
|
+
>
|
60
|
+
<tenderlove:foo awesome='true' size='giant'>snuggles!</tenderlove:foo>
|
61
|
+
</x>
|
62
|
+
eoxml
|
63
|
+
reader.each do |node|
|
64
|
+
node.attributes.each do |key, value|
|
65
|
+
assert_equal value, node.attribute(key)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_attribute_at
|
71
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
72
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
73
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
74
|
+
</x>
|
75
|
+
eoxml
|
76
|
+
assert_nil reader.attribute_at(nil)
|
77
|
+
assert_nil reader.attribute_at(0)
|
78
|
+
assert_equal ['http://tenderlovemaking.com/', nil, 'true', nil, 'true', nil, 'http://tenderlovemaking.com/'],
|
79
|
+
reader.map { |x| x.attribute_at(0) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_attribute
|
83
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
84
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
85
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
86
|
+
</x>
|
87
|
+
eoxml
|
88
|
+
assert_nil reader.attribute(nil)
|
89
|
+
assert_nil reader.attribute('awesome')
|
90
|
+
assert_equal [nil, nil, 'true', nil, 'true', nil, nil],
|
91
|
+
reader.map { |x| x.attribute('awesome') }
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_attribute_length
|
95
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
96
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
97
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
98
|
+
</x>
|
99
|
+
eoxml
|
100
|
+
assert_equal 0, reader.attribute_count
|
101
|
+
assert_equal [1, 0, 1, 0, 0, 0, 0], reader.map { |x| x.attribute_count }
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_depth
|
105
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
106
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
107
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
108
|
+
</x>
|
109
|
+
eoxml
|
110
|
+
assert_equal 0, reader.depth
|
111
|
+
assert_equal [0, 1, 1, 2, 1, 1, 0], reader.map { |x| x.depth }
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_encoding
|
115
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
116
|
+
<awesome>
|
117
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
118
|
+
<p xml:lang="ja">日本語が上手です</p>
|
119
|
+
</awesome>
|
120
|
+
eoxml
|
121
|
+
assert_nil reader.encoding
|
122
|
+
assert_equal [nil], reader.map { |x| x.encoding }.uniq
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_xml_version
|
126
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
127
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
128
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
129
|
+
</x>
|
130
|
+
eoxml
|
131
|
+
assert_nil reader.xml_version
|
132
|
+
assert_equal ['1.0'], reader.map { |x| x.xml_version }.uniq
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_lang
|
136
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
137
|
+
<awesome>
|
138
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
139
|
+
<p xml:lang="ja">日本語が上手です</p>
|
140
|
+
</awesome>
|
141
|
+
eoxml
|
142
|
+
assert_nil reader.lang
|
143
|
+
assert_equal [nil, nil, "en", "en", "en", nil, "ja", "ja", "ja", nil, nil],
|
144
|
+
reader.map { |x| x.lang }
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_value
|
148
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
149
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
150
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
151
|
+
</x>
|
152
|
+
eoxml
|
153
|
+
assert_nil reader.value
|
154
|
+
assert_equal [nil, "\n ", nil, "snuggles!", nil, "\n ", nil],
|
155
|
+
reader.map { |x| x.value }
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_prefix
|
159
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
160
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
161
|
+
<edi:foo>hello</edi:foo>
|
162
|
+
</x>
|
163
|
+
eoxml
|
164
|
+
assert_nil reader.prefix
|
165
|
+
assert_equal [nil, nil, "edi", nil, "edi", nil, nil],
|
166
|
+
reader.map { |n| n.prefix }
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_state
|
170
|
+
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</bar>')
|
171
|
+
assert reader.state
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_ns_uri
|
175
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
176
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
177
|
+
<edi:foo>hello</edi:foo>
|
178
|
+
</x>
|
179
|
+
eoxml
|
180
|
+
assert_nil reader.namespace_uri
|
181
|
+
assert_equal([nil,
|
182
|
+
nil,
|
183
|
+
"http://ecommerce.example.org/schema",
|
184
|
+
nil,
|
185
|
+
"http://ecommerce.example.org/schema",
|
186
|
+
nil,
|
187
|
+
nil],
|
188
|
+
reader.map { |n| n.namespace_uri })
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_local_name
|
192
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
193
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
194
|
+
<edi:foo>hello</edi:foo>
|
195
|
+
</x>
|
196
|
+
eoxml
|
197
|
+
assert_nil reader.local_name
|
198
|
+
assert_equal(["x", "#text", "foo", "#text", "foo", "#text", "x"],
|
199
|
+
reader.map { |n| n.local_name })
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_name
|
203
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
204
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
205
|
+
<edi:foo>hello</edi:foo>
|
206
|
+
</x>
|
207
|
+
eoxml
|
208
|
+
assert_nil reader.name
|
209
|
+
assert_equal(["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"],
|
210
|
+
reader.map { |n| n.name })
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_read_from_memory
|
214
|
+
called = false
|
215
|
+
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</foo>')
|
216
|
+
reader.each do |node|
|
217
|
+
called = true
|
218
|
+
assert node
|
219
|
+
end
|
220
|
+
assert called
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
|
+
|
3
|
+
class TestXsltTransforms < Nokogiri::TestCase
|
4
|
+
def test_transform
|
5
|
+
assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
|
6
|
+
assert doc.xml?
|
7
|
+
|
8
|
+
assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
|
9
|
+
|
10
|
+
assert result = style.apply_to(doc, ['title', '"Booyah"'])
|
11
|
+
assert_match %r{<h1>Booyah</h1>}, result
|
12
|
+
assert_match %r{<th.*Employee ID</th>}, result
|
13
|
+
assert_match %r{<th.*Name</th>}, result
|
14
|
+
assert_match %r{<th.*Position</th>}, result
|
15
|
+
assert_match %r{<th.*Salary</th>}, result
|
16
|
+
assert_match %r{<td>EMP0003</td>}, result
|
17
|
+
assert_match %r{<td>Margaret Martin</td>}, result
|
18
|
+
assert_match %r{<td>Computer Specialist</td>}, result
|
19
|
+
assert_match %r{<td>100,000</td>}, result
|
20
|
+
assert_no_match %r{Dallas|Texas}, result
|
21
|
+
assert_no_match %r{Female}, result
|
22
|
+
|
23
|
+
assert result = style.apply_to(doc, ['title', '"Grandma"'])
|
24
|
+
assert_match %r{<h1>Grandma</h1>}, result
|
25
|
+
|
26
|
+
assert result = style.apply_to(doc)
|
27
|
+
assert_match %r{<h1></h1>}, result
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', "helper"))
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
module SAX
|
6
|
+
class TestParser < Nokogiri::SAX::TestCase
|
7
|
+
def setup
|
8
|
+
@parser = XML::SAX::Parser.new(Doc.new)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_parse
|
12
|
+
File.open(XML_FILE, 'rb') { |f|
|
13
|
+
@parser.parse(f)
|
14
|
+
}
|
15
|
+
@parser.parse(File.read(XML_FILE))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_parse_io
|
19
|
+
File.open(XML_FILE, 'rb') { |f|
|
20
|
+
@parser.parse_io(f)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_parse_file
|
25
|
+
@parser.parse_file(XML_FILE)
|
26
|
+
assert_raises(Errno::ENOENT) {
|
27
|
+
@parser.parse_file('')
|
28
|
+
}
|
29
|
+
assert_raises(Errno::EISDIR) {
|
30
|
+
@parser.parse_file(File.expand_path(File.dirname(__FILE__)))
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_ctag
|
35
|
+
@parser.parse_memory(<<-eoxml)
|
36
|
+
<p id="asdfasdf">
|
37
|
+
<![CDATA[ This is a comment ]]>
|
38
|
+
Paragraph 1
|
39
|
+
</p>
|
40
|
+
eoxml
|
41
|
+
assert_equal [' This is a comment '], @parser.document.cdata_blocks
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_comment
|
45
|
+
@parser.parse_memory(<<-eoxml)
|
46
|
+
<p id="asdfasdf">
|
47
|
+
<!-- This is a comment -->
|
48
|
+
Paragraph 1
|
49
|
+
</p>
|
50
|
+
eoxml
|
51
|
+
assert_equal [' This is a comment '], @parser.document.comments
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_characters
|
55
|
+
@parser.parse_memory(<<-eoxml)
|
56
|
+
<p id="asdfasdf">Paragraph 1</p>
|
57
|
+
eoxml
|
58
|
+
assert_equal ['Paragraph 1'], @parser.document.data
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_end_document
|
62
|
+
@parser.parse_memory(<<-eoxml)
|
63
|
+
<p id="asdfasdf">Paragraph 1</p>
|
64
|
+
eoxml
|
65
|
+
assert @parser.document.end_document_called
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_end_element
|
69
|
+
@parser.parse_memory(<<-eoxml)
|
70
|
+
<p id="asdfasdf">Paragraph 1</p>
|
71
|
+
eoxml
|
72
|
+
assert_equal [["p"]],
|
73
|
+
@parser.document.end_elements
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_start_element_attrs
|
77
|
+
@parser.parse_memory(<<-eoxml)
|
78
|
+
<p id="asdfasdf">Paragraph 1</p>
|
79
|
+
eoxml
|
80
|
+
assert_equal [["p", ["id", "asdfasdf"]]],
|
81
|
+
@parser.document.start_elements
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_parse_document
|
85
|
+
@parser.parse_memory(<<-eoxml)
|
86
|
+
<p>Paragraph 1</p>
|
87
|
+
<p>Paragraph 2</p>
|
88
|
+
eoxml
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class TestBuilder < Nokogiri::TestCase
|
6
|
+
def test_cdata
|
7
|
+
builder = Nokogiri::XML::Builder.new do
|
8
|
+
root {
|
9
|
+
cdata "hello world"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
assert_equal("<?xml version=\"1.0\"?><root><![CDATA[hello world]]></root>", builder.to_xml.gsub(/\n/, ''))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class TestCDATA < Nokogiri::TestCase
|
6
|
+
def setup
|
7
|
+
@xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_cdata_node
|
11
|
+
name = @xml.xpath('//employee[2]/name').first
|
12
|
+
assert cdata = name.children[1]
|
13
|
+
assert cdata.cdata?
|
14
|
+
assert_equal 'cdata-section', cdata.name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class TestDocument < Nokogiri::TestCase
|
6
|
+
def setup
|
7
|
+
@xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_XML_function
|
11
|
+
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
|
12
|
+
assert xml.xml?
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_document_name
|
16
|
+
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
|
17
|
+
assert_equal 'document', xml.name
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_parse_can_take_io
|
21
|
+
xml = nil
|
22
|
+
File.open(XML_FILE, 'rb') { |f|
|
23
|
+
xml = Nokogiri::XML(f)
|
24
|
+
}
|
25
|
+
assert xml.xml?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_search_on_empty_documents
|
29
|
+
doc = Nokogiri::XML::Document.new
|
30
|
+
ns = doc.search('//foo')
|
31
|
+
assert_equal 0, ns.length
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_new_document_collect_namespaces
|
35
|
+
doc = Nokogiri::XML::Document.new
|
36
|
+
assert_equal({}, doc.collect_namespaces)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_find_with_namespace
|
40
|
+
doc = Nokogiri::XML.parse(<<-eoxml)
|
41
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
42
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
43
|
+
</x>
|
44
|
+
eoxml
|
45
|
+
|
46
|
+
ctx = Nokogiri::XML::XPathContext.new(doc)
|
47
|
+
ctx.register_ns 'tenderlove', 'http://tenderlovemaking.com/'
|
48
|
+
set = ctx.evaluate('//tenderlove:foo').node_set
|
49
|
+
assert_equal 1, set.length
|
50
|
+
assert_equal 'foo', set.first.name
|
51
|
+
|
52
|
+
# It looks like only the URI is important:
|
53
|
+
ctx = Nokogiri::XML::XPathContext.new(doc)
|
54
|
+
ctx.register_ns 'america', 'http://tenderlovemaking.com/'
|
55
|
+
set = ctx.evaluate('//america:foo').node_set
|
56
|
+
assert_equal 1, set.length
|
57
|
+
assert_equal 'foo', set.first.name
|
58
|
+
|
59
|
+
# Its so important that a missing slash will cause it to return nothing
|
60
|
+
ctx = Nokogiri::XML::XPathContext.new(doc)
|
61
|
+
ctx.register_ns 'america', 'http://tenderlovemaking.com'
|
62
|
+
set = ctx.evaluate('//america:foo').node_set
|
63
|
+
assert_equal 0, set.length
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_xml?
|
67
|
+
assert @xml.xml?
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_document
|
71
|
+
assert @xml.document
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_multiple_search
|
75
|
+
assert node_set = @xml.search('//employee', '//name')
|
76
|
+
employees = @xml.search('//employee')
|
77
|
+
names = @xml.search('//name')
|
78
|
+
assert_equal(employees.length + names.length, node_set.length)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_node_set_index
|
82
|
+
assert node_set = @xml.search('//employee')
|
83
|
+
|
84
|
+
assert_equal(5, node_set.length)
|
85
|
+
assert node_set[4]
|
86
|
+
assert_nil node_set[5]
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_search
|
90
|
+
assert node_set = @xml.search('//employee')
|
91
|
+
|
92
|
+
assert_equal(5, node_set.length)
|
93
|
+
|
94
|
+
node_set.each do |node|
|
95
|
+
assert_equal('employee', node.name)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_dump
|
100
|
+
assert @xml.serialize
|
101
|
+
assert @xml.to_xml
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_subset_is_decorated
|
105
|
+
x = Module.new do
|
106
|
+
def awesome!
|
107
|
+
end
|
108
|
+
end
|
109
|
+
util_decorate(@xml, x)
|
110
|
+
|
111
|
+
assert @xml.respond_to?(:awesome!)
|
112
|
+
assert node_set = @xml.search('//staff')
|
113
|
+
assert node_set.respond_to?(:awesome!)
|
114
|
+
assert subset = node_set.search('.//employee')
|
115
|
+
assert subset.respond_to?(:awesome!)
|
116
|
+
assert sub_subset = node_set.search('.//name')
|
117
|
+
assert sub_subset.respond_to?(:awesome!)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_decorator_is_applied
|
121
|
+
x = Module.new do
|
122
|
+
def awesome!
|
123
|
+
end
|
124
|
+
end
|
125
|
+
util_decorate(@xml, x)
|
126
|
+
|
127
|
+
assert @xml.respond_to?(:awesome!)
|
128
|
+
assert node_set = @xml.search('//employee')
|
129
|
+
assert node_set.respond_to?(:awesome!)
|
130
|
+
node_set.each do |node|
|
131
|
+
assert node.respond_to?(:awesome!), node.class
|
132
|
+
end
|
133
|
+
assert @xml.root.respond_to?(:awesome!)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_new
|
137
|
+
doc = nil
|
138
|
+
assert_nothing_raised {
|
139
|
+
doc = Nokogiri::XML::Document.new
|
140
|
+
}
|
141
|
+
assert doc
|
142
|
+
assert doc.xml?
|
143
|
+
assert_nil doc.root
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_set_root
|
147
|
+
doc = nil
|
148
|
+
assert_nothing_raised {
|
149
|
+
doc = Nokogiri::XML::Document.new
|
150
|
+
}
|
151
|
+
assert doc
|
152
|
+
assert doc.xml?
|
153
|
+
assert_nil doc.root
|
154
|
+
node = Nokogiri::XML::Node.new("b") { |n|
|
155
|
+
n.content = 'hello world'
|
156
|
+
}
|
157
|
+
assert_equal('hello world', node.content)
|
158
|
+
doc.root = node
|
159
|
+
assert_equal(node, doc.root)
|
160
|
+
end
|
161
|
+
|
162
|
+
def util_decorate(document, x)
|
163
|
+
document.decorators['document'] << x
|
164
|
+
document.decorators['node'] << x
|
165
|
+
document.decorators['element'] << x
|
166
|
+
document.decorators['nodeset'] << x
|
167
|
+
document.decorate!
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|