nokogiri 1.9.0.rc1 → 1.9.0
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.
- checksums.yaml +4 -4
- data/lib/nokogiri/css/parser.rb +61 -61
- data/lib/nokogiri/version.rb +1 -1
- metadata +4 -146
- data/.autotest +0 -22
- data/.cross_rubies +0 -8
- data/.editorconfig +0 -17
- data/.gemtest +0 -0
- data/.travis.yml +0 -63
- data/CHANGELOG.md +0 -1402
- data/CONTRIBUTING.md +0 -42
- data/C_CODING_STYLE.rdoc +0 -33
- data/Gemfile +0 -23
- data/Gemfile-libxml-ruby +0 -3
- data/Manifest.txt +0 -371
- data/ROADMAP.md +0 -111
- data/Rakefile +0 -358
- data/SECURITY.md +0 -19
- data/STANDARD_RESPONSES.md +0 -47
- data/Y_U_NO_GEMSPEC.md +0 -155
- data/appveyor.yml +0 -29
- data/build_all +0 -48
- data/patches/sort-patches-by-date +0 -25
- data/suppressions/README.txt +0 -1
- data/suppressions/nokogiri_ruby-2.supp +0 -10
- data/tasks/test.rb +0 -100
- data/test/css/test_nthiness.rb +0 -226
- data/test/css/test_parser.rb +0 -386
- data/test/css/test_tokenizer.rb +0 -215
- data/test/css/test_xpath_visitor.rb +0 -96
- data/test/decorators/test_slop.rb +0 -23
- data/test/files/2ch.html +0 -108
- data/test/files/GH_1042.html +0 -18
- data/test/files/address_book.rlx +0 -12
- data/test/files/address_book.xml +0 -10
- data/test/files/atom.xml +0 -344
- data/test/files/bar/bar.xsd +0 -4
- data/test/files/bogus.xml +0 -0
- data/test/files/dont_hurt_em_why.xml +0 -422
- data/test/files/encoding.html +0 -82
- data/test/files/encoding.xhtml +0 -84
- data/test/files/exslt.xml +0 -8
- data/test/files/exslt.xslt +0 -35
- data/test/files/foo/foo.xsd +0 -4
- data/test/files/metacharset.html +0 -10
- data/test/files/namespace_pressure_test.xml +0 -1684
- data/test/files/noencoding.html +0 -47
- data/test/files/po.xml +0 -32
- data/test/files/po.xsd +0 -66
- data/test/files/saml/saml20assertion_schema.xsd +0 -283
- data/test/files/saml/saml20protocol_schema.xsd +0 -302
- data/test/files/saml/xenc_schema.xsd +0 -146
- data/test/files/saml/xmldsig_schema.xsd +0 -318
- data/test/files/shift_jis.html +0 -10
- data/test/files/shift_jis.xml +0 -5
- data/test/files/shift_jis_no_charset.html +0 -9
- data/test/files/slow-xpath.xml +0 -25509
- data/test/files/snuggles.xml +0 -3
- data/test/files/staff.dtd +0 -10
- data/test/files/staff.xml +0 -59
- data/test/files/staff.xslt +0 -32
- data/test/files/test_document_url/bar.xml +0 -2
- data/test/files/test_document_url/document.dtd +0 -4
- data/test/files/test_document_url/document.xml +0 -6
- data/test/files/tlm.html +0 -851
- data/test/files/to_be_xincluded.xml +0 -2
- data/test/files/valid_bar.xml +0 -2
- data/test/files/xinclude.xml +0 -4
- data/test/helper.rb +0 -271
- data/test/html/sax/test_parser.rb +0 -168
- data/test/html/sax/test_parser_context.rb +0 -46
- data/test/html/sax/test_parser_text.rb +0 -163
- data/test/html/sax/test_push_parser.rb +0 -87
- data/test/html/test_attributes.rb +0 -85
- data/test/html/test_builder.rb +0 -164
- data/test/html/test_document.rb +0 -722
- data/test/html/test_document_encoding.rb +0 -143
- data/test/html/test_document_fragment.rb +0 -310
- data/test/html/test_element_description.rb +0 -105
- data/test/html/test_named_characters.rb +0 -14
- data/test/html/test_node.rb +0 -212
- data/test/html/test_node_encoding.rb +0 -91
- data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
- data/test/namespaces/test_namespaces_aliased_default.rb +0 -24
- data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_cloned_doc.rb +0 -31
- data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -80
- data/test/namespaces/test_namespaces_preservation.rb +0 -31
- data/test/test_convert_xpath.rb +0 -135
- data/test/test_css_cache.rb +0 -47
- data/test/test_encoding_handler.rb +0 -48
- data/test/test_memory_leak.rb +0 -226
- data/test/test_nokogiri.rb +0 -138
- data/test/test_soap4r_sax.rb +0 -52
- data/test/test_xslt_transforms.rb +0 -314
- data/test/xml/node/test_save_options.rb +0 -28
- data/test/xml/node/test_subclass.rb +0 -44
- data/test/xml/sax/test_parser.rb +0 -402
- data/test/xml/sax/test_parser_context.rb +0 -115
- data/test/xml/sax/test_parser_text.rb +0 -202
- data/test/xml/sax/test_push_parser.rb +0 -265
- data/test/xml/test_attr.rb +0 -96
- data/test/xml/test_attribute_decl.rb +0 -86
- data/test/xml/test_builder.rb +0 -353
- data/test/xml/test_c14n.rb +0 -180
- data/test/xml/test_cdata.rb +0 -54
- data/test/xml/test_comment.rb +0 -40
- data/test/xml/test_document.rb +0 -982
- data/test/xml/test_document_encoding.rb +0 -31
- data/test/xml/test_document_fragment.rb +0 -312
- data/test/xml/test_dtd.rb +0 -187
- data/test/xml/test_dtd_encoding.rb +0 -31
- data/test/xml/test_element_content.rb +0 -56
- data/test/xml/test_element_decl.rb +0 -73
- data/test/xml/test_entity_decl.rb +0 -122
- data/test/xml/test_entity_reference.rb +0 -262
- data/test/xml/test_namespace.rb +0 -96
- data/test/xml/test_node.rb +0 -1379
- data/test/xml/test_node_attributes.rb +0 -115
- data/test/xml/test_node_encoding.rb +0 -75
- data/test/xml/test_node_inheritance.rb +0 -32
- data/test/xml/test_node_reparenting.rb +0 -661
- data/test/xml/test_node_set.rb +0 -828
- data/test/xml/test_parse_options.rb +0 -64
- data/test/xml/test_processing_instruction.rb +0 -30
- data/test/xml/test_reader.rb +0 -620
- data/test/xml/test_reader_encoding.rb +0 -134
- data/test/xml/test_relax_ng.rb +0 -60
- data/test/xml/test_schema.rb +0 -142
- data/test/xml/test_syntax_error.rb +0 -36
- data/test/xml/test_text.rb +0 -69
- data/test/xml/test_unparented_node.rb +0 -483
- data/test/xml/test_xinclude.rb +0 -83
- data/test/xml/test_xpath.rb +0 -470
- data/test/xslt/test_custom_functions.rb +0 -133
- data/test/xslt/test_exception_handling.rb +0 -37
@@ -1,75 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
module Nokogiri
|
4
|
-
module XML
|
5
|
-
class TestNamespacesInBuilderDoc < Nokogiri::TestCase
|
6
|
-
def setup
|
7
|
-
super
|
8
|
-
b = Nokogiri::XML::Builder.new do |x|
|
9
|
-
x.fruit(:xmlns => 'ns:fruit', :'xmlns:veg' => 'ns:veg', :'xmlns:xlink' => 'http://www.w3.org/1999/xlink') do
|
10
|
-
x.pear { x.bosc }
|
11
|
-
x.orange
|
12
|
-
x[:veg].carrot do
|
13
|
-
x.cheese(:xmlns => 'ns:dairy', :'xlink:href' => 'http://example.com/cheese/')
|
14
|
-
end
|
15
|
-
x[:meat].bacon(:'xmlns:meat' => 'ns:meat') do
|
16
|
-
x.apple :count => 2
|
17
|
-
x[:veg].tomato
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
@doc = b.doc
|
23
|
-
end
|
24
|
-
|
25
|
-
def check_namespace e
|
26
|
-
e.namespace.nil? ? nil : e.namespace.href
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_builder_default_ns
|
30
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root)
|
31
|
-
end
|
32
|
-
def test_builder_parent_default_ns
|
33
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[0])
|
34
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[1])
|
35
|
-
end
|
36
|
-
def test_builder_grandparent_default_ns
|
37
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[0].elements[0])
|
38
|
-
end
|
39
|
-
def test_builder_parent_nondefault_ns
|
40
|
-
assert_equal 'ns:veg', check_namespace(@doc.root.elements[2])
|
41
|
-
end
|
42
|
-
def test_builder_single_decl_ns_1
|
43
|
-
assert_equal 'ns:dairy', check_namespace(@doc.root.elements[2].elements[0])
|
44
|
-
end
|
45
|
-
def test_builder_nondefault_attr_ns
|
46
|
-
assert_equal 'http://www.w3.org/1999/xlink',
|
47
|
-
check_namespace(@doc.root.elements[2].elements[0].attribute_nodes.find { |a| a.name =~ /href/ })
|
48
|
-
end
|
49
|
-
def test_builder_single_decl_ns_2
|
50
|
-
assert_equal 'ns:meat', check_namespace(@doc.root.elements[3])
|
51
|
-
end
|
52
|
-
def test_builder_buried_default_ns
|
53
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[3].elements[0])
|
54
|
-
end
|
55
|
-
def test_builder_buried_decl_ns
|
56
|
-
assert_equal 'ns:veg', check_namespace(@doc.root.elements[3].elements[1])
|
57
|
-
end
|
58
|
-
def test_builder_namespace_count
|
59
|
-
n = @doc.root.clone
|
60
|
-
n.children.each(&:remove)
|
61
|
-
ns_attrs = n.to_xml.scan(/\bxmlns(?::.+?)?=/)
|
62
|
-
assert_equal 3, ns_attrs.length
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_builder_namespaced_attribute_on_unparented_node
|
66
|
-
doc = Nokogiri::XML::Builder.new do |x|
|
67
|
-
x.root('xmlns:foo' => 'http://foo.io') {
|
68
|
-
x.obj('foo:attr' => 'baz')
|
69
|
-
}
|
70
|
-
end.doc
|
71
|
-
assert_equal 'http://foo.io', doc.root.children.first.attribute_nodes.first.namespace.href
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
module Nokogiri
|
4
|
-
module XML
|
5
|
-
class TestNamespacesInClonedDoc < Nokogiri::TestCase
|
6
|
-
def setup
|
7
|
-
super
|
8
|
-
b = Nokogiri::XML::Builder.new do |xml|
|
9
|
-
xml.mods("xmlns"=>"http://www.loc.gov/mods/v3") {
|
10
|
-
xml.name(:type=>"personal") {
|
11
|
-
xml.namePart()
|
12
|
-
}
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
@doc = b.doc
|
17
|
-
@clone = Nokogiri::XML(@doc.to_s)
|
18
|
-
end
|
19
|
-
|
20
|
-
def check_namespace e
|
21
|
-
e.namespace.nil? ? nil : e.namespace.href
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_namespace_ns
|
25
|
-
xpath = '//oxns:name[@type="personal"]'
|
26
|
-
namespaces = {'oxns' => "http://www.loc.gov/mods/v3"}
|
27
|
-
assert_equal @doc.xpath(xpath, namespaces).length, @clone.xpath(xpath, namespaces).length
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
module Nokogiri
|
4
|
-
module XML
|
5
|
-
class TestNamespacesInCreatedDoc < Nokogiri::TestCase
|
6
|
-
def setup
|
7
|
-
super
|
8
|
-
@doc = Nokogiri::XML('<fruit xmlns="ns:fruit" xmlns:veg="ns:veg" xmlns:xlink="http://www.w3.org/1999/xlink"/>')
|
9
|
-
pear = @doc.create_element('pear')
|
10
|
-
bosc = @doc.create_element('bosc')
|
11
|
-
pear.add_child(bosc)
|
12
|
-
@doc.root << pear
|
13
|
-
@doc.root.add_child('<orange/>')
|
14
|
-
carrot = @doc.create_element('veg:carrot')
|
15
|
-
@doc.root << carrot
|
16
|
-
cheese = @doc.create_element('cheese', :xmlns => 'ns:dairy', :'xlink:href' => 'http://example.com/cheese/')
|
17
|
-
carrot << cheese
|
18
|
-
bacon = @doc.create_element('meat:bacon', :'xmlns:meat' => 'ns:meat')
|
19
|
-
apple = @doc.create_element('apple')
|
20
|
-
apple['count'] = 2
|
21
|
-
bacon << apple
|
22
|
-
tomato = @doc.create_element('veg:tomato')
|
23
|
-
bacon << tomato
|
24
|
-
@doc.root << bacon
|
25
|
-
end
|
26
|
-
|
27
|
-
def check_namespace e
|
28
|
-
e.namespace.nil? ? nil : e.namespace.href
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_created_default_ns
|
32
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root)
|
33
|
-
end
|
34
|
-
def test_created_parent_default_ns
|
35
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[0])
|
36
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[1])
|
37
|
-
end
|
38
|
-
def test_created_grandparent_default_ns
|
39
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[0].elements[0])
|
40
|
-
end
|
41
|
-
def test_created_parent_nondefault_ns
|
42
|
-
assert_equal 'ns:veg', check_namespace(@doc.root.elements[2])
|
43
|
-
end
|
44
|
-
def test_created_single_decl_ns_1
|
45
|
-
assert_equal 'ns:dairy', check_namespace(@doc.root.elements[2].elements[0])
|
46
|
-
end
|
47
|
-
def test_created_nondefault_attr_ns
|
48
|
-
assert_equal 'http://www.w3.org/1999/xlink',
|
49
|
-
check_namespace(@doc.root.elements[2].elements[0].attribute_nodes.find { |a| a.name =~ /href/ })
|
50
|
-
end
|
51
|
-
def test_created_single_decl_ns_2
|
52
|
-
assert_equal 'ns:meat', check_namespace(@doc.root.elements[3])
|
53
|
-
end
|
54
|
-
def test_created_buried_default_ns
|
55
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[3].elements[0])
|
56
|
-
end
|
57
|
-
def test_created_buried_decl_ns
|
58
|
-
assert_equal 'ns:veg', check_namespace(@doc.root.elements[3].elements[1])
|
59
|
-
end
|
60
|
-
def test_created_namespace_count
|
61
|
-
n = @doc.root.clone
|
62
|
-
n.children.each(&:remove)
|
63
|
-
ns_attrs = n.to_xml.scan(/\bxmlns(?::.+?)?=/)
|
64
|
-
assert_equal 3, ns_attrs.length
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_created_namespaced_attribute_on_unparented_node
|
68
|
-
doc = Nokogiri::XML('<root xmlns:foo="http://foo.io"/>')
|
69
|
-
node = @doc.create_element('obj', 'foo:attr' => 'baz')
|
70
|
-
doc.root.add_child(node)
|
71
|
-
assert_equal 'http://foo.io', doc.root.children.first.attribute_nodes.first.namespace.href
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
module Nokogiri
|
4
|
-
module XML
|
5
|
-
class TestNamespacesInParsedDoc < Nokogiri::TestCase
|
6
|
-
def setup
|
7
|
-
super
|
8
|
-
@doc = Nokogiri::XML <<-eoxml
|
9
|
-
<fruit xmlns="ns:fruit" xmlns:veg="ns:veg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
10
|
-
<pear>
|
11
|
-
<bosc/>
|
12
|
-
</pear>
|
13
|
-
<orange/>
|
14
|
-
<veg:carrot>
|
15
|
-
<cheese xmlns="ns:dairy" xlink:href="http://example.com/cheese/"/>
|
16
|
-
</veg:carrot>
|
17
|
-
<meat:bacon xmlns:meat="ns:meat">
|
18
|
-
<apple count="2"/>
|
19
|
-
<veg:tomato/>
|
20
|
-
</meat:bacon>
|
21
|
-
</fruit>
|
22
|
-
eoxml
|
23
|
-
end
|
24
|
-
|
25
|
-
def check_namespace e
|
26
|
-
e.namespace.nil? ? nil : e.namespace.href
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_parsed_default_ns
|
30
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root)
|
31
|
-
end
|
32
|
-
def test_parsed_parent_default_ns
|
33
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[0])
|
34
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[1])
|
35
|
-
end
|
36
|
-
def test_parsed_grandparent_default_ns
|
37
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[0].elements[0])
|
38
|
-
end
|
39
|
-
def test_parsed_parent_nondefault_ns
|
40
|
-
assert_equal 'ns:veg', check_namespace(@doc.root.elements[2])
|
41
|
-
end
|
42
|
-
def test_parsed_single_decl_ns_1
|
43
|
-
assert_equal 'ns:dairy', check_namespace(@doc.root.elements[2].elements[0])
|
44
|
-
end
|
45
|
-
def test_parsed_nondefault_attr_ns
|
46
|
-
assert_equal 'http://www.w3.org/1999/xlink',
|
47
|
-
check_namespace(@doc.root.elements[2].elements[0].attribute_nodes.find { |a| a.name =~ /href/ })
|
48
|
-
end
|
49
|
-
def test_parsed_single_decl_ns_2
|
50
|
-
assert_equal 'ns:meat', check_namespace(@doc.root.elements[3])
|
51
|
-
end
|
52
|
-
def test_parsed_buried_default_ns
|
53
|
-
assert_equal 'ns:fruit', check_namespace(@doc.root.elements[3].elements[0])
|
54
|
-
end
|
55
|
-
def test_parsed_buried_decl_ns
|
56
|
-
assert_equal 'ns:veg', check_namespace(@doc.root.elements[3].elements[1])
|
57
|
-
end
|
58
|
-
def test_parsed_namespace_count
|
59
|
-
n = @doc.root.clone
|
60
|
-
n.children.each(&:remove)
|
61
|
-
ns_attrs = n.to_xml.scan(/\bxmlns(?::.+?)?=/)
|
62
|
-
assert_equal 3, ns_attrs.length
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_namespaces_under_memory_pressure_issue1155
|
66
|
-
skip("JRuby doesn't do GC.") if Nokogiri.jruby?
|
67
|
-
|
68
|
-
# this test is here to emit warnings when run under valgrind
|
69
|
-
# see https://github.com/sparklemotion/nokogiri/issues/1155 for background
|
70
|
-
filename = File.join ASSETS_DIR, 'namespace_pressure_test.xml'
|
71
|
-
doc = Nokogiri::XML File.open(filename)
|
72
|
-
|
73
|
-
# bizarrely, can't repro without the call to #to_a
|
74
|
-
doc.xpath('//namespace::*').to_a.each do |ns|
|
75
|
-
ns.inspect
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
module Nokogiri
|
4
|
-
module XML
|
5
|
-
class TestNamespacePreservation < Nokogiri::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@xml = Nokogiri.XML <<-eoxml
|
9
|
-
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
10
|
-
<xs:element xmlns:quer="http://api.geotrust.com/webtrust/query"/>
|
11
|
-
<xs:element xmlns:quer="http://api.geotrust.com/webtrust/query"/>
|
12
|
-
</xs:schema>
|
13
|
-
eoxml
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_xpath
|
17
|
-
first = @xml.at_xpath('//xs:element', 'xs' => 'http://www.w3.org/2001/XMLSchema')
|
18
|
-
last = @xml.at_xpath('//xs:element[last()]', 'xs' => 'http://www.w3.org/2001/XMLSchema')
|
19
|
-
assert_equal 'http://api.geotrust.com/webtrust/query' , first.namespaces['xmlns:quer'], "Should contain quer namespace"
|
20
|
-
assert_equal 'http://api.geotrust.com/webtrust/query' , last.namespaces['xmlns:quer'], "Should contain quer namespace"
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_traversing
|
24
|
-
first = @xml.root.element_children.first
|
25
|
-
last = @xml.root.element_children.last
|
26
|
-
assert_equal 'http://api.geotrust.com/webtrust/query' , first.namespaces['xmlns:quer'], "Should contain quer namespace"
|
27
|
-
assert_equal 'http://api.geotrust.com/webtrust/query' , last.namespaces['xmlns:quer'], "Should contain quer namespace"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/test/test_convert_xpath.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestConvertXPath < Nokogiri::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
@N = Nokogiri(File.read(HTML_FILE))
|
8
|
-
end
|
9
|
-
|
10
|
-
def assert_syntactical_equivalence(hpath, xpath, match, &blk)
|
11
|
-
blk ||= lambda {|j| j.first}
|
12
|
-
assert_equal match, blk.call(@N.search(xpath)), "xpath result did not match"
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_child_tag
|
16
|
-
assert_syntactical_equivalence("h1[a]", ".//h1[child::a]", "Tender Lovemaking") do |j|
|
17
|
-
j.inner_text
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_child_tag_equals
|
22
|
-
assert_syntactical_equivalence("h1[a='Tender Lovemaking']", ".//h1[child::a = 'Tender Lovemaking']", "Tender Lovemaking") do |j|
|
23
|
-
j.inner_text
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_filter_contains
|
28
|
-
assert_syntactical_equivalence("title:contains('Tender')", ".//title[contains(., 'Tender')]",
|
29
|
-
"Tender Lovemaking ") do |j|
|
30
|
-
j.inner_text
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_filter_comment
|
35
|
-
assert_syntactical_equivalence("div comment()[2]", ".//div//comment()[position() = 2]", "<!-- end of header -->") do |j|
|
36
|
-
j.first.to_s
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_filter_text
|
41
|
-
assert_syntactical_equivalence("a[text()]", ".//a[normalize-space(child::text())]", "<a href=\"http://tenderlovemaking.com\">Tender Lovemaking</a>") do |j|
|
42
|
-
j.first.to_s
|
43
|
-
end
|
44
|
-
assert_syntactical_equivalence("a[text()='Tender Lovemaking']", ".//a[normalize-space(child::text()) = 'Tender Lovemaking']", "<a href=\"http://tenderlovemaking.com\">Tender Lovemaking</a>") do |j|
|
45
|
-
j.first.to_s
|
46
|
-
end
|
47
|
-
assert_syntactical_equivalence("a/text()", ".//a/child::text()", "Tender Lovemaking") do |j|
|
48
|
-
j.first.to_s
|
49
|
-
end
|
50
|
-
assert_syntactical_equivalence("h2//a[text()!='Back Home!']", ".//h2//a[normalize-space(child::text()) != 'Back Home!']", "Meow meow meow meow meow") do |j|
|
51
|
-
j.first.inner_text
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_filter_by_attr
|
56
|
-
assert_syntactical_equivalence("a[@href='http://blog.geminigeek.com/wordpress-theme']",
|
57
|
-
".//a[@href = 'http://blog.geminigeek.com/wordpress-theme']",
|
58
|
-
"http://blog.geminigeek.com/wordpress-theme") do |j|
|
59
|
-
j.first["href"]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_css_id
|
64
|
-
assert_syntactical_equivalence("#linkcat-7", ".//*[@id = 'linkcat-7']", "linkcat-7") do |j|
|
65
|
-
j.first["id"]
|
66
|
-
end
|
67
|
-
assert_syntactical_equivalence("li#linkcat-7", ".//li[@id = 'linkcat-7']", "linkcat-7") do |j|
|
68
|
-
j.first["id"]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_css_class
|
73
|
-
assert_syntactical_equivalence(".cat-item-15", ".//*[contains(concat(' ', @class, ' '), ' cat-item-15 ')]",
|
74
|
-
"cat-item cat-item-15") do |j|
|
75
|
-
j.first["class"]
|
76
|
-
end
|
77
|
-
assert_syntactical_equivalence("li.cat-item-15", ".//li[contains(concat(' ', @class, ' '), ' cat-item-15 ')]",
|
78
|
-
"cat-item cat-item-15") do |j|
|
79
|
-
j.first["class"]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_css_tags
|
84
|
-
assert_syntactical_equivalence("div li a", ".//div//li//a", "http://brobinius.org/") do |j|
|
85
|
-
j.first.inner_text
|
86
|
-
end
|
87
|
-
assert_syntactical_equivalence("div li > a", ".//div//li/a", "http://brobinius.org/") do |j|
|
88
|
-
j.first.inner_text
|
89
|
-
end
|
90
|
-
assert_syntactical_equivalence("h1 ~ small", ".//small[preceding-sibling::h1]", "The act of making love, tenderly.") do |j|
|
91
|
-
j.first.inner_text
|
92
|
-
end
|
93
|
-
assert_syntactical_equivalence("h1 ~ small", ".//small[preceding-sibling::h1]", "The act of making love, tenderly.") do |j|
|
94
|
-
j.first.inner_text
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_positional
|
99
|
-
assert_syntactical_equivalence("div/div:first()", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n".gsub(/[\r\n]/, '')) do |j|
|
100
|
-
j.first.inner_text.gsub(/[\r\n]/, '')
|
101
|
-
end
|
102
|
-
assert_syntactical_equivalence("div/div:first", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n".gsub(/[\r\n]/, '')) do |j|
|
103
|
-
j.first.inner_text.gsub(/[\r\n]/, '')
|
104
|
-
end
|
105
|
-
assert_syntactical_equivalence("div//a:last()", ".//div//a[position() = last()]", "Wordpress") do |j|
|
106
|
-
j.last.inner_text
|
107
|
-
end
|
108
|
-
assert_syntactical_equivalence("div//a:last", ".//div//a[position() = last()]", "Wordpress") do |j|
|
109
|
-
j.last.inner_text
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_multiple_filters
|
114
|
-
assert_syntactical_equivalence("a[@rel='bookmark'][1]", ".//a[@rel = 'bookmark' and position() = 1]", "Back Home!") do |j|
|
115
|
-
j.first.inner_text
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# TODO:
|
120
|
-
# doc/'title ~ link' -> links that are siblings of title
|
121
|
-
# doc/'p[@class~="final"]' -> class includes string (whitespacy)
|
122
|
-
# doc/'p[text()*="final"]' -> class includes string (index) (broken: always returns true?)
|
123
|
-
# doc/'p[text()$="final"]' -> /final$/
|
124
|
-
# doc/'p[text()|="final"]' -> /^final$/
|
125
|
-
# doc/'p[text()^="final"]' -> string starts with 'final
|
126
|
-
# nth_first
|
127
|
-
# nth_last
|
128
|
-
# even
|
129
|
-
# odd
|
130
|
-
# first-child, nth-child, last-child, nth-last-child, nth-last-of-type
|
131
|
-
# only-of-type, only-child
|
132
|
-
# parent
|
133
|
-
# empty
|
134
|
-
# root
|
135
|
-
end
|
data/test/test_css_cache.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestCssCache < Nokogiri::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
@css = "a1 > b2 > c3"
|
8
|
-
@parse_result = Nokogiri::CSS.parse(@css)
|
9
|
-
@to_xpath_result = @parse_result.map(&:to_xpath)
|
10
|
-
Nokogiri::CSS::Parser.class_eval do
|
11
|
-
class << @cache
|
12
|
-
alias :old_bracket :[]
|
13
|
-
attr_reader :count
|
14
|
-
def [](key)
|
15
|
-
@count ||= 0
|
16
|
-
@count += 1
|
17
|
-
old_bracket(key)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
assert Nokogiri::CSS::Parser.cache_on?
|
22
|
-
end
|
23
|
-
|
24
|
-
def teardown
|
25
|
-
Nokogiri::CSS::Parser.clear_cache
|
26
|
-
Nokogiri::CSS::Parser.set_cache true
|
27
|
-
end
|
28
|
-
|
29
|
-
[ false, true ].each do |cache_setting|
|
30
|
-
define_method "test_css_cache_#{cache_setting ? "true" : "false"}" do
|
31
|
-
Nokogiri::CSS::Parser.set_cache cache_setting
|
32
|
-
|
33
|
-
Nokogiri::CSS.xpath_for(@css)
|
34
|
-
Nokogiri::CSS.xpath_for(@css)
|
35
|
-
Nokogiri::CSS::Parser.new.xpath_for(@css)
|
36
|
-
Nokogiri::CSS::Parser.new.xpath_for(@css)
|
37
|
-
|
38
|
-
if cache_setting
|
39
|
-
assert_equal(4, Nokogiri::CSS::Parser.class_eval { @cache.count })
|
40
|
-
else
|
41
|
-
assert_nil(Nokogiri::CSS::Parser.class_eval { @cache.count })
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
end
|