nokogiri 1.8.5-java → 1.9.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.

Files changed (160) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +0 -1
  3. data/ext/java/nokogiri/XmlAttr.java +3 -1
  4. data/ext/java/nokogiri/XmlDtd.java +20 -16
  5. data/ext/java/nokogiri/XmlElement.java +6 -6
  6. data/ext/java/nokogiri/XmlNode.java +29 -9
  7. data/ext/java/nokogiri/XmlNodeSet.java +258 -77
  8. data/ext/java/nokogiri/XmlXpathContext.java +10 -12
  9. data/ext/java/nokogiri/internals/NokogiriHelpers.java +25 -23
  10. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +5 -5
  11. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +11 -10
  12. data/ext/java/{org/apache/xml/dtm/ref/dom2dtm/DOM2DTMExt.java → nokogiri/internals/dom2dtm/DOM2DTM.java} +3 -7
  13. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +685 -0
  14. data/ext/nokogiri/extconf.rb +10 -6
  15. data/ext/nokogiri/xml_attr.c +26 -21
  16. data/ext/nokogiri/xml_document.c +4 -1
  17. data/ext/nokogiri/xml_namespace.c +3 -3
  18. data/ext/nokogiri/xml_namespace.h +1 -2
  19. data/ext/nokogiri/xml_node.c +55 -15
  20. data/lib/nokogiri/css/parser.rb +61 -61
  21. data/lib/nokogiri/nokogiri.jar +0 -0
  22. data/lib/nokogiri/version.rb +1 -1
  23. data/lib/nokogiri/xml/document_fragment.rb +11 -0
  24. data/lib/nokogiri/xml/node.rb +12 -0
  25. data/lib/nokogiri/xml/node_set.rb +4 -8
  26. data/lib/xercesImpl.jar +0 -0
  27. metadata +17 -152
  28. data/.autotest +0 -22
  29. data/.cross_rubies +0 -8
  30. data/.editorconfig +0 -17
  31. data/.gemtest +0 -0
  32. data/.travis.yml +0 -63
  33. data/CHANGELOG.md +0 -1368
  34. data/CONTRIBUTING.md +0 -42
  35. data/C_CODING_STYLE.rdoc +0 -33
  36. data/Gemfile +0 -23
  37. data/Gemfile-libxml-ruby +0 -3
  38. data/Manifest.txt +0 -370
  39. data/ROADMAP.md +0 -111
  40. data/Rakefile +0 -348
  41. data/SECURITY.md +0 -19
  42. data/STANDARD_RESPONSES.md +0 -47
  43. data/Y_U_NO_GEMSPEC.md +0 -155
  44. data/appveyor.yml +0 -29
  45. data/build_all +0 -44
  46. data/patches/sort-patches-by-date +0 -25
  47. data/suppressions/README.txt +0 -1
  48. data/suppressions/nokogiri_ruby-2.supp +0 -10
  49. data/tasks/test.rb +0 -100
  50. data/test/css/test_nthiness.rb +0 -226
  51. data/test/css/test_parser.rb +0 -386
  52. data/test/css/test_tokenizer.rb +0 -215
  53. data/test/css/test_xpath_visitor.rb +0 -96
  54. data/test/decorators/test_slop.rb +0 -23
  55. data/test/files/2ch.html +0 -108
  56. data/test/files/GH_1042.html +0 -18
  57. data/test/files/address_book.rlx +0 -12
  58. data/test/files/address_book.xml +0 -10
  59. data/test/files/atom.xml +0 -344
  60. data/test/files/bar/bar.xsd +0 -4
  61. data/test/files/bogus.xml +0 -0
  62. data/test/files/dont_hurt_em_why.xml +0 -422
  63. data/test/files/encoding.html +0 -82
  64. data/test/files/encoding.xhtml +0 -84
  65. data/test/files/exslt.xml +0 -8
  66. data/test/files/exslt.xslt +0 -35
  67. data/test/files/foo/foo.xsd +0 -4
  68. data/test/files/metacharset.html +0 -10
  69. data/test/files/namespace_pressure_test.xml +0 -1684
  70. data/test/files/noencoding.html +0 -47
  71. data/test/files/po.xml +0 -32
  72. data/test/files/po.xsd +0 -66
  73. data/test/files/saml/saml20assertion_schema.xsd +0 -283
  74. data/test/files/saml/saml20protocol_schema.xsd +0 -302
  75. data/test/files/saml/xenc_schema.xsd +0 -146
  76. data/test/files/saml/xmldsig_schema.xsd +0 -318
  77. data/test/files/shift_jis.html +0 -10
  78. data/test/files/shift_jis.xml +0 -5
  79. data/test/files/shift_jis_no_charset.html +0 -9
  80. data/test/files/slow-xpath.xml +0 -25509
  81. data/test/files/snuggles.xml +0 -3
  82. data/test/files/staff.dtd +0 -10
  83. data/test/files/staff.xml +0 -59
  84. data/test/files/staff.xslt +0 -32
  85. data/test/files/test_document_url/bar.xml +0 -2
  86. data/test/files/test_document_url/document.dtd +0 -4
  87. data/test/files/test_document_url/document.xml +0 -6
  88. data/test/files/tlm.html +0 -851
  89. data/test/files/to_be_xincluded.xml +0 -2
  90. data/test/files/valid_bar.xml +0 -2
  91. data/test/files/xinclude.xml +0 -4
  92. data/test/helper.rb +0 -271
  93. data/test/html/sax/test_parser.rb +0 -168
  94. data/test/html/sax/test_parser_context.rb +0 -46
  95. data/test/html/sax/test_parser_text.rb +0 -163
  96. data/test/html/sax/test_push_parser.rb +0 -87
  97. data/test/html/test_attributes.rb +0 -85
  98. data/test/html/test_builder.rb +0 -164
  99. data/test/html/test_document.rb +0 -712
  100. data/test/html/test_document_encoding.rb +0 -143
  101. data/test/html/test_document_fragment.rb +0 -310
  102. data/test/html/test_element_description.rb +0 -105
  103. data/test/html/test_named_characters.rb +0 -14
  104. data/test/html/test_node.rb +0 -212
  105. data/test/html/test_node_encoding.rb +0 -91
  106. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
  107. data/test/namespaces/test_namespaces_aliased_default.rb +0 -24
  108. data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
  109. data/test/namespaces/test_namespaces_in_cloned_doc.rb +0 -31
  110. data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
  111. data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -80
  112. data/test/namespaces/test_namespaces_preservation.rb +0 -31
  113. data/test/test_convert_xpath.rb +0 -135
  114. data/test/test_css_cache.rb +0 -47
  115. data/test/test_encoding_handler.rb +0 -48
  116. data/test/test_memory_leak.rb +0 -156
  117. data/test/test_nokogiri.rb +0 -138
  118. data/test/test_soap4r_sax.rb +0 -52
  119. data/test/test_xslt_transforms.rb +0 -314
  120. data/test/xml/node/test_save_options.rb +0 -28
  121. data/test/xml/node/test_subclass.rb +0 -44
  122. data/test/xml/sax/test_parser.rb +0 -402
  123. data/test/xml/sax/test_parser_context.rb +0 -115
  124. data/test/xml/sax/test_parser_text.rb +0 -202
  125. data/test/xml/sax/test_push_parser.rb +0 -265
  126. data/test/xml/test_attr.rb +0 -74
  127. data/test/xml/test_attribute_decl.rb +0 -86
  128. data/test/xml/test_builder.rb +0 -341
  129. data/test/xml/test_c14n.rb +0 -180
  130. data/test/xml/test_cdata.rb +0 -54
  131. data/test/xml/test_comment.rb +0 -40
  132. data/test/xml/test_document.rb +0 -982
  133. data/test/xml/test_document_encoding.rb +0 -31
  134. data/test/xml/test_document_fragment.rb +0 -298
  135. data/test/xml/test_dtd.rb +0 -187
  136. data/test/xml/test_dtd_encoding.rb +0 -31
  137. data/test/xml/test_element_content.rb +0 -56
  138. data/test/xml/test_element_decl.rb +0 -73
  139. data/test/xml/test_entity_decl.rb +0 -122
  140. data/test/xml/test_entity_reference.rb +0 -262
  141. data/test/xml/test_namespace.rb +0 -96
  142. data/test/xml/test_node.rb +0 -1325
  143. data/test/xml/test_node_attributes.rb +0 -115
  144. data/test/xml/test_node_encoding.rb +0 -75
  145. data/test/xml/test_node_inheritance.rb +0 -32
  146. data/test/xml/test_node_reparenting.rb +0 -592
  147. data/test/xml/test_node_set.rb +0 -809
  148. data/test/xml/test_parse_options.rb +0 -64
  149. data/test/xml/test_processing_instruction.rb +0 -30
  150. data/test/xml/test_reader.rb +0 -620
  151. data/test/xml/test_reader_encoding.rb +0 -134
  152. data/test/xml/test_relax_ng.rb +0 -60
  153. data/test/xml/test_schema.rb +0 -142
  154. data/test/xml/test_syntax_error.rb +0 -36
  155. data/test/xml/test_text.rb +0 -60
  156. data/test/xml/test_unparented_node.rb +0 -483
  157. data/test/xml/test_xinclude.rb +0 -83
  158. data/test/xml/test_xpath.rb +0 -470
  159. data/test/xslt/test_custom_functions.rb +0 -133
  160. 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
@@ -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
@@ -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