nokogiri 1.2.3-java → 1.3.0-java
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/.autotest +14 -2
- data/CHANGELOG.ja.rdoc +38 -0
- data/CHANGELOG.rdoc +43 -0
- data/Manifest.txt +80 -5
- data/README.ja.rdoc +12 -11
- data/README.rdoc +4 -2
- data/Rakefile +103 -173
- data/bin/nokogiri +47 -0
- data/ext/nokogiri/extconf.rb +19 -13
- data/ext/nokogiri/html_document.c +39 -3
- data/ext/nokogiri/html_document.h +1 -1
- data/ext/nokogiri/html_element_description.c +272 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.h +1 -1
- data/ext/nokogiri/html_sax_parser.h +1 -1
- data/ext/nokogiri/{native.c → nokogiri.c} +11 -3
- data/ext/nokogiri/{native.h → nokogiri.h} +18 -4
- data/ext/nokogiri/xml_attr.c +14 -5
- data/ext/nokogiri/xml_attr.h +1 -1
- data/ext/nokogiri/xml_cdata.c +15 -6
- data/ext/nokogiri/xml_cdata.h +1 -1
- data/ext/nokogiri/xml_comment.c +13 -4
- data/ext/nokogiri/xml_comment.h +1 -1
- data/ext/nokogiri/xml_document.c +50 -41
- data/ext/nokogiri/xml_document.h +1 -1
- data/ext/nokogiri/xml_document_fragment.c +12 -4
- data/ext/nokogiri/xml_document_fragment.h +1 -1
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_dtd.h +1 -1
- data/ext/nokogiri/xml_entity_reference.c +13 -4
- data/ext/nokogiri/xml_entity_reference.h +1 -1
- data/ext/nokogiri/xml_io.h +1 -1
- data/ext/nokogiri/xml_namespace.c +69 -0
- data/ext/nokogiri/xml_namespace.h +12 -0
- data/ext/nokogiri/xml_node.c +232 -124
- data/ext/nokogiri/xml_node.h +3 -4
- data/ext/nokogiri/xml_node_set.c +204 -17
- data/ext/nokogiri/xml_node_set.h +1 -1
- data/ext/nokogiri/xml_processing_instruction.c +14 -4
- data/ext/nokogiri/xml_processing_instruction.h +1 -1
- data/ext/nokogiri/xml_reader.c +87 -7
- data/ext/nokogiri/xml_reader.h +1 -1
- data/ext/nokogiri/xml_relax_ng.c +106 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +122 -2
- data/ext/nokogiri/xml_sax_parser.h +1 -1
- data/ext/nokogiri/xml_sax_push_parser.c +1 -0
- data/ext/nokogiri/xml_sax_push_parser.h +1 -1
- data/ext/nokogiri/xml_schema.c +107 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.h +1 -1
- data/ext/nokogiri/xml_text.c +10 -3
- data/ext/nokogiri/xml_text.h +1 -1
- data/ext/nokogiri/xml_xpath.h +1 -1
- data/ext/nokogiri/xml_xpath_context.h +1 -1
- data/ext/nokogiri/xslt_stylesheet.c +29 -16
- data/ext/nokogiri/xslt_stylesheet.h +1 -1
- data/lib/action-nokogiri.rb +7 -1
- data/lib/nokogiri.rb +21 -5
- data/lib/nokogiri/css/generated_parser.rb +49 -14
- data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
- data/lib/nokogiri/css/node.rb +13 -3
- data/lib/nokogiri/css/parser.rb +8 -0
- data/lib/nokogiri/css/parser.y +7 -7
- data/lib/nokogiri/css/tokenizer.rb +2 -0
- data/lib/nokogiri/css/xpath_visitor.rb +10 -6
- data/lib/nokogiri/decorators/hpricot/node.rb +1 -1
- data/lib/nokogiri/decorators/hpricot/node_set.rb +2 -2
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +2 -0
- data/lib/nokogiri/decorators/slop.rb +3 -1
- data/lib/nokogiri/ffi/html/document.rb +37 -0
- data/lib/nokogiri/ffi/html/element_description.rb +85 -0
- data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
- data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
- data/lib/nokogiri/ffi/libxml.rb +314 -0
- data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
- data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
- data/lib/nokogiri/ffi/xml/attr.rb +41 -0
- data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
- data/lib/nokogiri/ffi/xml/comment.rb +18 -0
- data/lib/nokogiri/ffi/xml/document.rb +107 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
- data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
- data/lib/nokogiri/ffi/xml/node.rb +380 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +217 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
- data/lib/nokogiri/ffi/xml/schema.rb +55 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
- data/lib/nokogiri/ffi/xml/text.rb +18 -0
- data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
- data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
- data/lib/nokogiri/hpricot.rb +14 -3
- data/lib/nokogiri/html.rb +11 -46
- data/lib/nokogiri/html/builder.rb +27 -1
- data/lib/nokogiri/html/document.rb +62 -6
- data/lib/nokogiri/html/document_fragment.rb +15 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/entity_lookup.rb +2 -0
- data/lib/nokogiri/html/sax/parser.rb +27 -1
- data/lib/nokogiri/version.rb +26 -1
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +25 -51
- data/lib/nokogiri/xml/builder.rb +166 -10
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/document.rb +39 -6
- data/lib/nokogiri/xml/document_fragment.rb +41 -1
- data/lib/nokogiri/xml/dtd.rb +3 -1
- data/lib/nokogiri/xml/entity_declaration.rb +3 -1
- data/lib/nokogiri/xml/fragment_handler.rb +24 -3
- data/lib/nokogiri/xml/namespace.rb +7 -0
- data/lib/nokogiri/xml/node.rb +314 -65
- data/lib/nokogiri/xml/node/save_options.rb +12 -2
- data/lib/nokogiri/xml/node_set.rb +58 -8
- data/lib/nokogiri/xml/parse_options.rb +80 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -0
- data/lib/nokogiri/xml/reader.rb +42 -3
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +0 -7
- data/lib/nokogiri/xml/sax/document.rb +84 -0
- data/lib/nokogiri/xml/sax/parser.rb +38 -2
- data/lib/nokogiri/xml/sax/push_parser.rb +12 -0
- data/lib/nokogiri/xml/schema.rb +65 -0
- data/lib/nokogiri/xml/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath.rb +1 -1
- data/lib/nokogiri/xml/xpath_context.rb +2 -0
- data/lib/nokogiri/xslt.rb +21 -1
- data/lib/nokogiri/xslt/stylesheet.rb +19 -0
- data/lib/xsd/xmlparser/nokogiri.rb +12 -2
- data/tasks/test.rb +42 -19
- data/test/css/test_parser.rb +29 -0
- data/test/ffi/test_document.rb +35 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/helper.rb +38 -8
- data/test/html/sax/test_parser.rb +12 -0
- data/test/html/test_builder.rb +25 -2
- data/test/html/test_document.rb +91 -20
- data/test/html/test_document_fragment.rb +97 -0
- data/test/html/test_element_description.rb +95 -0
- data/test/html/test_node.rb +66 -3
- data/test/test_convert_xpath.rb +1 -1
- data/test/test_memory_leak.rb +57 -18
- data/test/test_nokogiri.rb +24 -2
- data/test/test_reader.rb +77 -0
- data/test/test_xslt_transforms.rb +120 -82
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +9 -0
- data/test/xml/sax/test_push_parser.rb +24 -0
- data/test/xml/test_attr.rb +7 -0
- data/test/xml/test_builder.rb +48 -0
- data/test/xml/test_cdata.rb +19 -0
- data/test/xml/test_comment.rb +6 -0
- data/test/xml/test_document.rb +101 -2
- data/test/xml/test_document_fragment.rb +55 -3
- data/test/xml/test_entity_reference.rb +4 -0
- data/test/xml/test_namespace.rb +43 -0
- data/test/xml/test_node.rb +255 -8
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +9 -2
- data/test/xml/test_node_set.rb +197 -1
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +5 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +65 -0
- data/test/xml/test_text.rb +5 -0
- data/test/xml/test_unparented_node.rb +3 -3
- metadata +129 -13
- data/lib/nokogiri/xml/comment.rb +0 -6
- data/lib/nokogiri/xml/element.rb +0 -6
- data/lib/nokogiri/xml/text.rb +0 -6
@@ -1,93 +1,131 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
2
|
|
3
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
|
-
def test_transform2
|
30
|
-
assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
|
31
|
-
assert doc.xml?
|
32
4
|
|
33
|
-
|
34
|
-
assert result_doc = style.transform(doc, ['title', '"Booyah"'])
|
35
|
-
assert doc.xml?
|
5
|
+
if Nokogiri::VERSION_INFO['libxml']['loaded'] > '2.6.16'
|
36
6
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def test_quote_params
|
41
|
-
h = {
|
42
|
-
:sym => %{xxx},
|
43
|
-
'str' => %{"xxx"},
|
44
|
-
:sym2 => %{'xxx'},
|
45
|
-
'str2' => %{x'x'x},
|
46
|
-
:sym3 => %{x"x"x},
|
47
|
-
}
|
48
|
-
hh=h.dup
|
49
|
-
result_hash = Nokogiri::XSLT.quote_params(h)
|
50
|
-
assert_equal hh, h # non-destructive
|
51
|
-
|
52
|
-
a=h.to_a.flatten
|
53
|
-
result_array = Nokogiri::XSLT.quote_params(a)
|
54
|
-
assert_equal h.to_a.flatten, a #non-destructive
|
55
|
-
|
56
|
-
assert_equal result_array, result_hash
|
57
|
-
end
|
7
|
+
def test_class_methods
|
8
|
+
doc = Nokogiri::XML(File.read(XML_FILE))
|
9
|
+
style = Nokogiri::XSLT(File.read(XSLT_FILE))
|
58
10
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
11
|
+
assert result = style.apply_to(doc, ['title', '"Grandma"'])
|
12
|
+
assert_match %r{<h1>Grandma</h1>}, result
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_transform
|
16
|
+
assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
|
17
|
+
assert doc.xml?
|
18
|
+
|
19
|
+
assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
|
20
|
+
|
21
|
+
assert result = style.apply_to(doc, ['title', '"Booyah"'])
|
22
|
+
assert_match %r{<h1>Booyah</h1>}, result
|
23
|
+
assert_match %r{<th.*Employee ID</th>}, result
|
24
|
+
assert_match %r{<th.*Name</th>}, result
|
25
|
+
assert_match %r{<th.*Position</th>}, result
|
26
|
+
assert_match %r{<th.*Salary</th>}, result
|
27
|
+
assert_match %r{<td>EMP0003</td>}, result
|
28
|
+
assert_match %r{<td>Margaret Martin</td>}, result
|
29
|
+
assert_match %r{<td>Computer Specialist</td>}, result
|
30
|
+
assert_match %r{<td>100,000</td>}, result
|
31
|
+
assert_no_match %r{Dallas|Texas}, result
|
32
|
+
assert_no_match %r{Female}, result
|
33
|
+
|
34
|
+
assert result = style.apply_to(doc, ['title', '"Grandma"'])
|
35
|
+
assert_match %r{<h1>Grandma</h1>}, result
|
36
|
+
|
37
|
+
assert result = style.apply_to(doc)
|
38
|
+
assert_match %r{<h1></h1>}, result
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_transform2
|
42
|
+
assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
|
43
|
+
assert doc.xml?
|
44
|
+
|
45
|
+
assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
|
46
|
+
assert result_doc = style.transform(doc)
|
47
|
+
assert doc.xml?
|
48
|
+
|
49
|
+
assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
|
50
|
+
assert result_doc = style.transform(doc, ['title', '"Booyah"'])
|
51
|
+
assert doc.xml?
|
52
|
+
|
53
|
+
assert result_string = style.apply_to(doc, ['title', '"Booyah"'])
|
54
|
+
assert_equal result_string, style.serialize(result_doc)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_quote_params
|
58
|
+
h = {
|
59
|
+
:sym => %{xxx},
|
60
|
+
'str' => %{"xxx"},
|
61
|
+
:sym2 => %{'xxx'},
|
62
|
+
'str2' => %{x'x'x},
|
63
|
+
:sym3 => %{x"x"x},
|
64
|
+
}
|
65
|
+
hh=h.dup
|
66
|
+
result_hash = Nokogiri::XSLT.quote_params(h)
|
67
|
+
assert_equal hh, h # non-destructive
|
68
|
+
|
69
|
+
a=h.to_a.flatten
|
70
|
+
result_array = Nokogiri::XSLT.quote_params(a)
|
71
|
+
assert_equal h.to_a.flatten, a #non-destructive
|
72
|
+
|
73
|
+
assert_equal result_array, result_hash
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_exslt
|
77
|
+
assert doc = Nokogiri::XML.parse(File.read(EXML_FILE))
|
78
|
+
assert doc.xml?
|
79
|
+
|
80
|
+
assert style = Nokogiri::XSLT.parse(File.read(EXSLT_FILE))
|
81
|
+
params = {
|
82
|
+
:p1 => 'xxx',
|
83
|
+
:p2 => "x'x'x",
|
84
|
+
:p3 => 'x"x"x',
|
85
|
+
:p4 => '"xxx"'
|
86
|
+
}
|
87
|
+
result_doc = Nokogiri::XML.parse(style.apply_to(doc,
|
88
|
+
Nokogiri::XSLT.quote_params(params)))
|
89
|
+
|
90
|
+
assert_equal 'func-result', result_doc.at('/root/function').content
|
91
|
+
assert_equal 3, result_doc.at('/root/max').content.to_i
|
92
|
+
assert_match(
|
93
|
+
/\d{4}-\d\d-\d\d[-|+]\d\d:\d\d/,
|
94
|
+
result_doc.at('/root/date').content
|
95
|
+
)
|
96
|
+
result_doc.xpath('/root/params/*').each do |p|
|
97
|
+
assert_equal p.content, params[p.name.intern]
|
98
|
+
end
|
99
|
+
check_params result_doc, params
|
100
|
+
result_doc = Nokogiri::XML.parse(style.apply_to(doc,
|
101
|
+
Nokogiri::XSLT.quote_params(params.to_a.flatten)))
|
102
|
+
check_params result_doc, params
|
103
|
+
end
|
72
104
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
105
|
+
def test_xslt_parse_error
|
106
|
+
xslt_str = <<-EOX
|
107
|
+
<xsl:stylesheet version="1.0"
|
108
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
109
|
+
<!-- Not well-formed: -->
|
110
|
+
<xsl:template match="/"/>
|
111
|
+
<values>
|
112
|
+
<xsl:for-each select="//*">
|
113
|
+
<value>
|
114
|
+
<xsl:value-of select="@id"/>
|
115
|
+
</value>
|
116
|
+
</xsl:for-each>
|
117
|
+
</values>
|
118
|
+
</xsl:template>
|
119
|
+
</xsl:stylesheet>}
|
120
|
+
EOX
|
121
|
+
assert_raises(RuntimeError) { Nokogiri::XSLT.parse(xslt_str) }
|
81
122
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def check_params result_doc, params
|
89
|
-
result_doc.xpath('/root/params/*').each do |p|
|
90
|
-
assert_equal p.content, params[p.name.intern]
|
123
|
+
|
124
|
+
def check_params result_doc, params
|
125
|
+
result_doc.xpath('/root/params/*').each do |p|
|
126
|
+
assert_equal p.content, params[p.name.intern]
|
127
|
+
end
|
91
128
|
end
|
129
|
+
|
92
130
|
end
|
93
131
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..',"helper"))
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Node
|
6
|
+
class TestSubclass < Nokogiri::TestCase
|
7
|
+
{
|
8
|
+
Nokogiri::XML::CDATA => 'doc, "foo"',
|
9
|
+
Nokogiri::XML::Attr => 'doc, "foo"',
|
10
|
+
Nokogiri::XML::Comment => 'doc, "foo"',
|
11
|
+
Nokogiri::XML::EntityReference => 'doc, "foo"',
|
12
|
+
Nokogiri::XML::ProcessingInstruction => 'doc, "foo", "bar"',
|
13
|
+
Nokogiri::XML::DocumentFragment => 'doc',
|
14
|
+
Nokogiri::XML::Node => '"foo", doc',
|
15
|
+
Nokogiri::XML::Text => '"foo", doc',
|
16
|
+
}.each do |klass, constructor|
|
17
|
+
class_eval %{
|
18
|
+
def test_subclass_#{klass.name.gsub('::', '_')}
|
19
|
+
doc = Nokogiri::XML::Document.new
|
20
|
+
klass = Class.new(#{klass.name})
|
21
|
+
node = klass.new(#{constructor})
|
22
|
+
assert_instance_of klass, node
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
class_eval <<-eocode, __FILE__, __LINE__ + 1
|
27
|
+
def test_subclass_initialize_#{klass.name.gsub('::', '_')}
|
28
|
+
doc = Nokogiri::XML::Document.new
|
29
|
+
klass = Class.new(#{klass.name}) do
|
30
|
+
attr_accessor :initialized_with
|
31
|
+
|
32
|
+
def initialize *args
|
33
|
+
@initialized_with = args
|
34
|
+
end
|
35
|
+
end
|
36
|
+
node = klass.new(#{constructor}, 1)
|
37
|
+
assert_equal [#{constructor}, 1], node.initialized_with
|
38
|
+
end
|
39
|
+
eocode
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/test/xml/sax/test_parser.rb
CHANGED
@@ -90,6 +90,11 @@ module Nokogiri
|
|
90
90
|
|
91
91
|
def test_parse_file
|
92
92
|
@parser.parse_file(XML_FILE)
|
93
|
+
|
94
|
+
assert_raises(ArgumentError) {
|
95
|
+
@parser.parse_file(nil)
|
96
|
+
}
|
97
|
+
|
93
98
|
assert_raises(Errno::ENOENT) {
|
94
99
|
@parser.parse_file('')
|
95
100
|
}
|
@@ -98,6 +103,10 @@ module Nokogiri
|
|
98
103
|
}
|
99
104
|
end
|
100
105
|
|
106
|
+
def test_render_parse_nil_param
|
107
|
+
assert_raises(ArgumentError) { @parser.parse_memory(nil) }
|
108
|
+
end
|
109
|
+
|
101
110
|
def test_ctag
|
102
111
|
@parser.parse_memory(<<-eoxml)
|
103
112
|
<p id="asdfasdf">
|
@@ -38,6 +38,30 @@ module Nokogiri
|
|
38
38
|
@parser.finish
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_start_element_ns
|
42
|
+
@parser.<<(<<-eoxml)
|
43
|
+
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' size='large'></stream:stream>
|
44
|
+
eoxml
|
45
|
+
|
46
|
+
assert_equal [[ 'stream',
|
47
|
+
{'version' => '1.0', 'size' => 'large'},
|
48
|
+
'stream',
|
49
|
+
'http://etherx.jabber.org/streams',
|
50
|
+
{nil => 'jabber:client', 'stream' => 'http://etherx.jabber.org/streams'}]],
|
51
|
+
@parser.document.start_elements_ns
|
52
|
+
@parser.finish
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_end_element_ns
|
56
|
+
@parser.<<(<<-eoxml)
|
57
|
+
<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'></stream:stream>
|
58
|
+
eoxml
|
59
|
+
|
60
|
+
assert_equal [['stream', 'stream', 'http://etherx.jabber.org/streams']],
|
61
|
+
@parser.document.end_elements_ns
|
62
|
+
@parser.finish
|
63
|
+
end
|
64
|
+
|
41
65
|
def test_chevron_partial_xml
|
42
66
|
@parser.<<(<<-eoxml)
|
43
67
|
<p id="asdfasdf">
|
data/test/xml/test_attr.rb
CHANGED
@@ -3,6 +3,13 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
|
3
3
|
module Nokogiri
|
4
4
|
module XML
|
5
5
|
class TestAttr < Nokogiri::TestCase
|
6
|
+
def test_new
|
7
|
+
100.times {
|
8
|
+
doc = Nokogiri::XML::Document.new
|
9
|
+
attribute = Nokogiri::XML::Attr.new(doc, 'foo')
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
6
13
|
def test_content=
|
7
14
|
xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
|
8
15
|
address = xml.xpath('//address')[3]
|
data/test/xml/test_builder.rb
CHANGED
@@ -3,6 +3,54 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
|
3
3
|
module Nokogiri
|
4
4
|
module XML
|
5
5
|
class TestBuilder < Nokogiri::TestCase
|
6
|
+
def test_set_encoding
|
7
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
8
|
+
xml.root do
|
9
|
+
xml.bar 'blah'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
assert_match 'UTF-8', builder.to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_bang_and_underscore_is_escaped
|
16
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
17
|
+
xml.root do
|
18
|
+
xml.p_('adsfadsf')
|
19
|
+
xml.p!('adsfadsf')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
assert_equal 2, builder.doc.xpath('//p').length
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_square_brackets_set_attributes
|
26
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
27
|
+
xml.root do
|
28
|
+
foo = xml.foo
|
29
|
+
foo['id'] = 'hello'
|
30
|
+
assert_equal 'hello', foo['id']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
assert_equal 1, builder.doc.xpath('//foo[@id = "hello"]').length
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_nested_local_variable
|
37
|
+
@ivar = 'hello'
|
38
|
+
local_var = 'hello world'
|
39
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
40
|
+
xml.root do
|
41
|
+
xml.foo local_var
|
42
|
+
xml.bar @ivar
|
43
|
+
xml.baz {
|
44
|
+
xml.text @ivar
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_equal 'hello world', builder.doc.at('//root/foo').content
|
50
|
+
assert_equal 'hello', builder.doc.at('//root/bar').content
|
51
|
+
assert_equal 'hello', builder.doc.at('baz').content
|
52
|
+
end
|
53
|
+
|
6
54
|
def test_cdata
|
7
55
|
builder = Nokogiri::XML::Builder.new do
|
8
56
|
root {
|
data/test/xml/test_cdata.rb
CHANGED
@@ -14,6 +14,25 @@ module Nokogiri
|
|
14
14
|
assert cdata.cdata?
|
15
15
|
assert_equal '#cdata-section', cdata.name
|
16
16
|
end
|
17
|
+
|
18
|
+
def test_new
|
19
|
+
node = CDATA.new(@xml, "foo")
|
20
|
+
assert_equal "foo", node.content
|
21
|
+
|
22
|
+
node = CDATA.new(@xml.root, "foo")
|
23
|
+
assert_equal "foo", node.content
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_new_with_nil
|
27
|
+
node = CDATA.new(@xml, nil)
|
28
|
+
assert_equal nil, node.content
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_lots_of_new_cdata
|
32
|
+
100.times {
|
33
|
+
node = CDATA.new(@xml, "asdfasdf")
|
34
|
+
}
|
35
|
+
end
|
17
36
|
end
|
18
37
|
end
|
19
38
|
end
|
data/test/xml/test_comment.rb
CHANGED
@@ -12,6 +12,12 @@ module Nokogiri
|
|
12
12
|
comment = Nokogiri::XML::Comment.new(@xml, 'hello world')
|
13
13
|
assert_equal('<!--hello world-->', comment.to_s)
|
14
14
|
end
|
15
|
+
|
16
|
+
def test_many_comments
|
17
|
+
100.times {
|
18
|
+
Nokogiri::XML::Comment.new(@xml, 'hello world')
|
19
|
+
}
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
data/test/xml/test_document.rb
CHANGED
@@ -10,6 +10,80 @@ module Nokogiri
|
|
10
10
|
@xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_parse_takes_block
|
14
|
+
options = nil
|
15
|
+
Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
|
16
|
+
options = cfg
|
17
|
+
end
|
18
|
+
assert options
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_parse_yields_parse_options
|
22
|
+
options = nil
|
23
|
+
Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
|
24
|
+
options = cfg
|
25
|
+
options.nonet.nowarning.dtdattr
|
26
|
+
end
|
27
|
+
assert options.nonet?
|
28
|
+
assert options.nowarning?
|
29
|
+
assert options.dtdattr?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_XML_takes_block
|
33
|
+
options = nil
|
34
|
+
Nokogiri::XML(File.read(XML_FILE), XML_FILE) do |cfg|
|
35
|
+
options = cfg
|
36
|
+
options.nonet.nowarning.dtdattr
|
37
|
+
end
|
38
|
+
assert options.nonet?
|
39
|
+
assert options.nowarning?
|
40
|
+
assert options.dtdattr?
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_subclass
|
44
|
+
klass = Class.new(Nokogiri::XML::Document)
|
45
|
+
doc = klass.new
|
46
|
+
assert_instance_of klass, doc
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_subclass_initialize
|
50
|
+
klass = Class.new(Nokogiri::XML::Document) do
|
51
|
+
attr_accessor :initialized_with
|
52
|
+
|
53
|
+
def initialize(*args)
|
54
|
+
@initialized_with = args
|
55
|
+
end
|
56
|
+
end
|
57
|
+
doc = klass.new("1.0", 1)
|
58
|
+
assert_equal ["1.0", 1], doc.initialized_with
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_subclass_dup
|
62
|
+
klass = Class.new(Nokogiri::XML::Document)
|
63
|
+
doc = klass.new.dup
|
64
|
+
assert_instance_of klass, doc
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_subclass_parse
|
68
|
+
klass = Class.new(Nokogiri::XML::Document)
|
69
|
+
doc = klass.parse(File.read(XML_FILE))
|
70
|
+
assert_equal @xml.to_s, doc.to_s
|
71
|
+
assert_instance_of klass, doc
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_document_parse_method
|
75
|
+
xml = Nokogiri::XML::Document.parse(File.read(XML_FILE))
|
76
|
+
assert_equal @xml.to_s, xml.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_encoding=
|
80
|
+
@xml.encoding = 'UTF-8'
|
81
|
+
assert_match 'UTF-8', @xml.to_xml
|
82
|
+
|
83
|
+
@xml.encoding = 'EUC-JP'
|
84
|
+
assert_match 'EUC-JP', @xml.to_xml
|
85
|
+
end
|
86
|
+
|
13
87
|
def test_namespace_should_not_exist
|
14
88
|
assert_raises(NoMethodError) {
|
15
89
|
@xml.namespace
|
@@ -17,13 +91,22 @@ module Nokogiri
|
|
17
91
|
end
|
18
92
|
|
19
93
|
def test_non_existant_function
|
20
|
-
|
94
|
+
# WTF. I don't know why this is different between MRI and ffi.
|
95
|
+
# They should be the same... Either way, raising an exception
|
96
|
+
# is the correct thing to do.
|
97
|
+
exception = RuntimeError
|
98
|
+
|
99
|
+
if Nokogiri::VERSION_INFO['libxml']['platform'] == 'jruby'
|
100
|
+
exception = Nokogiri::XML::XPath::SyntaxError
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_raises(exception) {
|
21
104
|
@xml.xpath('//name[foo()]')
|
22
105
|
}
|
23
106
|
end
|
24
107
|
|
25
108
|
def test_ancestors
|
26
|
-
assert_equal
|
109
|
+
assert_equal 0, @xml.ancestors.length
|
27
110
|
end
|
28
111
|
|
29
112
|
def test_root_node_parent_is_document
|
@@ -68,6 +151,22 @@ module Nokogiri
|
|
68
151
|
assert_equal 1, doc.search('//xmlns:foo').search('./xmlns:bar').length
|
69
152
|
end
|
70
153
|
|
154
|
+
def test_to_xml_with_indent
|
155
|
+
doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
|
156
|
+
doc = Nokogiri::XML(doc.to_xml(:indent => 5))
|
157
|
+
|
158
|
+
assert_indent 5, doc
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_write_xml_to_with_indent
|
162
|
+
io = StringIO.new
|
163
|
+
doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
|
164
|
+
doc.write_xml_to io, :indent => 5
|
165
|
+
io.rewind
|
166
|
+
doc = Nokogiri::XML(io.read)
|
167
|
+
assert_indent 5, doc
|
168
|
+
end
|
169
|
+
|
71
170
|
# wtf... osx's libxml sucks.
|
72
171
|
unless Nokogiri::LIBXML_VERSION =~ /^2\.6\./
|
73
172
|
def test_encoding
|