nokogiri 1.3.3-x86-mingw32 → 1.4.0-x86-mingw32
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/CHANGELOG.ja.rdoc +48 -3
- data/CHANGELOG.rdoc +42 -0
- data/Manifest.txt +44 -29
- data/README.ja.rdoc +0 -2
- data/README.rdoc +4 -7
- data/Rakefile +14 -22
- data/bin/nokogiri +7 -5
- data/ext/nokogiri/extconf.rb +5 -21
- data/ext/nokogiri/html_document.c +14 -50
- data/ext/nokogiri/html_element_description.c +7 -7
- data/ext/nokogiri/html_entity_lookup.c +6 -4
- data/ext/nokogiri/html_sax_parser_context.c +92 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/nokogiri.c +9 -3
- data/ext/nokogiri/nokogiri.h +16 -20
- data/ext/nokogiri/xml_attr.c +1 -1
- data/ext/nokogiri/xml_attribute_decl.c +67 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +6 -5
- data/ext/nokogiri/xml_comment.c +3 -2
- data/ext/nokogiri/xml_document.c +93 -23
- data/ext/nokogiri/xml_document_fragment.c +1 -3
- data/ext/nokogiri/xml_dtd.c +63 -6
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_entity_decl.c +97 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_io.c +10 -3
- data/ext/nokogiri/xml_io.h +1 -0
- data/ext/nokogiri/xml_namespace.c +2 -2
- data/ext/nokogiri/xml_node.c +139 -34
- data/ext/nokogiri/xml_node.h +0 -1
- data/ext/nokogiri/xml_node_set.c +23 -16
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +78 -50
- data/ext/nokogiri/xml_sax_parser.c +109 -168
- data/ext/nokogiri/xml_sax_parser.h +33 -0
- data/ext/nokogiri/xml_sax_parser_context.c +155 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +11 -6
- data/ext/nokogiri/xml_syntax_error.c +63 -12
- data/ext/nokogiri/xml_text.c +4 -3
- data/ext/nokogiri/xml_xpath.c +1 -1
- data/ext/nokogiri/xml_xpath_context.c +12 -25
- data/ext/nokogiri/xslt_stylesheet.c +3 -3
- data/lib/nokogiri.rb +4 -4
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css/node.rb +1 -9
- data/lib/nokogiri/css/xpath_visitor.rb +11 -21
- data/lib/nokogiri/ffi/html/document.rb +0 -9
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +38 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +4 -2
- data/lib/nokogiri/ffi/libxml.rb +44 -10
- data/lib/nokogiri/ffi/structs/common_node.rb +1 -1
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +27 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +3 -1
- data/lib/nokogiri/ffi/structs/xml_element.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +17 -0
- data/lib/nokogiri/ffi/structs/xml_entity.rb +32 -0
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_parser_context.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +4 -3
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +1 -1
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +27 -0
- data/lib/nokogiri/ffi/xml/comment.rb +2 -2
- data/lib/nokogiri/ffi/xml/document.rb +29 -12
- data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -5
- data/lib/nokogiri/ffi/xml/dtd.rb +14 -3
- data/lib/nokogiri/ffi/xml/element_content.rb +43 -0
- data/lib/nokogiri/ffi/xml/element_decl.rb +19 -0
- data/lib/nokogiri/ffi/xml/entity_decl.rb +27 -0
- data/lib/nokogiri/ffi/xml/node.rb +45 -5
- data/lib/nokogiri/ffi/xml/node_set.rb +1 -1
- data/lib/nokogiri/ffi/xml/reader.rb +45 -24
- data/lib/nokogiri/ffi/xml/sax/parser.rb +27 -34
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +67 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +5 -4
- data/lib/nokogiri/ffi/xml/syntax_error.rb +31 -16
- data/lib/nokogiri/ffi/xml/text.rb +2 -2
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/document.rb +39 -24
- data/lib/nokogiri/html/sax/parser.rb +2 -2
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml.rb +6 -1
- data/lib/nokogiri/xml/attr.rb +5 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +121 -13
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +43 -29
- data/lib/nokogiri/xml/document_fragment.rb +26 -6
- data/lib/nokogiri/xml/dtd.rb +5 -5
- data/lib/nokogiri/xml/element_content.rb +36 -0
- data/lib/nokogiri/xml/element_decl.rb +13 -0
- data/lib/nokogiri/xml/entity_decl.rb +15 -0
- data/lib/nokogiri/xml/fragment_handler.rb +22 -11
- data/lib/nokogiri/xml/namespace.rb +6 -0
- data/lib/nokogiri/xml/node.rb +33 -15
- data/lib/nokogiri/xml/node_set.rb +66 -44
- data/lib/nokogiri/xml/pp.rb +2 -0
- data/lib/nokogiri/xml/pp/character_data.rb +18 -0
- data/lib/nokogiri/xml/pp/node.rb +56 -0
- data/lib/nokogiri/xml/reader.rb +8 -0
- data/lib/nokogiri/xml/sax.rb +1 -1
- data/lib/nokogiri/xml/sax/document.rb +18 -1
- data/lib/nokogiri/xml/sax/parser.rb +15 -8
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +0 -3
- data/lib/nokogiri/xml/syntax_error.rb +4 -0
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/test/css/test_nthiness.rb +1 -1
- data/test/css/test_parser.rb +1 -1
- data/test/css/test_tokenizer.rb +1 -1
- data/test/css/test_xpath_visitor.rb +1 -1
- data/test/ffi/test_document.rb +1 -1
- data/test/files/shift_jis.html +10 -0
- data/test/files/staff.dtd +10 -0
- data/test/helper.rb +12 -3
- data/test/html/sax/test_parser.rb +1 -1
- data/test/html/sax/test_parser_context.rb +48 -0
- data/test/html/test_builder.rb +8 -2
- data/test/html/test_document.rb +23 -1
- data/test/html/test_document_encoding.rb +15 -1
- data/test/html/test_document_fragment.rb +10 -1
- data/test/html/test_element_description.rb +1 -2
- data/test/html/test_named_characters.rb +1 -1
- data/test/html/test_node.rb +61 -1
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +1 -3
- data/test/test_css_cache.rb +1 -1
- data/test/test_gc.rb +1 -1
- data/test/test_memory_leak.rb +1 -1
- data/test/test_nokogiri.rb +3 -3
- data/test/test_reader.rb +29 -1
- data/test/test_xslt_transforms.rb +1 -1
- data/test/xml/node/test_save_options.rb +1 -1
- data/test/xml/node/test_subclass.rb +1 -1
- data/test/xml/sax/test_parser.rb +64 -3
- data/test/xml/sax/test_parser_context.rb +56 -0
- data/test/xml/sax/test_push_parser.rb +11 -1
- data/test/xml/test_attr.rb +1 -1
- data/test/xml/test_attribute_decl.rb +82 -0
- data/test/xml/test_builder.rb +95 -1
- data/test/xml/test_cdata.rb +1 -1
- data/test/xml/test_comment.rb +7 -1
- data/test/xml/test_document.rb +147 -6
- data/test/xml/test_document_encoding.rb +1 -1
- data/test/xml/test_document_fragment.rb +55 -5
- data/test/xml/test_dtd.rb +40 -5
- data/test/xml/test_dtd_encoding.rb +3 -1
- data/test/xml/test_element_content.rb +56 -0
- data/test/xml/test_element_decl.rb +73 -0
- data/test/xml/test_entity_decl.rb +83 -0
- data/test/xml/test_entity_reference.rb +1 -1
- data/test/xml/test_namespace.rb +21 -1
- data/test/xml/test_node.rb +70 -4
- data/test/xml/test_node_attributes.rb +1 -1
- data/test/xml/test_node_encoding.rb +1 -1
- data/test/xml/test_node_set.rb +136 -2
- data/test/xml/test_parse_options.rb +1 -1
- data/test/xml/test_processing_instruction.rb +1 -1
- data/test/xml/test_reader_encoding.rb +1 -1
- data/test/xml/test_relax_ng.rb +1 -1
- data/test/xml/test_schema.rb +1 -1
- data/test/xml/test_syntax_error.rb +27 -0
- data/test/xml/test_text.rb +13 -1
- data/test/xml/test_unparented_node.rb +1 -1
- data/test/xml/test_xpath.rb +1 -1
- metadata +55 -38
- data/ext/nokogiri/html_sax_parser.c +0 -57
- data/ext/nokogiri/html_sax_parser.h +0 -11
- data/lib/action-nokogiri.rb +0 -38
- data/lib/nokogiri/decorators.rb +0 -2
- data/lib/nokogiri/decorators/hpricot.rb +0 -3
- data/lib/nokogiri/decorators/hpricot/node.rb +0 -56
- data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -54
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -30
- data/lib/nokogiri/ffi/html/sax/parser.rb +0 -21
- data/lib/nokogiri/hpricot.rb +0 -92
- data/lib/nokogiri/xml/entity_declaration.rb +0 -11
- data/lib/nokogiri/xml/sax/legacy_handlers.rb +0 -65
- data/test/hpricot/files/basic.xhtml +0 -17
- data/test/hpricot/files/boingboing.html +0 -2266
- data/test/hpricot/files/cy0.html +0 -3653
- data/test/hpricot/files/immob.html +0 -400
- data/test/hpricot/files/pace_application.html +0 -1320
- data/test/hpricot/files/tenderlove.html +0 -16
- data/test/hpricot/files/uswebgen.html +0 -220
- data/test/hpricot/files/utf8.html +0 -1054
- data/test/hpricot/files/week9.html +0 -1723
- data/test/hpricot/files/why.xml +0 -19
- data/test/hpricot/load_files.rb +0 -11
- data/test/hpricot/test_alter.rb +0 -68
- data/test/hpricot/test_builder.rb +0 -20
- data/test/hpricot/test_parser.rb +0 -350
- data/test/hpricot/test_paths.rb +0 -15
- data/test/hpricot/test_preserved.rb +0 -77
- data/test/hpricot/test_xml.rb +0 -30
data/test/xml/test_dtd.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
module Nokogiri
|
4
4
|
module XML
|
@@ -9,6 +9,45 @@ module Nokogiri
|
|
9
9
|
assert @dtd = @xml.internal_subset
|
10
10
|
end
|
11
11
|
|
12
|
+
def test_system_id
|
13
|
+
assert_equal 'staff.dtd', @dtd.system_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_external_id
|
17
|
+
xml = Nokogiri::XML('<!DOCTYPE foo PUBLIC "bar" ><foo />')
|
18
|
+
assert dtd = xml.internal_subset
|
19
|
+
assert_equal 'bar', dtd.external_id
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_content
|
23
|
+
assert_raise NoMethodError do
|
24
|
+
@dtd.content
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_attributes
|
29
|
+
assert_equal ['width'], @dtd.attributes.keys
|
30
|
+
assert_equal '0', @dtd.attributes['width'].default
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_namespace
|
34
|
+
assert_raise NoMethodError do
|
35
|
+
@dtd.namespace
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_namespace_definitions
|
40
|
+
assert_raise NoMethodError do
|
41
|
+
@dtd.namespace_definitions
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_line
|
46
|
+
assert_raise NoMethodError do
|
47
|
+
@dtd.line
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
12
51
|
def test_validate
|
13
52
|
list = @xml.internal_subset.validate @xml
|
14
53
|
assert_equal 44, list.length
|
@@ -24,10 +63,6 @@ module Nokogiri
|
|
24
63
|
assert_equal %w[ ent1 ent2 ent3 ent4 ent5 ].sort, entities.keys.sort
|
25
64
|
end
|
26
65
|
|
27
|
-
def test_attributes
|
28
|
-
assert_nil @dtd.attributes
|
29
|
-
end
|
30
|
-
|
31
66
|
def test_elements
|
32
67
|
assert elements = @dtd.elements
|
33
68
|
assert_equal %w[ br ], elements.keys
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class TestElementContent < Nokogiri::TestCase
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@xml = Nokogiri::XML(<<-eoxml)
|
9
|
+
<?xml version="1.0"?><?TEST-STYLE PIDATA?>
|
10
|
+
<!DOCTYPE staff SYSTEM "staff.dtd" [
|
11
|
+
<!ELEMENT br EMPTY>
|
12
|
+
<!ELEMENT div1 (head, (p | list | note)*, div2*)>
|
13
|
+
<!ELEMENT div2 (tender:love)>
|
14
|
+
]>
|
15
|
+
</root>
|
16
|
+
eoxml
|
17
|
+
@elements = @xml.internal_subset.children.find_all { |x|
|
18
|
+
x.type == 15
|
19
|
+
}
|
20
|
+
@tree = @elements[1].content
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_allowed_content_not_defined
|
24
|
+
assert_nil @elements.first.content
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_document
|
28
|
+
assert @tree
|
29
|
+
assert_equal @xml, @tree.document
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_type
|
33
|
+
assert_equal ElementContent::SEQ, @tree.type
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_children
|
37
|
+
assert_equal 2, @tree.children.length
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_name
|
41
|
+
assert_nil @tree.name
|
42
|
+
assert_equal 'head', @tree.children.first.name
|
43
|
+
assert_equal 'p', @tree.children[1].children.first.children.first.name
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_occur
|
47
|
+
assert_equal ElementContent::ONCE, @tree.occur
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_prefix
|
51
|
+
assert_nil @tree.prefix
|
52
|
+
assert_equal 'tender', @elements[2].content.prefix
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class TestElementDecl < Nokogiri::TestCase
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@xml = Nokogiri::XML(<<-eoxml)
|
9
|
+
<?xml version="1.0"?><?TEST-STYLE PIDATA?>
|
10
|
+
<!DOCTYPE staff SYSTEM "staff.dtd" [
|
11
|
+
<!ELEMENT br EMPTY>
|
12
|
+
<!ELEMENT div1 (head, (p | list | note)*, div2*)>
|
13
|
+
<!ELEMENT my:way EMPTY>
|
14
|
+
<!ATTLIST br width CDATA "0">
|
15
|
+
<!ATTLIST br height CDATA "0">
|
16
|
+
]>
|
17
|
+
</root>
|
18
|
+
eoxml
|
19
|
+
@elements = @xml.internal_subset.children.find_all { |x|
|
20
|
+
x.type == 15
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_inspect
|
25
|
+
e = @elements.first
|
26
|
+
assert_equal(
|
27
|
+
"#<#{e.class.name}:#{sprintf("0x%x", e.object_id)} #{e.to_s.inspect}>",
|
28
|
+
e.inspect
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_prefix
|
33
|
+
assert_nil @elements[1].prefix
|
34
|
+
assert_equal 'my', @elements[2].prefix
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_line
|
38
|
+
assert_raise NoMethodError do
|
39
|
+
@elements.first.line
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_namespace
|
44
|
+
assert_raise NoMethodError do
|
45
|
+
@elements.first.namespace
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_namespace_definitions
|
50
|
+
assert_raise NoMethodError do
|
51
|
+
@elements.first.namespace_definitions
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_element_type
|
56
|
+
assert_equal 1, @elements.first.element_type
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_type
|
60
|
+
assert_equal 15, @elements.first.type
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_class
|
64
|
+
assert_instance_of Nokogiri::XML::ElementDecl, @elements.first
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_attributes
|
68
|
+
assert_equal 2, @elements.first.attribute_nodes.length
|
69
|
+
assert_equal 'width', @elements.first.attribute_nodes.first.name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class TestEntityDecl < Nokogiri::TestCase
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@xml = Nokogiri::XML(<<-eoxml)
|
9
|
+
<?xml version="1.0"?><?TEST-STYLE PIDATA?>
|
10
|
+
<!DOCTYPE staff SYSTEM "staff.dtd" [
|
11
|
+
<!ENTITY ent1 "es">
|
12
|
+
<!ENTITY nocontent >
|
13
|
+
]>
|
14
|
+
<root />
|
15
|
+
eoxml
|
16
|
+
|
17
|
+
@entities = @xml.internal_subset.children
|
18
|
+
@entity_decl = @entities.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_external_id
|
22
|
+
assert_nil @entity_decl.external_id
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_system_id
|
26
|
+
assert_nil @entity_decl.system_id
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_entity_type
|
30
|
+
assert_equal 1, @entity_decl.entity_type
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_original_content
|
34
|
+
assert_equal "es", @entity_decl.original_content
|
35
|
+
assert_nil @entities[1].original_content
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_content
|
39
|
+
assert_equal "es", @entity_decl.content
|
40
|
+
assert_nil @entities[1].content
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_type
|
44
|
+
assert_equal 17, @entities.first.type
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_class
|
48
|
+
assert_instance_of Nokogiri::XML::EntityDecl, @entities.first
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_attributes
|
52
|
+
assert_raise NoMethodError do
|
53
|
+
@entity_decl.attributes
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_namespace
|
58
|
+
assert_raise NoMethodError do
|
59
|
+
@entity_decl.namespace
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_namespace_definitions
|
64
|
+
assert_raise NoMethodError do
|
65
|
+
@entity_decl.namespace_definitions
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_line
|
70
|
+
assert_raise NoMethodError do
|
71
|
+
@entity_decl.line
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_inspect
|
76
|
+
assert_equal(
|
77
|
+
"#<#{@entity_decl.class.name}:#{sprintf("0x%x", @entity_decl.object_id)} #{@entity_decl.to_s.inspect}>",
|
78
|
+
@entity_decl.inspect
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/test/xml/test_namespace.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
module Nokogiri
|
4
4
|
module XML
|
5
5
|
class TestNamespace < Nokogiri::TestCase
|
6
6
|
def setup
|
7
|
+
super
|
7
8
|
@xml = Nokogiri::XML <<-eoxml
|
8
9
|
<root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
|
9
10
|
<awesome/>
|
@@ -11,6 +12,25 @@ module Nokogiri
|
|
11
12
|
eoxml
|
12
13
|
end
|
13
14
|
|
15
|
+
def test_built_nodes_keep_namespace_decls
|
16
|
+
doc = Document.new
|
17
|
+
e = Node.new 'element', doc
|
18
|
+
c = Node.new 'child', doc
|
19
|
+
c.default_namespace = 'woop:de:doo'
|
20
|
+
|
21
|
+
assert c.namespace, 'has a namespace'
|
22
|
+
e.add_child c
|
23
|
+
assert c.namespace, 'has a namespace'
|
24
|
+
|
25
|
+
doc.add_child e
|
26
|
+
assert c.namespace, 'has a namespace'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_inspect
|
30
|
+
ns = @xml.root.namespace
|
31
|
+
assert_equal "#<#{ns.class.name}:#{sprintf("0x%x", ns.object_id)} href=#{ns.href.inspect}>", ns.inspect
|
32
|
+
end
|
33
|
+
|
14
34
|
def test_namespace_is_in_node_cache
|
15
35
|
node = @xml.root.namespace
|
16
36
|
assert @xml.instance_variable_get(:@node_cache).include?(node)
|
data/test/xml/test_node.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
require 'stringio'
|
4
4
|
|
@@ -10,6 +10,44 @@ module Nokogiri
|
|
10
10
|
@xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_element?
|
14
|
+
assert @xml.root.element?, 'is an element'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_slash_search
|
18
|
+
assert_equal 'EMP0001', (@xml/:staff/:employee/:employeeId).first.text
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_append_with_document
|
22
|
+
assert_raises(ArgumentError) do
|
23
|
+
@xml.root << Nokogiri::XML::Document.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_inspect_ns
|
28
|
+
xml = Nokogiri::XML(<<-eoxml) { |c| c.noblanks }
|
29
|
+
<root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
|
30
|
+
<awesome/>
|
31
|
+
</root>
|
32
|
+
eoxml
|
33
|
+
ins = xml.inspect
|
34
|
+
|
35
|
+
xml.traverse do |node|
|
36
|
+
assert_match node.class.name, ins
|
37
|
+
if node.respond_to? :attributes
|
38
|
+
node.attributes.each do |k,v|
|
39
|
+
assert_match k, ins
|
40
|
+
assert_match v, ins
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if node.respond_to?(:namespace) && node.namespace
|
45
|
+
assert_match node.namespace.class.name, ins
|
46
|
+
assert_match node.namespace.href, ins
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
13
51
|
def test_namespace_nodes
|
14
52
|
xml = Nokogiri::XML <<-eoxml
|
15
53
|
<root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
|
@@ -244,6 +282,20 @@ module Nokogiri
|
|
244
282
|
assert_equal node, @xml.xpath('//address').first
|
245
283
|
end
|
246
284
|
|
285
|
+
def test_at_xpath
|
286
|
+
node = @xml.at_xpath('//address')
|
287
|
+
nodes = @xml.xpath('//address')
|
288
|
+
assert_equal 5, nodes.size
|
289
|
+
assert_equal node, nodes.first
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_at_css
|
293
|
+
node = @xml.at_css('address')
|
294
|
+
nodes = @xml.css('address')
|
295
|
+
assert_equal 5, nodes.size
|
296
|
+
assert_equal node, nodes.first
|
297
|
+
end
|
298
|
+
|
247
299
|
def test_percent
|
248
300
|
node = @xml % ('address')
|
249
301
|
assert_equal node, @xml.xpath('//address').first
|
@@ -293,6 +345,23 @@ module Nokogiri
|
|
293
345
|
assert doc.at('//xmlns:second')
|
294
346
|
end
|
295
347
|
|
348
|
+
def test_add_child_should_not_inherit_namespace_if_it_has_one
|
349
|
+
doc = Nokogiri::XML(<<-eoxml)
|
350
|
+
<root xmlns="http://tenderlovemaking.com/" xmlns:foo="http://flavorjon.es/">
|
351
|
+
<first>
|
352
|
+
</first>
|
353
|
+
</root>
|
354
|
+
eoxml
|
355
|
+
assert node = doc.at('//xmlns:first')
|
356
|
+
child = Nokogiri::XML::Node.new('second', doc)
|
357
|
+
|
358
|
+
ns = doc.root.namespace_definitions.detect { |x| x.prefix == "foo" }
|
359
|
+
child.namespace = ns
|
360
|
+
|
361
|
+
node.add_child(child)
|
362
|
+
assert doc.at('//foo:second', "foo" => "http://flavorjon.es/")
|
363
|
+
end
|
364
|
+
|
296
365
|
def test_write_to
|
297
366
|
io = StringIO.new
|
298
367
|
@xml.write_to io
|
@@ -737,12 +806,9 @@ EOF
|
|
737
806
|
assert_equal 'http://foo.com/', namespaces['xmlns:a']
|
738
807
|
assert namespaces.key?('xmlns:b')
|
739
808
|
assert_equal 'http://bar.com/', namespaces['xmlns:b']
|
740
|
-
assert namespaces.key?('xmlns:c')
|
741
|
-
assert_equal 'http://bazz.com/', namespaces['xmlns:c']
|
742
809
|
|
743
810
|
assert_equal "hello a", xml.search("//a:div", xml.namespaces).first.inner_text
|
744
811
|
assert_equal "hello b", xml.search("//b:div", xml.namespaces).first.inner_text
|
745
|
-
assert_equal "hello c", xml.search("//c:div", xml.namespaces).first.inner_text
|
746
812
|
end
|
747
813
|
|
748
814
|
def test_namespace
|