nokogiri 1.3.0-x86-mswin32
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 +27 -0
- data/CHANGELOG.ja.rdoc +233 -0
- data/CHANGELOG.rdoc +222 -0
- data/Manifest.txt +247 -0
- data/README.ja.rdoc +103 -0
- data/README.rdoc +117 -0
- data/Rakefile +205 -0
- data/bin/nokogiri +47 -0
- data/ext/nokogiri/extconf.rb +89 -0
- data/ext/nokogiri/html_document.c +183 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +272 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +30 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser.c +57 -0
- data/ext/nokogiri/html_sax_parser.h +11 -0
- data/ext/nokogiri/iconv.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/nokogiri.c +81 -0
- data/ext/nokogiri/nokogiri.h +149 -0
- data/ext/nokogiri/xml_attr.c +92 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_cdata.c +53 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +51 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +308 -0
- data/ext/nokogiri/xml_document.h +21 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +102 -0
- data/ext/nokogiri/xml_dtd.h +8 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +24 -0
- data/ext/nokogiri/xml_io.h +10 -0
- data/ext/nokogiri/xml_namespace.c +69 -0
- data/ext/nokogiri/xml_namespace.h +12 -0
- data/ext/nokogiri/xml_node.c +928 -0
- data/ext/nokogiri/xml_node.h +14 -0
- data/ext/nokogiri/xml_node_set.c +386 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +572 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- 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 +336 -0
- data/ext/nokogiri/xml_sax_parser.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +86 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +107 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +203 -0
- data/ext/nokogiri/xml_syntax_error.h +12 -0
- data/ext/nokogiri/xml_text.c +47 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +53 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +252 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +131 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/action-nokogiri.rb +36 -0
- data/lib/nokogiri.rb +110 -0
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css.rb +25 -0
- data/lib/nokogiri/css/generated_parser.rb +748 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +144 -0
- data/lib/nokogiri/css/node.rb +107 -0
- data/lib/nokogiri/css/parser.rb +82 -0
- data/lib/nokogiri/css/parser.y +227 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +11 -0
- data/lib/nokogiri/css/tokenizer.rex +54 -0
- data/lib/nokogiri/css/xpath_visitor.rb +172 -0
- data/lib/nokogiri/decorators.rb +2 -0
- data/lib/nokogiri/decorators/hpricot.rb +3 -0
- data/lib/nokogiri/decorators/hpricot/node.rb +56 -0
- data/lib/nokogiri/decorators/hpricot/node_set.rb +54 -0
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +30 -0
- data/lib/nokogiri/decorators/slop.rb +33 -0
- 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 +62 -0
- data/lib/nokogiri/html.rb +34 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +71 -0
- 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 +13 -0
- data/lib/nokogiri/html/sax/parser.rb +47 -0
- data/lib/nokogiri/nokogiri.rb +1 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +29 -0
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +62 -0
- data/lib/nokogiri/xml/attr.rb +9 -0
- data/lib/nokogiri/xml/builder.rb +254 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/document.rb +100 -0
- data/lib/nokogiri/xml/document_fragment.rb +49 -0
- data/lib/nokogiri/xml/dtd.rb +11 -0
- data/lib/nokogiri/xml/entity_declaration.rb +11 -0
- data/lib/nokogiri/xml/fragment_handler.rb +55 -0
- data/lib/nokogiri/xml/namespace.rb +7 -0
- data/lib/nokogiri/xml/node.rb +745 -0
- data/lib/nokogiri/xml/node/save_options.rb +42 -0
- data/lib/nokogiri/xml/node_set.rb +238 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +80 -0
- data/lib/nokogiri/xml/processing_instruction.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +66 -0
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +3 -0
- data/lib/nokogiri/xml/sax/document.rb +143 -0
- data/lib/nokogiri/xml/sax/parser.rb +101 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/schema.rb +65 -0
- data/lib/nokogiri/xml/syntax_error.rb +34 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +48 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xsd/xmlparser/nokogiri.rb +64 -0
- data/tasks/test.rb +161 -0
- data/test/css/test_nthiness.rb +160 -0
- data/test/css/test_parser.rb +277 -0
- data/test/css/test_tokenizer.rb +176 -0
- data/test/css/test_xpath_visitor.rb +76 -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/dont_hurt_em_why.xml +422 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/helper.rb +123 -0
- data/test/hpricot/files/basic.xhtml +17 -0
- data/test/hpricot/files/boingboing.html +2266 -0
- data/test/hpricot/files/cy0.html +3653 -0
- data/test/hpricot/files/immob.html +400 -0
- data/test/hpricot/files/pace_application.html +1320 -0
- data/test/hpricot/files/tenderlove.html +16 -0
- data/test/hpricot/files/uswebgen.html +220 -0
- data/test/hpricot/files/utf8.html +1054 -0
- data/test/hpricot/files/week9.html +1723 -0
- data/test/hpricot/files/why.xml +19 -0
- data/test/hpricot/load_files.rb +11 -0
- data/test/hpricot/test_alter.rb +68 -0
- data/test/hpricot/test_builder.rb +20 -0
- data/test/hpricot/test_parser.rb +426 -0
- data/test/hpricot/test_paths.rb +15 -0
- data/test/hpricot/test_preserved.rb +77 -0
- data/test/hpricot/test_xml.rb +30 -0
- data/test/html/sax/test_parser.rb +52 -0
- data/test/html/test_builder.rb +156 -0
- data/test/html/test_document.rb +361 -0
- data/test/html/test_document_encoding.rb +46 -0
- data/test/html/test_document_fragment.rb +97 -0
- data/test/html/test_element_description.rb +95 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +165 -0
- data/test/test_convert_xpath.rb +186 -0
- data/test/test_css_cache.rb +56 -0
- data/test/test_gc.rb +15 -0
- data/test/test_memory_leak.rb +77 -0
- data/test/test_nokogiri.rb +127 -0
- data/test/test_reader.rb +316 -0
- data/test/test_xslt_transforms.rb +131 -0
- data/test/xml/node/test_save_options.rb +20 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +169 -0
- data/test/xml/sax/test_push_parser.rb +92 -0
- data/test/xml/test_attr.rb +38 -0
- data/test/xml/test_builder.rb +73 -0
- data/test/xml/test_cdata.rb +38 -0
- data/test/xml/test_comment.rb +23 -0
- data/test/xml/test_document.rb +397 -0
- data/test/xml/test_document_encoding.rb +26 -0
- data/test/xml/test_document_fragment.rb +76 -0
- data/test/xml/test_dtd.rb +42 -0
- data/test/xml/test_dtd_encoding.rb +31 -0
- data/test/xml/test_entity_reference.rb +21 -0
- data/test/xml/test_namespace.rb +43 -0
- data/test/xml/test_node.rb +808 -0
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +84 -0
- data/test/xml/test_node_set.rb +368 -0
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +126 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +65 -0
- data/test/xml/test_text.rb +18 -0
- data/test/xml/test_unparented_node.rb +381 -0
- data/test/xml/test_xpath.rb +106 -0
- metadata +409 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "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 {|ast| ast.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
|
+
times = cache_setting ? 4 : nil
|
32
|
+
|
33
|
+
Nokogiri::CSS::Parser.set_cache cache_setting
|
34
|
+
|
35
|
+
Nokogiri::CSS.xpath_for(@css)
|
36
|
+
Nokogiri::CSS.xpath_for(@css)
|
37
|
+
Nokogiri::CSS::Parser.new.xpath_for(@css)
|
38
|
+
Nokogiri::CSS::Parser.new.xpath_for(@css)
|
39
|
+
|
40
|
+
assert_equal(times, Nokogiri::CSS::Parser.class_eval { @cache.count })
|
41
|
+
end
|
42
|
+
|
43
|
+
define_method "test_hpricot_cache_#{cache_setting ? "true" : "false"}" do
|
44
|
+
times = cache_setting ? 2 : nil
|
45
|
+
Nokogiri::CSS::Parser.set_cache cache_setting
|
46
|
+
|
47
|
+
nh = Nokogiri.Hpricot("<html></html>")
|
48
|
+
|
49
|
+
nh.convert_to_xpath(@css)
|
50
|
+
nh.convert_to_xpath(@css)
|
51
|
+
assert_equal(times, Nokogiri::CSS::Parser.class_eval { @cache.count })
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
data/test/test_gc.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
|
+
|
3
|
+
class TestGc < Nokogiri::TestCase
|
4
|
+
|
5
|
+
def test_dont_hurt_em_why
|
6
|
+
content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
|
7
|
+
ndoc = Nokogiri::XML(content)
|
8
|
+
2.times do
|
9
|
+
info = ndoc.search('status text').first.inner_text
|
10
|
+
url = ndoc.search('user name').first.inner_text
|
11
|
+
GC.start
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
|
+
|
3
|
+
class TestMemoryLeak < Nokogiri::TestCase
|
4
|
+
|
5
|
+
if ENV['NOKOGIRI_GC'] # turning these off by default for now
|
6
|
+
|
7
|
+
def test_for_memory_leak
|
8
|
+
begin
|
9
|
+
# we don't use Dike in any tests, but requiring it has side effects
|
10
|
+
# that can create memory leaks, and that's what we're testing for.
|
11
|
+
require 'rubygems'
|
12
|
+
require 'dike' # do not remove!
|
13
|
+
|
14
|
+
count_start = count_object_space_documents
|
15
|
+
xml_data = <<-EOS
|
16
|
+
<test>
|
17
|
+
<items>
|
18
|
+
<item>abc</item>
|
19
|
+
<item>1234</item>
|
20
|
+
<item>Zzz</item>
|
21
|
+
<items>
|
22
|
+
</test>
|
23
|
+
EOS
|
24
|
+
20.times do
|
25
|
+
doc = Nokogiri::XML(xml_data)
|
26
|
+
doc.xpath("//item")
|
27
|
+
end
|
28
|
+
2.times { GC.start }
|
29
|
+
count_end = count_object_space_documents
|
30
|
+
assert((count_end - count_start) <= 2, "memory leak detected")
|
31
|
+
rescue LoadError
|
32
|
+
puts "\ndike is not installed, skipping memory leak test"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if Nokogiri.ffi?
|
37
|
+
[ ['Node', 'p', nil],
|
38
|
+
['CDATA', nil, 'content'],
|
39
|
+
['Comment', nil, 'content'],
|
40
|
+
['DocumentFragment', nil],
|
41
|
+
['EntityReference', nil, 'p'],
|
42
|
+
['ProcessingInstruction', nil, 'p', 'content'] ].each do |klass, *args|
|
43
|
+
|
44
|
+
define_method "test_for_leaked_#{klass}_nodes" do
|
45
|
+
Nokogiri::LibXML.expects(:xmlAddChild).at_least(1) # more than once shows we're GCing properly
|
46
|
+
10.times {
|
47
|
+
xml = Nokogiri::XML("<root></root>")
|
48
|
+
2.times { Nokogiri::XML.const_get(klass).new(*(args.collect{|arg| arg || xml})) }
|
49
|
+
GC.start
|
50
|
+
}
|
51
|
+
GC.start
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_for_leaked_attr_nodes
|
57
|
+
Nokogiri::LibXML.expects(:xmlFreePropList).at_least(1) # more than once shows we're GCing properly
|
58
|
+
10.times {
|
59
|
+
xml = Nokogiri::XML("<root></root>")
|
60
|
+
2.times { Nokogiri::XML::Attr.new(xml, "p") }
|
61
|
+
GC.start
|
62
|
+
}
|
63
|
+
GC.start
|
64
|
+
end
|
65
|
+
|
66
|
+
end # if ffi
|
67
|
+
|
68
|
+
end # if NOKOGIRI_GC
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def count_object_space_documents
|
73
|
+
count = 0
|
74
|
+
ObjectSpace.each_object {|j| count += 1 if j.is_a?(Nokogiri::XML::Document) }
|
75
|
+
count
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
2
|
+
|
3
|
+
class TestNokogiri < Nokogiri::TestCase
|
4
|
+
def test_versions
|
5
|
+
version_match = /\d+\.\d+\.\d+/
|
6
|
+
assert_match version_match, Nokogiri::VERSION
|
7
|
+
assert_match version_match, Nokogiri::LIBXML_VERSION
|
8
|
+
|
9
|
+
if defined?(FFI)
|
10
|
+
assert_equal 'ffi', Nokogiri::VERSION_INFO['libxml']['binding']
|
11
|
+
if RUBY_PLATFORM =~ /java/
|
12
|
+
assert_equal 'jruby', Nokogiri::VERSION_INFO['libxml']['platform']
|
13
|
+
else
|
14
|
+
assert_equal 'ruby', Nokogiri::VERSION_INFO['libxml']['platform']
|
15
|
+
end
|
16
|
+
assert Nokogiri.ffi?
|
17
|
+
else
|
18
|
+
assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']
|
19
|
+
|
20
|
+
assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
|
21
|
+
assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']
|
22
|
+
assert ! Nokogiri.ffi?
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_match version_match, Nokogiri::VERSION_INFO['libxml']['loaded']
|
26
|
+
Nokogiri::LIBXML_PARSER_VERSION =~ /(\d)(\d{2})(\d{2})/
|
27
|
+
major = $1.to_i
|
28
|
+
minor = $2.to_i
|
29
|
+
bug = $3.to_i
|
30
|
+
assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_xml?
|
34
|
+
doc = Nokogiri.parse(File.read(XML_FILE))
|
35
|
+
assert doc.xml?
|
36
|
+
assert !doc.html?
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_html?
|
40
|
+
doc = Nokogiri.parse(File.read(HTML_FILE))
|
41
|
+
assert !doc.xml?
|
42
|
+
assert doc.html?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_nokogiri_method_with_html
|
46
|
+
doc1 = Nokogiri(File.read(HTML_FILE))
|
47
|
+
doc2 = Nokogiri.parse(File.read(HTML_FILE))
|
48
|
+
assert_equal doc1.serialize, doc2.serialize
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_nokogiri_method_with_block
|
52
|
+
doc = Nokogiri { b "bold tag" }
|
53
|
+
assert_equal('<b>bold tag</b>', doc.to_html.chomp)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_make_with_html
|
57
|
+
doc = Nokogiri.make("<b>bold tag</b>")
|
58
|
+
assert_equal('<b>bold tag</b>', doc.to_html.chomp)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_make_with_block
|
62
|
+
doc = Nokogiri.make { b "bold tag" }
|
63
|
+
assert_equal('<b>bold tag</b>', doc.to_html.chomp)
|
64
|
+
end
|
65
|
+
|
66
|
+
SLOP_HTML = <<-END
|
67
|
+
<html>
|
68
|
+
<body>
|
69
|
+
<ul>
|
70
|
+
<li class='red'>one</li>
|
71
|
+
<li class='blue'>two</li>
|
72
|
+
</ul>
|
73
|
+
<div>
|
74
|
+
one
|
75
|
+
<div>div two</div>
|
76
|
+
</div>
|
77
|
+
</body>
|
78
|
+
</html>
|
79
|
+
END
|
80
|
+
|
81
|
+
def test_slop_css
|
82
|
+
doc = Nokogiri::Slop(<<-eohtml)
|
83
|
+
<html>
|
84
|
+
<body>
|
85
|
+
<div>
|
86
|
+
one
|
87
|
+
<div class='foo'>
|
88
|
+
div two
|
89
|
+
<div class='foo'>
|
90
|
+
div three
|
91
|
+
</div>
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
</body>
|
95
|
+
</html>
|
96
|
+
eohtml
|
97
|
+
assert_equal "div", doc.html.body.div.div('.foo').name
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_slop
|
101
|
+
doc = Nokogiri::Slop(SLOP_HTML)
|
102
|
+
|
103
|
+
assert_equal "one", doc.html.body.ul.li.first.text
|
104
|
+
assert_equal "two", doc.html.body.ul.li(".blue").text
|
105
|
+
assert_equal "div two", doc.html.body.div.div.text
|
106
|
+
|
107
|
+
assert_equal "two", doc.html.body.ul.li(:css => ".blue").text
|
108
|
+
|
109
|
+
assert_equal "two", doc.html.body.ul.li(:xpath => "position()=2").text
|
110
|
+
assert_equal "one", doc.html.body.ul.li(:xpath => ["contains(text(),'o')"]).first.text
|
111
|
+
assert_equal "two", doc.html.body.ul.li(:xpath => ["contains(text(),'o')","contains(text(),'t')"]).text
|
112
|
+
|
113
|
+
assert_raise(NoMethodError) { doc.nonexistent }
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_slop_decorator
|
117
|
+
doc = Nokogiri(SLOP_HTML)
|
118
|
+
assert !doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)
|
119
|
+
|
120
|
+
doc.slop!
|
121
|
+
assert doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)
|
122
|
+
|
123
|
+
doc.slop!
|
124
|
+
assert_equal 1, doc.decorators(Nokogiri::XML::Node).select { |d| d == Nokogiri::Decorators::Slop }.size
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
data/test/test_reader.rb
ADDED
@@ -0,0 +1,316 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
3
|
+
|
4
|
+
class TestReader < Nokogiri::TestCase
|
5
|
+
def test_from_io_sets_io_as_source
|
6
|
+
io = StringIO.new(<<-eoxml)
|
7
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
8
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
9
|
+
</x>
|
10
|
+
eoxml
|
11
|
+
reader = Nokogiri::XML::Reader.from_io(io)
|
12
|
+
assert_equal io, reader.source
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_reader_takes_block
|
16
|
+
options = nil
|
17
|
+
Nokogiri::XML::Reader(File.read(XML_FILE), XML_FILE) do |cfg|
|
18
|
+
options = cfg
|
19
|
+
options.nonet.nowarning.dtdattr
|
20
|
+
end
|
21
|
+
assert options.nonet?
|
22
|
+
assert options.nowarning?
|
23
|
+
assert options.dtdattr?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_nil_raises
|
27
|
+
assert_raises(ArgumentError) {
|
28
|
+
Nokogiri::XML::Reader.from_memory(nil)
|
29
|
+
}
|
30
|
+
assert_raises(ArgumentError) {
|
31
|
+
Nokogiri::XML::Reader.from_io(nil)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_from_io
|
36
|
+
io = StringIO.new(<<-eoxml)
|
37
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
38
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
39
|
+
</x>
|
40
|
+
eoxml
|
41
|
+
reader = Nokogiri::XML::Reader.from_io(io)
|
42
|
+
assert_equal false, reader.default?
|
43
|
+
assert_equal [false, false, false, false, false, false, false],
|
44
|
+
reader.map { |x| x.default? }
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_io
|
48
|
+
io = StringIO.new(<<-eoxml)
|
49
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
50
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
51
|
+
</x>
|
52
|
+
eoxml
|
53
|
+
reader = Nokogiri::XML::Reader(io)
|
54
|
+
assert_equal false, reader.default?
|
55
|
+
assert_equal [false, false, false, false, false, false, false],
|
56
|
+
reader.map { |x| x.default? }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_in_memory
|
60
|
+
reader = Nokogiri::XML::Reader(<<-eoxml)
|
61
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
62
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
63
|
+
</x>
|
64
|
+
eoxml
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_reader_holds_on_to_string
|
68
|
+
xml = <<-eoxml
|
69
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
70
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
71
|
+
</x>
|
72
|
+
eoxml
|
73
|
+
reader = Nokogiri::XML::Reader(xml)
|
74
|
+
if Nokogiri::VERSION_INFO['libxml']['binding'] == 'ffi'
|
75
|
+
assert_not_nil reader.source
|
76
|
+
assert reader.source.is_a?(FFI::MemoryPointer)
|
77
|
+
else
|
78
|
+
assert_equal xml, reader.source
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_default?
|
83
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
84
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
85
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
86
|
+
</x>
|
87
|
+
eoxml
|
88
|
+
assert_equal false, reader.default?
|
89
|
+
assert_equal [false, false, false, false, false, false, false],
|
90
|
+
reader.map { |x| x.default? }
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_value?
|
94
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
95
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
96
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
97
|
+
</x>
|
98
|
+
eoxml
|
99
|
+
assert_equal false, reader.value?
|
100
|
+
assert_equal [false, true, false, true, false, true, false],
|
101
|
+
reader.map { |x| x.value? }
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_read_error_document
|
105
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
106
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
107
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
108
|
+
<foo>
|
109
|
+
</x>
|
110
|
+
eoxml
|
111
|
+
error_happened = false
|
112
|
+
begin
|
113
|
+
reader.each { |node| }
|
114
|
+
rescue Nokogiri::XML::SyntaxError => ex
|
115
|
+
error_happened = true
|
116
|
+
end
|
117
|
+
assert error_happened
|
118
|
+
assert 1, reader.errors.length
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_attributes?
|
122
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
123
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
124
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
125
|
+
</x>
|
126
|
+
eoxml
|
127
|
+
assert_equal false, reader.attributes?
|
128
|
+
assert_equal [true, false, true, false, true, false, true],
|
129
|
+
reader.map { |x| x.attributes? }
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_attributes
|
133
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
134
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
135
|
+
xmlns='http://mothership.connection.com/'
|
136
|
+
>
|
137
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
138
|
+
</x>
|
139
|
+
eoxml
|
140
|
+
assert_equal({}, reader.attributes)
|
141
|
+
assert_equal [{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
142
|
+
'xmlns'=>'http://mothership.connection.com/'},
|
143
|
+
{}, {"awesome"=>"true"}, {}, {"awesome"=>"true"}, {},
|
144
|
+
{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
145
|
+
'xmlns'=>'http://mothership.connection.com/'}],
|
146
|
+
reader.map { |x| x.attributes }
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_attribute_roundtrip
|
150
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
151
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
152
|
+
xmlns='http://mothership.connection.com/'
|
153
|
+
>
|
154
|
+
<tenderlove:foo awesome='true' size='giant'>snuggles!</tenderlove:foo>
|
155
|
+
</x>
|
156
|
+
eoxml
|
157
|
+
reader.each do |node|
|
158
|
+
node.attributes.each do |key, value|
|
159
|
+
assert_equal value, node.attribute(key)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_attribute_at
|
165
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
166
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
167
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
168
|
+
</x>
|
169
|
+
eoxml
|
170
|
+
assert_nil reader.attribute_at(nil)
|
171
|
+
assert_nil reader.attribute_at(0)
|
172
|
+
assert_equal ['http://tenderlovemaking.com/', nil, 'true', nil, 'true', nil, 'http://tenderlovemaking.com/'],
|
173
|
+
reader.map { |x| x.attribute_at(0) }
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_attribute
|
177
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
178
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
179
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
180
|
+
</x>
|
181
|
+
eoxml
|
182
|
+
assert_nil reader.attribute(nil)
|
183
|
+
assert_nil reader.attribute('awesome')
|
184
|
+
assert_equal [nil, nil, 'true', nil, 'true', nil, nil],
|
185
|
+
reader.map { |x| x.attribute('awesome') }
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_attribute_length
|
189
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
190
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
191
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
192
|
+
</x>
|
193
|
+
eoxml
|
194
|
+
assert_equal 0, reader.attribute_count
|
195
|
+
assert_equal [1, 0, 1, 0, 0, 0, 0], reader.map { |x| x.attribute_count }
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_depth
|
199
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
200
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
201
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
202
|
+
</x>
|
203
|
+
eoxml
|
204
|
+
assert_equal 0, reader.depth
|
205
|
+
assert_equal [0, 1, 1, 2, 1, 1, 0], reader.map { |x| x.depth }
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_encoding
|
209
|
+
string = <<-eoxml
|
210
|
+
<awesome>
|
211
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
212
|
+
<p xml:lang="ja">日本語が上手です</p>
|
213
|
+
</awesome>
|
214
|
+
eoxml
|
215
|
+
reader = Nokogiri::XML::Reader.from_memory(string, nil, 'UTF-8')
|
216
|
+
assert_equal ['UTF-8'], reader.map { |x| x.encoding }.uniq
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_xml_version
|
220
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
221
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
222
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
223
|
+
</x>
|
224
|
+
eoxml
|
225
|
+
assert_nil reader.xml_version
|
226
|
+
assert_equal ['1.0'], reader.map { |x| x.xml_version }.uniq
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_lang
|
230
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
231
|
+
<awesome>
|
232
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
233
|
+
<p xml:lang="ja">日本語が上手です</p>
|
234
|
+
</awesome>
|
235
|
+
eoxml
|
236
|
+
assert_nil reader.lang
|
237
|
+
assert_equal [nil, nil, "en", "en", "en", nil, "ja", "ja", "ja", nil, nil],
|
238
|
+
reader.map { |x| x.lang }
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_value
|
242
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
243
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
244
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
245
|
+
</x>
|
246
|
+
eoxml
|
247
|
+
assert_nil reader.value
|
248
|
+
assert_equal [nil, "\n ", nil, "snuggles!", nil, "\n ", nil],
|
249
|
+
reader.map { |x| x.value }
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_prefix
|
253
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
254
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
255
|
+
<edi:foo>hello</edi:foo>
|
256
|
+
</x>
|
257
|
+
eoxml
|
258
|
+
assert_nil reader.prefix
|
259
|
+
assert_equal [nil, nil, "edi", nil, "edi", nil, nil],
|
260
|
+
reader.map { |n| n.prefix }
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_state
|
264
|
+
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</bar>')
|
265
|
+
assert reader.state
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_ns_uri
|
269
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
270
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
271
|
+
<edi:foo>hello</edi:foo>
|
272
|
+
</x>
|
273
|
+
eoxml
|
274
|
+
assert_nil reader.namespace_uri
|
275
|
+
assert_equal([nil,
|
276
|
+
nil,
|
277
|
+
"http://ecommerce.example.org/schema",
|
278
|
+
nil,
|
279
|
+
"http://ecommerce.example.org/schema",
|
280
|
+
nil,
|
281
|
+
nil],
|
282
|
+
reader.map { |n| n.namespace_uri })
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_local_name
|
286
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
287
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
288
|
+
<edi:foo>hello</edi:foo>
|
289
|
+
</x>
|
290
|
+
eoxml
|
291
|
+
assert_nil reader.local_name
|
292
|
+
assert_equal(["x", "#text", "foo", "#text", "foo", "#text", "x"],
|
293
|
+
reader.map { |n| n.local_name })
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_name
|
297
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
298
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
299
|
+
<edi:foo>hello</edi:foo>
|
300
|
+
</x>
|
301
|
+
eoxml
|
302
|
+
assert_nil reader.name
|
303
|
+
assert_equal(["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"],
|
304
|
+
reader.map { |n| n.name })
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_read_from_memory
|
308
|
+
called = false
|
309
|
+
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</foo>')
|
310
|
+
reader.each do |node|
|
311
|
+
called = true
|
312
|
+
assert node
|
313
|
+
end
|
314
|
+
assert called
|
315
|
+
end
|
316
|
+
end
|