tenderlove-nokogiri 0.0.0.20081001111445

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +105 -0
  3. data/README.txt +51 -0
  4. data/Rakefile +70 -0
  5. data/ext/nokogiri/extconf.rb +24 -0
  6. data/ext/nokogiri/html_document.c +85 -0
  7. data/ext/nokogiri/html_document.h +10 -0
  8. data/ext/nokogiri/html_sax_parser.c +32 -0
  9. data/ext/nokogiri/html_sax_parser.h +11 -0
  10. data/ext/nokogiri/native.c +35 -0
  11. data/ext/nokogiri/native.h +32 -0
  12. data/ext/nokogiri/xml_cdata.c +36 -0
  13. data/ext/nokogiri/xml_cdata.h +9 -0
  14. data/ext/nokogiri/xml_document.c +159 -0
  15. data/ext/nokogiri/xml_document.h +10 -0
  16. data/ext/nokogiri/xml_node.c +573 -0
  17. data/ext/nokogiri/xml_node.h +13 -0
  18. data/ext/nokogiri/xml_node_set.c +90 -0
  19. data/ext/nokogiri/xml_node_set.h +9 -0
  20. data/ext/nokogiri/xml_reader.c +420 -0
  21. data/ext/nokogiri/xml_reader.h +10 -0
  22. data/ext/nokogiri/xml_sax_parser.c +161 -0
  23. data/ext/nokogiri/xml_sax_parser.h +10 -0
  24. data/ext/nokogiri/xml_text.c +25 -0
  25. data/ext/nokogiri/xml_text.h +9 -0
  26. data/ext/nokogiri/xml_xpath.c +39 -0
  27. data/ext/nokogiri/xml_xpath.h +11 -0
  28. data/ext/nokogiri/xml_xpath_context.c +69 -0
  29. data/ext/nokogiri/xml_xpath_context.h +9 -0
  30. data/ext/nokogiri/xslt_stylesheet.c +83 -0
  31. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  32. data/lib/nokogiri.rb +45 -0
  33. data/lib/nokogiri/css.rb +6 -0
  34. data/lib/nokogiri/css/node.rb +95 -0
  35. data/lib/nokogiri/css/parser.rb +24 -0
  36. data/lib/nokogiri/css/parser.y +198 -0
  37. data/lib/nokogiri/css/tokenizer.rb +9 -0
  38. data/lib/nokogiri/css/tokenizer.rex +63 -0
  39. data/lib/nokogiri/css/xpath_visitor.rb +153 -0
  40. data/lib/nokogiri/decorators.rb +1 -0
  41. data/lib/nokogiri/decorators/hpricot.rb +3 -0
  42. data/lib/nokogiri/decorators/hpricot/node.rb +47 -0
  43. data/lib/nokogiri/decorators/hpricot/node_set.rb +14 -0
  44. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +13 -0
  45. data/lib/nokogiri/hpricot.rb +46 -0
  46. data/lib/nokogiri/html.rb +64 -0
  47. data/lib/nokogiri/html/builder.rb +9 -0
  48. data/lib/nokogiri/html/document.rb +9 -0
  49. data/lib/nokogiri/html/sax/parser.rb +21 -0
  50. data/lib/nokogiri/version.rb +3 -0
  51. data/lib/nokogiri/xml.rb +29 -0
  52. data/lib/nokogiri/xml/after_handler.rb +18 -0
  53. data/lib/nokogiri/xml/before_handler.rb +32 -0
  54. data/lib/nokogiri/xml/builder.rb +79 -0
  55. data/lib/nokogiri/xml/document.rb +22 -0
  56. data/lib/nokogiri/xml/node.rb +162 -0
  57. data/lib/nokogiri/xml/node_set.rb +136 -0
  58. data/lib/nokogiri/xml/reader.rb +14 -0
  59. data/lib/nokogiri/xml/sax.rb +9 -0
  60. data/lib/nokogiri/xml/sax/document.rb +59 -0
  61. data/lib/nokogiri/xml/sax/parser.rb +33 -0
  62. data/lib/nokogiri/xml/text.rb +6 -0
  63. data/lib/nokogiri/xml/xpath.rb +6 -0
  64. data/lib/nokogiri/xslt.rb +11 -0
  65. data/lib/nokogiri/xslt/stylesheet.rb +6 -0
  66. data/nokogiri.gemspec +33 -0
  67. data/test/css/test_nthiness.rb +141 -0
  68. data/test/css/test_parser.rb +214 -0
  69. data/test/css/test_tokenizer.rb +162 -0
  70. data/test/files/staff.xml +57 -0
  71. data/test/files/staff.xslt +32 -0
  72. data/test/files/tlm.html +850 -0
  73. data/test/helper.rb +70 -0
  74. data/test/hpricot/files/basic.xhtml +17 -0
  75. data/test/hpricot/files/boingboing.html +2266 -0
  76. data/test/hpricot/files/cy0.html +3653 -0
  77. data/test/hpricot/files/immob.html +400 -0
  78. data/test/hpricot/files/pace_application.html +1320 -0
  79. data/test/hpricot/files/tenderlove.html +16 -0
  80. data/test/hpricot/files/uswebgen.html +220 -0
  81. data/test/hpricot/files/utf8.html +1054 -0
  82. data/test/hpricot/files/week9.html +1723 -0
  83. data/test/hpricot/files/why.xml +19 -0
  84. data/test/hpricot/load_files.rb +7 -0
  85. data/test/hpricot/test_alter.rb +67 -0
  86. data/test/hpricot/test_builder.rb +27 -0
  87. data/test/hpricot/test_parser.rb +412 -0
  88. data/test/hpricot/test_paths.rb +15 -0
  89. data/test/hpricot/test_preserved.rb +72 -0
  90. data/test/hpricot/test_xml.rb +26 -0
  91. data/test/html/sax/test_parser.rb +27 -0
  92. data/test/html/test_builder.rb +78 -0
  93. data/test/html/test_document.rb +22 -0
  94. data/test/test_convert_xpath.rb +173 -0
  95. data/test/test_nokogiri.rb +36 -0
  96. data/test/test_reader.rb +222 -0
  97. data/test/test_xslt_transforms.rb +29 -0
  98. data/test/xml/sax/test_parser.rb +93 -0
  99. data/test/xml/test_builder.rb +16 -0
  100. data/test/xml/test_document.rb +141 -0
  101. data/test/xml/test_node.rb +148 -0
  102. data/test/xml/test_node_set.rb +54 -0
  103. data/test/xml/test_text.rb +13 -0
  104. metadata +191 -0
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+ require File.join(File.dirname(__FILE__),"load_files")
3
+
4
+ class TestParser < Nokogiri::TestCase
5
+ include Nokogiri
6
+
7
+ def test_roundtrip
8
+ @basic = Hpricot.parse(TestFiles::BASIC)
9
+ %w[link link[2] body #link1 a p.ohmy].each do |css_sel|
10
+ ele = @basic.at(css_sel)
11
+ assert_equal ele, @basic.at(ele.css_path), ele.css_path
12
+ assert_equal ele, @basic.at(ele.xpath), ele.xpath
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+ require File.join(File.dirname(__FILE__),"load_files")
3
+
4
+ class TestPreserved < Nokogiri::TestCase
5
+ def assert_roundtrip str
6
+ doc = Nokogiri.Hpricot(str)
7
+ yield doc if block_given?
8
+ str2 = doc.to_original_html
9
+ [*str].zip([*str2]).each do |s1, s2|
10
+ assert_equal s1, s2
11
+ end
12
+ end
13
+
14
+ def assert_html str1, str2
15
+ doc = Nokogiri.Hpricot(str2)
16
+ yield doc if block_given?
17
+ assert_equal str1, doc.to_original_html
18
+ end
19
+
20
+ ####
21
+ # Not supporting to_original_html
22
+ #def test_simple
23
+ # str = "<p>Hpricot is a <b>you know <i>uh</b> fine thing.</p>"
24
+ # assert_html str, str
25
+ # assert_html "<p class=\"new\">Hpricot is a <b>you know <i>uh</b> fine thing.</p>", str do |doc|
26
+ # (doc/:p).set('class', 'new')
27
+ # end
28
+ #end
29
+
30
+ ####
31
+ # Not supporting to_original_html
32
+ #def test_parent
33
+ # str = "<html><base href='/'><head><title>Test</title></head><body><div id='wrap'><p>Paragraph one.</p><p>Paragraph two.</p></div></body></html>"
34
+ # assert_html str, str
35
+ # assert_html "<html><base href='/'><body><div id=\"all\"><div><p>Paragraph one.</p></div><div><p>Paragraph two.</p></div></div></body></html>", str do |doc|
36
+ # (doc/:head).remove
37
+ # (doc/:div).set('id', 'all')
38
+ # (doc/:p).wrap('<div></div>')
39
+ # end
40
+ #end
41
+
42
+ def test_escaping_of_contents
43
+ doc = Nokogiri.Hpricot(TestFiles::BOINGBOING)
44
+ assert_equal "Fukuda&#x2019;s Automatic Door opens around your body as you pass through it. The idea is to save energy and keep the room clean.", doc.at("img[@alt='200606131240']").next.to_s.strip
45
+ end
46
+
47
+ ####
48
+ # Modified. No.
49
+ #def test_files
50
+ # assert_roundtrip TestFiles::BASIC
51
+ # assert_roundtrip TestFiles::BOINGBOING
52
+ # assert_roundtrip TestFiles::CY0
53
+ #end
54
+
55
+ ####
56
+ # Modified.. When calling "to_html" on the document, proper html/doc tags
57
+ # are produced too.
58
+ def test_escaping_of_attrs
59
+ # ampersands in URLs
60
+ str = %{<a href="http://google.com/search?q=nokogiri&amp;l=en">Google</a>}
61
+ link = (doc = Nokogiri.Hpricot(str)).at(:a)
62
+ assert_equal "http://google.com/search?q=nokogiri&l=en", link['href']
63
+ assert_equal "http://google.com/search?q=nokogiri&l=en", link.attributes['href']
64
+ assert_equal "http://google.com/search?q=nokogiri&l=en", link.get_attribute('href')
65
+ assert_equal "http://google.com/search?q=nokogiri&l=en", link.raw_attributes['href']
66
+ assert_equal str, link.to_html
67
+
68
+ # alter the url
69
+ link['href'] = "javascript:alert(\"AGGA-KA-BOO!\")"
70
+ assert_equal %{<a href="javascript:alert(&quot;AGGA-KA-BOO!&quot;)">Google</a>}, link.to_html
71
+ end
72
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+ require File.join(File.dirname(__FILE__),"load_files")
3
+
4
+ class TestParser < Nokogiri::TestCase
5
+ include Nokogiri
6
+ # normally, the link tags are empty HTML tags.
7
+ # contributed by laudney.
8
+ def test_normally_empty
9
+ doc = Hpricot::XML("<rss><channel><title>this is title</title><link>http://fake.com</link></channel></rss>")
10
+ assert_equal "this is title", (doc/:rss/:channel/:title).text
11
+ assert_equal "http://fake.com", (doc/:rss/:channel/:link).text
12
+ end
13
+
14
+ # make sure XML doesn't get downcased
15
+ def test_casing
16
+ doc = Hpricot::XML(TestFiles::WHY)
17
+ assert_equal "hourly", (doc.at "sy:updatePeriod").inner_html
18
+ assert_equal 1, (doc/"guid[@isPermaLink]").length
19
+ end
20
+
21
+ # be sure tags named "text" are ok
22
+ def test_text_tags
23
+ doc = Hpricot::XML("<feed><title>City Poisoned</title><text>Rita Lee has poisoned Brazil.</text></feed>")
24
+ assert_equal "City Poisoned", (doc/"title").text
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module HTML
5
+ module SAX
6
+ class TestParser < Nokogiri::SAX::TestCase
7
+ def setup
8
+ @parser = HTML::SAX::Parser.new(Doc.new)
9
+ end
10
+
11
+ def test_parse_file
12
+ @parser.parse_file(HTML_FILE)
13
+ assert_equal 1110, @parser.document.end_elements.length
14
+ end
15
+
16
+ def test_parse_document
17
+ @parser.parse_memory(<<-eoxml)
18
+ <p>Paragraph 1</p>
19
+ <p>Paragraph 2</p>
20
+ eoxml
21
+ assert_equal([["html", []], ["body", []], ["p", []], ["p", []]],
22
+ @parser.document.start_elements)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module HTML
5
+ class TestBuilder < Nokogiri::TestCase
6
+ def test_hash_as_attributes
7
+ builder = Nokogiri::HTML::Builder.new do
8
+ div(:id => 'awesome') {
9
+ h1 "america"
10
+ }
11
+ end
12
+ assert_equal('<div id="awesome"><h1>america</h1></div>',
13
+ builder.to_html.gsub(/\n/, ''))
14
+ end
15
+
16
+ def test_has_ampersand
17
+ builder = Nokogiri::HTML::Builder.new do
18
+ div.rad.thing! {
19
+ text "<awe&some>"
20
+ b "hello & world"
21
+ }
22
+ end
23
+ assert_equal(
24
+ '<div class="rad" id="thing">&lt;awe&amp;some&gt;<b>hello &amp; world</b></div>',
25
+ builder.to_html.gsub(/\n/, ''))
26
+ end
27
+
28
+ def test_multi_tags
29
+ builder = Nokogiri::HTML::Builder.new do
30
+ div.rad.thing! {
31
+ text "<awesome>"
32
+ b "hello"
33
+ }
34
+ end
35
+ assert_equal(
36
+ '<div class="rad" id="thing">&lt;awesome&gt;<b>hello</b></div>',
37
+ builder.doc.to_html.gsub(/\n/, ''))
38
+ end
39
+
40
+ def test_attributes_plus_block
41
+ builder = Nokogiri::HTML::Builder.new do
42
+ div.rad.thing! {
43
+ text "<awesome>"
44
+ }
45
+ end
46
+ assert_equal('<div class="rad" id="thing">&lt;awesome&gt;</div>',
47
+ builder.doc.to_html.chomp)
48
+ end
49
+
50
+ def test_builder_adds_attributes
51
+ builder = Nokogiri::HTML::Builder.new do
52
+ div.rad.thing! "tender div"
53
+ end
54
+ assert_equal('<div class="rad" id="thing">tender div</div>',
55
+ builder.doc.to_html.chomp)
56
+ end
57
+
58
+ def test_bold_tag
59
+ builder = Nokogiri::HTML::Builder.new do
60
+ b "bold tag"
61
+ end
62
+ assert_equal('<b>bold tag</b>', builder.doc.to_html.chomp)
63
+ end
64
+
65
+ def test_html_then_body_tag
66
+ builder = Nokogiri::HTML::Builder.new do
67
+ html {
68
+ body {
69
+ b "bold tag"
70
+ }
71
+ }
72
+ end
73
+ assert_equal('<html><body><b>bold tag</b></body></html>',
74
+ builder.doc.to_html.chomp)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module HTML
5
+ class TestDocument < Nokogiri::TestCase
6
+ def setup
7
+ @html = Nokogiri::HTML.parse(File.read(HTML_FILE))
8
+ end
9
+
10
+ def test_html?
11
+ assert !@html.xml?
12
+ assert @html.html?
13
+ end
14
+
15
+ def test_serialize
16
+ assert @html.serialize
17
+ assert @html.to_html
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,173 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ require 'rubygems'
4
+ require 'hpricot'
5
+
6
+ class TestConvertXPath < Nokogiri::TestCase
7
+
8
+ def setup
9
+ @N = Nokogiri(File.read(HTML_FILE))
10
+ @NH = Nokogiri.Hpricot(File.read(HTML_FILE)) # decorated document
11
+ @H = Hpricot(File.read(HTML_FILE))
12
+ end
13
+
14
+ def assert_syntactical_equivalence(hpath, xpath, match, &blk)
15
+ blk ||= lambda {|j| j.first}
16
+ assert_equal match, blk.call(@N.search(xpath)), "xpath result did not match"
17
+ assert_equal match, blk.call(@H.search(hpath)), "hpath result did not match"
18
+ assert_equal [xpath], @NH.convert_to_xpath(hpath), "converted hpath did not match xpath"
19
+ end
20
+
21
+ def test_ordinary_xpath_conversions
22
+ assert_equal(".//p", @NH.convert_to_xpath("p").first)
23
+ assert_equal(".//p", @NH.convert_to_xpath(:p).first)
24
+ assert_equal(".//p", @NH.convert_to_xpath("//p").first)
25
+ assert_equal(".//p", @NH.convert_to_xpath(".//p").first)
26
+ end
27
+
28
+ def test_child_tag
29
+ assert_syntactical_equivalence("h1[a]", ".//h1[child::a]", "Tender Lovemaking") do |j|
30
+ j.inner_text
31
+ end
32
+ end
33
+
34
+ def test_child_tag_equals
35
+ assert_syntactical_equivalence("h1[a='Tender Lovemaking']", ".//h1[child::a = 'Tender Lovemaking']", "Tender Lovemaking") do |j|
36
+ j.inner_text
37
+ end
38
+ end
39
+
40
+ def test_filter_contains
41
+ assert_syntactical_equivalence("title:contains('Tender')", ".//title[contains(., 'Tender')]",
42
+ "Tender Lovemaking ") do |j|
43
+ j.inner_text
44
+ end
45
+ end
46
+
47
+ def test_filter_comment
48
+ assert_syntactical_equivalence("div comment()[2]", ".//div//comment()[position() = 2]", "<!-- end of header -->") do |j|
49
+ j.first.to_s
50
+ end
51
+ end
52
+
53
+ def test_filter_text
54
+ assert_syntactical_equivalence("a[text()]", ".//a[normalize-space(child::text())]", "<a href=\"http://tenderlovemaking.com\">Tender Lovemaking</a>") do |j|
55
+ j.first.to_s
56
+ end
57
+ assert_syntactical_equivalence("a[text()='Tender Lovemaking']", ".//a[normalize-space(child::text()) = 'Tender Lovemaking']", "<a href=\"http://tenderlovemaking.com\">Tender Lovemaking</a>") do |j|
58
+ j.first.to_s
59
+ end
60
+ assert_syntactical_equivalence("a/text()", ".//a/child::text()", "Tender Lovemaking") do |j|
61
+ j.first.to_s
62
+ end
63
+ assert_syntactical_equivalence("h2//a[text()!='Back Home!']", ".//h2//a[normalize-space(child::text()) != 'Back Home!']", "Meow meow meow meow meow") do |j|
64
+ j.first.inner_text
65
+ end
66
+ end
67
+
68
+ def test_filter_by_attr
69
+ assert_syntactical_equivalence("a[@href='http://blog.geminigeek.com/wordpress-theme']",
70
+ ".//a[@href = 'http://blog.geminigeek.com/wordpress-theme']",
71
+ "http://blog.geminigeek.com/wordpress-theme") do |j|
72
+ j.first["href"]
73
+ end
74
+ end
75
+
76
+ def test_css_id
77
+ assert_syntactical_equivalence("#linkcat-7", ".//*[@id = 'linkcat-7']", "linkcat-7") do |j|
78
+ j.first["id"]
79
+ end
80
+ assert_syntactical_equivalence("li#linkcat-7", ".//li[@id = 'linkcat-7']", "linkcat-7") do |j|
81
+ j.first["id"]
82
+ end
83
+ end
84
+
85
+ def test_css_class
86
+ assert_syntactical_equivalence(".cat-item-15", ".//*[contains(@class, 'cat-item-15')]",
87
+ "cat-item cat-item-15") do |j|
88
+ j.first["class"]
89
+ end
90
+ assert_syntactical_equivalence("li.cat-item-15", ".//li[contains(@class, 'cat-item-15')]",
91
+ "cat-item cat-item-15") do |j|
92
+ j.first["class"]
93
+ end
94
+ end
95
+
96
+ def test_css_tags
97
+ assert_syntactical_equivalence("div li a", ".//div//li//a", "http://brobinius.org/") do |j|
98
+ j.first.inner_text
99
+ end
100
+ assert_syntactical_equivalence("div li > a", ".//div//li/a", "http://brobinius.org/") do |j|
101
+ j.first.inner_text
102
+ end
103
+ assert_syntactical_equivalence("h1 ~ small", ".//small[preceding-sibling::h1]", "The act of making love, tenderly.") do |j|
104
+ j.first.inner_text
105
+ end
106
+ assert_syntactical_equivalence("h1 ~ small", ".//small[preceding-sibling::h1]", "The act of making love, tenderly.") do |j|
107
+ j.first.inner_text
108
+ end
109
+ end
110
+
111
+ def test_positional
112
+ ##
113
+ # we are intentionally NOT staying compatible with nth-and-friends, as Hpricot has an OB1 bug.
114
+ #
115
+ # assert_syntactical_equivalence("div > div:eq(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
116
+ # j.first.inner_text
117
+ # end
118
+ # assert_syntactical_equivalence("div/div:eq(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
119
+ # j.first.inner_text
120
+ # end
121
+ # assert_syntactical_equivalence("div/div:nth(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
122
+ # j.first.inner_text
123
+ # end
124
+ # assert_syntactical_equivalence("div/div:nth-of-type(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
125
+ # j.first.inner_text
126
+ # end
127
+ assert_syntactical_equivalence("div/div:first()", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
128
+ j.first.inner_text
129
+ end
130
+ assert_syntactical_equivalence("div/div:first", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
131
+ j.first.inner_text
132
+ end
133
+ assert_syntactical_equivalence("div//a:last()", ".//div//a[position() = last()]", "Wordpress") do |j|
134
+ j.last.inner_text
135
+ end
136
+ assert_syntactical_equivalence("div//a:last", ".//div//a[position() = last()]", "Wordpress") do |j|
137
+ j.last.inner_text
138
+ end
139
+ end
140
+
141
+ def test_multiple_filters
142
+ assert_syntactical_equivalence("a[@rel='bookmark'][1]", ".//a[@rel = 'bookmark' and position() = 1]", "Back Home!") do |j|
143
+ j.first.inner_text
144
+ end
145
+ end
146
+
147
+ ##
148
+ # 'and' is not supported by hpricot
149
+ # def test_and
150
+ # assert_syntactical_equivalence("div[h1 and small]", ".//div[h1 and small]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
151
+ # j.inner_text
152
+ # end
153
+ # end
154
+
155
+
156
+
157
+ # TODO:
158
+ # doc/'title ~ link' -> links that are siblings of title
159
+ # doc/'p[@class~="final"]' -> class includes string (whitespacy)
160
+ # doc/'p[text()*="final"]' -> class includes string (index) (broken: always returns true?)
161
+ # doc/'p[text()$="final"]' -> /final$/
162
+ # doc/'p[text()|="final"]' -> /^final$/
163
+ # doc/'p[text()^="final"]' -> string starts with 'final
164
+ # nth_first
165
+ # nth_last
166
+ # even
167
+ # odd
168
+ # first-child, nth-child, last-child, nth-last-child, nth-last-of-type
169
+ # only-of-type, only-child
170
+ # parent
171
+ # empty
172
+ # root
173
+ end
@@ -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