libxml-ruby 5.0.5 → 6.0.0

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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/{HISTORY → CHANGELOG.md} +875 -923
  3. data/LICENSE +20 -20
  4. data/README.md +67 -0
  5. data/Rakefile +77 -98
  6. data/ext/libxml/extconf.rb +34 -20
  7. data/ext/libxml/libxml.c +67 -79
  8. data/ext/libxml/ruby_libxml.h +1 -1
  9. data/ext/libxml/ruby_xml_attr.c +338 -333
  10. data/ext/libxml/ruby_xml_attr.h +13 -12
  11. data/ext/libxml/ruby_xml_attr_decl.c +19 -12
  12. data/ext/libxml/ruby_xml_attr_decl.h +11 -11
  13. data/ext/libxml/ruby_xml_attributes.c +18 -9
  14. data/ext/libxml/ruby_xml_document.c +111 -98
  15. data/ext/libxml/ruby_xml_document.h +1 -0
  16. data/ext/libxml/ruby_xml_dtd.c +49 -19
  17. data/ext/libxml/ruby_xml_dtd.h +10 -9
  18. data/ext/libxml/ruby_xml_html_parser.c +91 -91
  19. data/ext/libxml/ruby_xml_html_parser.h +10 -10
  20. data/ext/libxml/ruby_xml_html_parser_context.c +19 -6
  21. data/ext/libxml/ruby_xml_html_parser_context.h +11 -10
  22. data/ext/libxml/ruby_xml_html_parser_options.c +48 -48
  23. data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
  24. data/ext/libxml/ruby_xml_input_cbg.c +45 -17
  25. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  26. data/ext/libxml/ruby_xml_io.c +49 -47
  27. data/ext/libxml/ruby_xml_io.h +10 -10
  28. data/ext/libxml/ruby_xml_namespace.c +20 -12
  29. data/ext/libxml/ruby_xml_namespace.h +11 -10
  30. data/ext/libxml/ruby_xml_namespaces.c +313 -293
  31. data/ext/libxml/ruby_xml_namespaces.h +9 -9
  32. data/ext/libxml/ruby_xml_node.c +71 -32
  33. data/ext/libxml/ruby_xml_node.h +15 -13
  34. data/ext/libxml/ruby_xml_parser.c +91 -91
  35. data/ext/libxml/ruby_xml_parser_context.c +54 -47
  36. data/ext/libxml/ruby_xml_parser_context.h +11 -10
  37. data/ext/libxml/ruby_xml_reader.c +25 -15
  38. data/ext/libxml/ruby_xml_reader.h +14 -14
  39. data/ext/libxml/ruby_xml_registry.c +31 -0
  40. data/ext/libxml/ruby_xml_registry.h +22 -0
  41. data/ext/libxml/ruby_xml_relaxng.c +21 -5
  42. data/ext/libxml/ruby_xml_relaxng.h +9 -8
  43. data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
  44. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  45. data/ext/libxml/ruby_xml_sax_parser.h +10 -10
  46. data/ext/libxml/ruby_xml_schema.c +18 -11
  47. data/ext/libxml/ruby_xml_schema.h +26 -25
  48. data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
  49. data/ext/libxml/ruby_xml_schema_attribute.h +37 -37
  50. data/ext/libxml/ruby_xml_schema_element.c +8 -8
  51. data/ext/libxml/ruby_xml_schema_element.h +11 -11
  52. data/ext/libxml/ruby_xml_schema_facet.c +50 -50
  53. data/ext/libxml/ruby_xml_schema_facet.h +9 -9
  54. data/ext/libxml/ruby_xml_schema_type.c +12 -19
  55. data/ext/libxml/ruby_xml_schema_type.h +9 -9
  56. data/ext/libxml/ruby_xml_version.h +4 -4
  57. data/ext/libxml/ruby_xml_writer.c +1136 -1124
  58. data/ext/libxml/ruby_xml_writer.h +6 -6
  59. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  60. data/ext/libxml/ruby_xml_xinclude.h +11 -11
  61. data/ext/libxml/ruby_xml_xpath.c +195 -195
  62. data/ext/libxml/ruby_xml_xpath.h +15 -15
  63. data/ext/libxml/ruby_xml_xpath_context.c +408 -362
  64. data/ext/libxml/ruby_xml_xpath_context.h +9 -9
  65. data/ext/libxml/ruby_xml_xpath_expression.c +11 -5
  66. data/ext/libxml/ruby_xml_xpath_expression.h +11 -10
  67. data/ext/libxml/ruby_xml_xpath_object.c +69 -54
  68. data/ext/libxml/ruby_xml_xpath_object.h +19 -17
  69. data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
  70. data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
  71. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  72. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  73. data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
  74. data/lib/libxml/document.rb +0 -29
  75. data/lib/libxml/error.rb +30 -3
  76. data/lib/libxml/html_parser.rb +0 -16
  77. data/lib/libxml/node.rb +1 -3
  78. data/lib/libxml/parser.rb +0 -8
  79. data/lib/libxml/schema/attribute.rb +27 -19
  80. data/lib/libxml/schema/element.rb +20 -0
  81. data/lib/libxml/schema/type.rb +44 -21
  82. data/lib/libxml/schema.rb +47 -47
  83. data/lib/libxml-ruby.rb +30 -30
  84. data/libxml-ruby.gemspec +12 -16
  85. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  86. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  87. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  88. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  89. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  90. data/test/c14n/result/with-comments/example-1 +5 -5
  91. data/test/c14n/result/with-comments/example-2 +10 -10
  92. data/test/c14n/result/with-comments/example-3 +13 -13
  93. data/test/c14n/result/with-comments/example-4 +8 -8
  94. data/test/c14n/result/with-comments/example-5 +3 -3
  95. data/test/c14n/result/without-comments/example-1 +3 -3
  96. data/test/c14n/result/without-comments/example-2 +10 -10
  97. data/test/c14n/result/without-comments/example-3 +13 -13
  98. data/test/c14n/result/without-comments/example-4 +8 -8
  99. data/test/c14n/result/without-comments/example-5 +2 -2
  100. data/test/test_attr.rb +179 -180
  101. data/test/test_attr_decl.rb +131 -131
  102. data/test/test_attributes.rb +135 -135
  103. data/test/test_canonicalize.rb +122 -120
  104. data/test/test_document.rb +2 -4
  105. data/test/test_dtd.rb +12 -4
  106. data/test/test_encoding_sax.rb +114 -114
  107. data/test/test_error.rb +6 -3
  108. data/test/test_helper.rb +1 -0
  109. data/test/test_html_parser.rb +6 -2
  110. data/test/test_html_parser_context.rb +22 -22
  111. data/test/test_input_callbacks.rb +36 -0
  112. data/test/test_namespace.rb +1 -1
  113. data/test/test_namespaces.rb +200 -200
  114. data/test/test_node.rb +16 -0
  115. data/test/test_node_cdata.rb +50 -50
  116. data/test/test_node_comment.rb +32 -32
  117. data/test/test_node_copy.rb +40 -40
  118. data/test/test_node_edit.rb +176 -158
  119. data/test/test_node_pi.rb +37 -37
  120. data/test/test_node_text.rb +69 -69
  121. data/test/test_node_xlink.rb +28 -28
  122. data/test/test_parser.rb +5 -41
  123. data/test/test_parser_context.rb +198 -198
  124. data/test/test_properties.rb +38 -38
  125. data/test/test_reader.rb +55 -6
  126. data/test/test_relaxng.rb +59 -53
  127. data/test/test_sax_parser.rb +345 -345
  128. data/test/test_schema.rb +28 -0
  129. data/test/test_traversal.rb +152 -152
  130. data/test/test_writer.rb +469 -468
  131. data/test/test_xinclude.rb +20 -20
  132. data/test/test_xml.rb +3 -7
  133. data/test/test_xpath.rb +244 -244
  134. data/test/test_xpath_context.rb +87 -87
  135. data/test/test_xpath_expression.rb +37 -37
  136. metadata +33 -27
  137. data/README.rdoc +0 -208
  138. data/ext/libxml/extconf.h +0 -3
  139. data/ext/libxml/ruby_xml_cbg.c +0 -85
  140. data/lib/libxml/hpricot.rb +0 -78
  141. data/lib/libxml.rb +0 -5
  142. data/lib/xml/libxml.rb +0 -10
  143. data/lib/xml.rb +0 -14
  144. data/script/benchmark/depixelate +0 -634
  145. data/script/benchmark/hamlet.xml +0 -9055
  146. data/script/benchmark/parsecount +0 -170
  147. data/script/benchmark/sock_entries.xml +0 -507
  148. data/script/benchmark/throughput +0 -41
  149. data/script/test +0 -6
  150. data/test/test.rb +0 -5
  151. data/test/test_deprecated_require.rb +0 -12
@@ -1,120 +1,122 @@
1
- # encoding: UTF-8
2
- require_relative './test_helper'
3
-
4
- class TestCanonicalize < Minitest::Test
5
- def path(file)
6
- File.join(File.dirname(__FILE__), file)
7
- end
8
-
9
- # (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
10
- # http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
11
- def test_canonicalize_with_w3c_c14n_3_1
12
- given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-1.xml'))
13
-
14
- # With Comments
15
- expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-1'))
16
- assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
17
-
18
- # Without Comments
19
- expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-1'))
20
- assert_equal(expected_without_comments, given_doc.canonicalize)
21
- assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
22
-
23
- # Without Comments (XML_C14N_1_1)
24
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-1'))
25
- mode = LibXML::XML::Document::XML_C14N_1_1
26
- assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
27
- end#test_canonicalize_with_w3c_c14n_3_1
28
-
29
-
30
- # (www.w3.org) 3.2 Whitespace in Document Content
31
- # http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
32
- def test_canonicalize_with_w3c_c14n_3_2
33
- given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-2.xml'))
34
- expected = IO.read(self.path('c14n/result/without-comments/example-2'))
35
- assert_equal(expected, given_doc.canonicalize)
36
-
37
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-2'))
38
- mode = LibXML::XML::Document::XML_C14N_1_1
39
- assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
40
- end
41
-
42
- # (www.w3.org) 3.3 Start and End Tags
43
- # http://www.w3.org/TR/xml-c14n#Example-SETags
44
- # (2012-02-20) Test failing due to missing 'attr' in 'e9' node.
45
- # - Embedded DTD not parsed out of XML, therefore default attributes are
46
- # not applied to canonicalization.
47
- def test_canonicalize_with_w3c_c14n_3_3
48
- given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-3.xml'))
49
- expected = IO.read(self.path('c14n/result/without-comments/example-3'))
50
- assert_equal(expected, given_doc.canonicalize)
51
-
52
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-3'))
53
- mode = LibXML::XML::Document::XML_C14N_1_1
54
- assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
55
- end
56
-
57
- # (www.w3.org) 3.4 Character Modifications and Character References
58
- # http://www.w3.org/TR/xml-c14n#Example-Chars
59
- def test_canonicalize_with_w3c_c14n_3_4
60
- given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-4.xml'))
61
- expected = IO.read(self.path('c14n/result/without-comments/example-4'))
62
- assert_equal(expected, given_doc.canonicalize)
63
-
64
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-4'))
65
- mode = LibXML::XML::Document::XML_C14N_1_1
66
- assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
67
- end
68
-
69
- # (www.w3.org) 3.5 Entity References
70
- # http://www.w3.org/TR/xml-c14n#Example-Entities
71
- # (2012-02-20) Failing likely due to a logic error
72
- # - libxml2(c14n.c:1788) XML_ENTITY_REF_NODE is invalid node for parsing.
73
- def test_canonicalize_with_w3c_c14n_3_5
74
- #given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-5.xml'))
75
-
76
- # With Comments
77
- #expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-5'))
78
-
79
- # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
80
- #assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
81
-
82
- # Without Comments
83
- #expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-5'))
84
- # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
85
- #assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
86
- #expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-5'))
87
- #mode = LibXML::XML::Document::XML_C14N_1_1
88
-
89
- # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
90
- #assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
91
- end
92
-
93
- # (www.w3.org) 3.6 UTF-8 Encoding
94
- # http://www.w3.org/TR/xml-c14n#Example-UTF8
95
- def test_canonicalize_with_w3c_c14n_3_6
96
- given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-6.xml'))
97
- expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
98
- assert_equal(expected, given_doc.canonicalize)
99
-
100
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
101
- mode = LibXML::XML::Document::XML_C14N_1_1
102
- assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
103
- end
104
-
105
- # (www.w3.org) 3.7 Document Subsets
106
- # http://www.w3.org/TR/xml-c14n#Example-DocSubsets
107
- def test_canonicalize_with_w3c_c14n_3_7
108
- # Non Canonicalized Document
109
- # given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-7.xml'))
110
- #expected = IO.read(self.path('c14n/result/without-comments/example-7'))
111
-
112
- # e1_node = given_doc.find_first('ietf:e1', 'ietf:http://www.ietf.org')
113
-
114
- # Select current node, all child nodes, all attributes and namespace nodes
115
- #subdoc_nodes = e1_node.find("(.//.|.//@id|namespace::*)")
116
-
117
- # TODO - This fails because the namespace nodes aren't taken into account
118
- # assert_equal(expected, given_doc.canonicalize(:nodes => subdoc_nodes))
119
- end
120
- end
1
+ # encoding: UTF-8
2
+ require_relative './test_helper'
3
+
4
+ class TestCanonicalize < Minitest::Test
5
+ def path(file)
6
+ File.join(File.dirname(__FILE__), file)
7
+ end
8
+
9
+ # (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
10
+ # http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
11
+ def test_canonicalize_with_w3c_c14n_3_1
12
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-1.xml'))
13
+
14
+ # With Comments
15
+ expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-1'))
16
+ assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
17
+
18
+ # Without Comments
19
+ expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-1'))
20
+ assert_equal(expected_without_comments, given_doc.canonicalize)
21
+ assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
22
+
23
+ # Without Comments (XML_C14N_1_1)
24
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-1'))
25
+ mode = LibXML::XML::Document::XML_C14N_1_1
26
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
27
+ end
28
+
29
+ # (www.w3.org) 3.2 Whitespace in Document Content
30
+ # http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
31
+ def test_canonicalize_with_w3c_c14n_3_2
32
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-2.xml'))
33
+ expected = IO.read(self.path('c14n/result/without-comments/example-2'))
34
+ assert_equal(expected, given_doc.canonicalize)
35
+
36
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-2'))
37
+ mode = LibXML::XML::Document::XML_C14N_1_1
38
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
39
+ end
40
+
41
+ # (www.w3.org) 3.3 Start and End Tags
42
+ # http://www.w3.org/TR/xml-c14n#Example-SETags
43
+ # (2012-02-20) Test failing due to missing 'attr' in 'e9' node.
44
+ # - Embedded DTD not parsed out of XML, therefore default attributes are
45
+ # not applied to canonicalization.
46
+ def test_canonicalize_with_w3c_c14n_3_3
47
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-3.xml'))
48
+ expected = IO.read(self.path('c14n/result/without-comments/example-3'))
49
+ assert_equal(expected, given_doc.canonicalize)
50
+
51
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-3'))
52
+ mode = LibXML::XML::Document::XML_C14N_1_1
53
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
54
+ end
55
+
56
+ # (www.w3.org) 3.4 Character Modifications and Character References
57
+ # http://www.w3.org/TR/xml-c14n#Example-Chars
58
+ def test_canonicalize_with_w3c_c14n_3_4
59
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-4.xml'))
60
+ expected = IO.read(self.path('c14n/result/without-comments/example-4'))
61
+ assert_equal(expected, given_doc.canonicalize)
62
+
63
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-4'))
64
+ mode = LibXML::XML::Document::XML_C14N_1_1
65
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
66
+ end
67
+
68
+ # (www.w3.org) 3.5 Entity References
69
+ # http://www.w3.org/TR/xml-c14n#Example-Entities
70
+ def test_canonicalize_with_w3c_c14n_3_5
71
+ # NOENT resolves entity references, DTDLOAD loads the external entity
72
+ options = LibXML::XML::Parser::Options::NOENT | LibXML::XML::Parser::Options::DTDLOAD
73
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-5.xml'), options: options)
74
+
75
+ # With Comments
76
+ expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-5'))
77
+ assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
78
+
79
+ # Without Comments
80
+ expected_without_comments = IO.read(self.path('c14n/result/without-comments/example-5'))
81
+ assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
82
+
83
+ # Without Comments (XML_C14N_1_1)
84
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-5'))
85
+ mode = LibXML::XML::Document::XML_C14N_1_1
86
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
87
+ end
88
+
89
+ # (www.w3.org) 3.6 UTF-8 Encoding
90
+ # http://www.w3.org/TR/xml-c14n#Example-UTF8
91
+ def test_canonicalize_with_w3c_c14n_3_6
92
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-6.xml'))
93
+ expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
94
+ assert_equal(expected, given_doc.canonicalize)
95
+
96
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
97
+ mode = LibXML::XML::Document::XML_C14N_1_1
98
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
99
+ end
100
+
101
+ # (www.w3.org) 3.7 Document Subsets
102
+ # http://www.w3.org/TR/xml-c14n#Example-DocSubsets
103
+ def test_canonicalize_with_w3c_c14n_3_7
104
+ # Parse with DTDATTR and DTDLOAD so default attributes and ID types
105
+ # from the internal DTD subset are materialized
106
+ options = LibXML::XML::Parser::Options::DTDATTR | LibXML::XML::Parser::Options::DTDLOAD
107
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-7.xml'),
108
+ options: options)
109
+ expected = IO.read(self.path('c14n/result/without-comments/example-7'))
110
+
111
+ ctx = given_doc.context
112
+ ctx.register_namespace('ietf', 'http://www.ietf.org')
113
+
114
+ # W3C C14N spec example 3.7 XPath expression for document subsets
115
+ subdoc_nodes = ctx.find(
116
+ "(//. | //@* | //namespace::*)" \
117
+ "[self::ietf:e1 or (parent::ietf:e1 and not(self::text() or self::e2))" \
118
+ " or count(id('E3')|ancestor-or-self::node()) = count(ancestor-or-self::node())]")
119
+
120
+ assert_equal(expected, given_doc.canonicalize(:nodes => subdoc_nodes))
121
+ end
122
+ end
@@ -43,14 +43,12 @@ class TestDocument < Minitest::Test
43
43
  end
44
44
 
45
45
  10.upto(20) do |i|
46
- # assert_equal(9, @doc.compression = i)
47
- assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
46
+ assert_equal(i, @doc.compression = i)
48
47
  assert_equal(9, @doc.compression)
49
48
  end
50
49
 
51
50
  -1.downto(-10) do |i|
52
- # assert_equal(0, @doc.compression = i)
53
- assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
51
+ @doc.compression = i
54
52
  assert_equal(0, @doc.compression)
55
53
  end
56
54
  end
data/test/test_dtd.rb CHANGED
@@ -44,6 +44,16 @@ class TestDtd < Minitest::Test
44
44
  assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
45
45
  end
46
46
 
47
+ def test_internal_subset_nil_ids
48
+ doc = LibXML::XML::Document.new
49
+ doc.root = LibXML::XML::Node.new('test')
50
+ dtd = LibXML::XML::Dtd.new(nil, nil, 'test', doc, true)
51
+ assert_equal('test', dtd.name)
52
+ assert_nil(dtd.external_id)
53
+ assert_nil(dtd.uri)
54
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE test>\n<test/>\n", doc.to_s)
55
+ end
56
+
47
57
  def test_external_subset
48
58
  xhtml_dtd = LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil)
49
59
  assert xhtml_dtd.name.nil?
@@ -112,14 +122,12 @@ class TestDtd < Minitest::Test
112
122
  errors.clear
113
123
  LibXML::XML::Parser.string(xml, options: LibXML::XML::Parser::Options::DTDLOAD).parse
114
124
  assert_equal(1, errors.length)
115
- assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
116
- errors[0].to_s)
125
+ assert_match(/Warning: failed to load.*test\.dtd/, errors[0].to_s)
117
126
 
118
127
  errors = Array.new
119
128
  LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse
120
129
  assert_equal(1, errors.length)
121
- assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
122
- errors[0].to_s)
130
+ assert_match(/Warning: failed to load.*test\.dtd/, errors[0].to_s)
123
131
  ensure
124
132
  LibXML::XML::Error.reset_handler
125
133
  end
@@ -1,115 +1,115 @@
1
- # encoding: UTF-8
2
- require_relative './test_helper'
3
-
4
- class SaxEncodingCallbacks
5
- attr_reader :encoding
6
- attr_accessor :assertions
7
- include Minitest::Assertions
8
-
9
- def initialize
10
- @assertions = 0
11
- @encoding = Encoding::UTF_8
12
- end
13
-
14
- # Called for a CDATA block event.
15
- def on_cdata_block(cdata)
16
- assert_equal(self.encoding, cdata.encoding)
17
- end
18
-
19
- # Called for a characters event.
20
- def on_characters(chars)
21
- assert_equal(self.encoding, chars.encoding)
22
- end
23
-
24
- # Called for a comment event.
25
- def on_comment(msg)
26
- assert_equal(self.encoding, msg.encoding)
27
- end
28
-
29
- # Called for a end document event.
30
- def on_end_document
31
- end
32
-
33
- # Called for a end element event.
34
- def on_end_element_ns(name, prefix, uri)
35
- assert_equal(self.encoding, name.encoding)
36
- assert_equal(self.encoding, prefix.encoding) if prefix
37
- assert_equal(self.encoding, uri.encoding) if uri
38
- end
39
-
40
- # Called for parser errors.
41
- def on_error(msg)
42
- assert_equal(self.encoding, msg.encoding)
43
- end
44
-
45
- # Called for an external subset event.
46
- def on_external_subset(name, external_id, system_id)
47
- assert_equal(self.encoding, name.encoding)
48
- assert_equal(self.encoding, external_id.encoding)
49
- assert_equal(self.encoding, system_id.encoding)
50
- end
51
-
52
- # Called for an external subset notification event.
53
- def on_has_external_subset
54
- end
55
-
56
- # Called for an internal subset notification event.
57
- def on_has_internal_subset
58
- end
59
-
60
- # Called for an internal subset event.
61
- def on_internal_subset(name, external_id, system_id)
62
- assert_equal(self.encoding, name.encoding)
63
- assert_equal(self.encoding, external_id.encoding)
64
- assert_equal(self.encoding, system_id.encoding)
65
- end
66
-
67
- # Called for 'is standalone' event.
68
- def on_is_standalone
69
- end
70
-
71
- # Called for an processing instruction event.
72
- def on_processing_instruction(target, data)
73
- assert_equal(self.encoding, target.encoding)
74
- assert_equal(self.encoding, data.encoding)
75
- end
76
-
77
- # Called for a reference event.
78
- def on_reference(name)
79
- assert_equal(self.encoding, name.encoding)
80
- end
81
-
82
- # Called for a start document event.
83
- def on_start_document
84
- end
85
-
86
- # Called for a start element event.
87
- def on_start_element_ns(name, attributes, prefix, uri, namespaces)
88
- assert_equal(self.encoding, name.encoding) if name
89
- assert_equal(self.encoding, prefix.encoding) if prefix
90
- assert_equal(self.encoding, uri.encoding) if uri
91
- end
92
- end
93
-
94
- class TestEncodingSax < Minitest::Test
95
- def setup
96
- Encoding.default_internal = nil
97
- end
98
-
99
- def file_for_encoding(encoding)
100
- file_name = "model/bands.#{encoding.name.downcase}.xml"
101
- File.join(File.dirname(__FILE__), file_name)
102
- end
103
-
104
- def test_encoding_iso_8859_1
105
- parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
106
- parser.callbacks = SaxEncodingCallbacks.new
107
- parser.parse
108
- end
109
-
110
- def test_encoding_utf8
111
- parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
112
- parser.callbacks = SaxEncodingCallbacks.new
113
- parser.parse
114
- end
1
+ # encoding: UTF-8
2
+ require_relative './test_helper'
3
+
4
+ class SaxEncodingCallbacks
5
+ attr_reader :encoding
6
+ attr_accessor :assertions
7
+ include Minitest::Assertions
8
+
9
+ def initialize
10
+ @assertions = 0
11
+ @encoding = Encoding::UTF_8
12
+ end
13
+
14
+ # Called for a CDATA block event.
15
+ def on_cdata_block(cdata)
16
+ assert_equal(self.encoding, cdata.encoding)
17
+ end
18
+
19
+ # Called for a characters event.
20
+ def on_characters(chars)
21
+ assert_equal(self.encoding, chars.encoding)
22
+ end
23
+
24
+ # Called for a comment event.
25
+ def on_comment(msg)
26
+ assert_equal(self.encoding, msg.encoding)
27
+ end
28
+
29
+ # Called for a end document event.
30
+ def on_end_document
31
+ end
32
+
33
+ # Called for a end element event.
34
+ def on_end_element_ns(name, prefix, uri)
35
+ assert_equal(self.encoding, name.encoding)
36
+ assert_equal(self.encoding, prefix.encoding) if prefix
37
+ assert_equal(self.encoding, uri.encoding) if uri
38
+ end
39
+
40
+ # Called for parser errors.
41
+ def on_error(msg)
42
+ assert_equal(self.encoding, msg.encoding)
43
+ end
44
+
45
+ # Called for an external subset event.
46
+ def on_external_subset(name, external_id, system_id)
47
+ assert_equal(self.encoding, name.encoding)
48
+ assert_equal(self.encoding, external_id.encoding)
49
+ assert_equal(self.encoding, system_id.encoding)
50
+ end
51
+
52
+ # Called for an external subset notification event.
53
+ def on_has_external_subset
54
+ end
55
+
56
+ # Called for an internal subset notification event.
57
+ def on_has_internal_subset
58
+ end
59
+
60
+ # Called for an internal subset event.
61
+ def on_internal_subset(name, external_id, system_id)
62
+ assert_equal(self.encoding, name.encoding)
63
+ assert_equal(self.encoding, external_id.encoding)
64
+ assert_equal(self.encoding, system_id.encoding)
65
+ end
66
+
67
+ # Called for 'is standalone' event.
68
+ def on_is_standalone
69
+ end
70
+
71
+ # Called for an processing instruction event.
72
+ def on_processing_instruction(target, data)
73
+ assert_equal(self.encoding, target.encoding)
74
+ assert_equal(self.encoding, data.encoding)
75
+ end
76
+
77
+ # Called for a reference event.
78
+ def on_reference(name)
79
+ assert_equal(self.encoding, name.encoding)
80
+ end
81
+
82
+ # Called for a start document event.
83
+ def on_start_document
84
+ end
85
+
86
+ # Called for a start element event.
87
+ def on_start_element_ns(name, attributes, prefix, uri, namespaces)
88
+ assert_equal(self.encoding, name.encoding) if name
89
+ assert_equal(self.encoding, prefix.encoding) if prefix
90
+ assert_equal(self.encoding, uri.encoding) if uri
91
+ end
92
+ end
93
+
94
+ class TestEncodingSax < Minitest::Test
95
+ def setup
96
+ Encoding.default_internal = nil
97
+ end
98
+
99
+ def file_for_encoding(encoding)
100
+ file_name = "model/bands.#{encoding.name.downcase}.xml"
101
+ File.join(File.dirname(__FILE__), file_name)
102
+ end
103
+
104
+ def test_encoding_iso_8859_1
105
+ parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
106
+ parser.callbacks = SaxEncodingCallbacks.new
107
+ parser.parse
108
+ end
109
+
110
+ def test_encoding_utf8
111
+ parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
112
+ parser.callbacks = SaxEncodingCallbacks.new
113
+ parser.parse
114
+ end
115
115
  end
data/test/test_error.rb CHANGED
@@ -71,8 +71,11 @@ class TestError < Minitest::Test
71
71
  else
72
72
  LibXML::XML::Error.reset_handler
73
73
  end
74
-
75
- assert_equal(LibXML::XML::Error.get_handler, saved_handler)
74
+ if saved_handler.nil?
75
+ assert_nil(LibXML::XML::Error.get_handler)
76
+ else
77
+ assert_equal(LibXML::XML::Error.get_handler, saved_handler)
78
+ end
76
79
  end
77
80
 
78
81
  def test_verbose_handler
@@ -151,7 +154,7 @@ class TestError < Minitest::Test
151
154
  end
152
155
 
153
156
  def test_double_parse_register_handler
154
- LibXML::XML::Parser.register_error_handler(lambda {|msg| nil })
157
+ LibXML::XML::Error.set_handler {|msg| nil }
155
158
  parser = LibXML::XML::Parser.string("<test>something</test>")
156
159
  parser.parse
157
160
 
data/test/test_helper.rb CHANGED
@@ -17,4 +17,5 @@ end
17
17
  STDOUT.write "\nlibxml2: #{LibXML::XML::LIBXML_VERSION}\n#{RUBY_DESCRIPTION}\n\n"
18
18
 
19
19
  require 'minitest/autorun'
20
+ Minitest.load_plugins
20
21
 
@@ -21,7 +21,7 @@ class HTMLParserTest < Minitest::Test
21
21
  LibXML::XML::HTMLParser.file('i_dont_exist.xml')
22
22
  end
23
23
 
24
- assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
24
+ assert_match(/Warning: failed to load.*i_dont_exist\.xml/, error.to_s)
25
25
  end
26
26
 
27
27
  def test_nil_file
@@ -141,7 +141,11 @@ class HTMLParserTest < Minitest::Test
141
141
  html = "hello world"
142
142
  parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOIMPLIED)
143
143
  doc = parser.parse
144
- assert_equal("<p>#{html}</p>", doc.root.to_s)
144
+ if Gem::Version.new(LibXML::XML::LIBXML_VERSION) >= Gem::Version.new("2.14")
145
+ assert_nil(doc.root)
146
+ else
147
+ assert_equal("<p>#{html}</p>", doc.root.to_s)
148
+ end
145
149
  end
146
150
 
147
151
  def test_comment
@@ -1,23 +1,23 @@
1
- # encoding: UTF-8
2
-
3
- require_relative './test_helper'
4
-
5
-
6
- class TestHtmlParserContext < Minitest::Test
7
- def test_default_options
8
- context = LibXML::XML::HTMLParser::Context.new
9
- assert_equal(0, context.options)
10
- end
11
-
12
- def test_no_options
13
- context = LibXML::XML::HTMLParser::Context.new
14
- context.options = 0
15
- assert_equal(0, context.options)
16
- end
17
-
18
- def test_options
19
- context = LibXML::XML::HTMLParser::Context.new
20
- context.options = LibXML::XML::HTMLParser::Options::NOERROR
21
- assert_equal(LibXML::XML::HTMLParser::Options::NOERROR, context.options)
22
- end
1
+ # encoding: UTF-8
2
+
3
+ require_relative './test_helper'
4
+
5
+
6
+ class TestHtmlParserContext < Minitest::Test
7
+ def test_default_options
8
+ context = LibXML::XML::HTMLParser::Context.new
9
+ assert_equal(0, context.options)
10
+ end
11
+
12
+ def test_no_options
13
+ context = LibXML::XML::HTMLParser::Context.new
14
+ context.options = 0
15
+ assert_equal(0, context.options)
16
+ end
17
+
18
+ def test_options
19
+ context = LibXML::XML::HTMLParser::Context.new
20
+ context.options = LibXML::XML::HTMLParser::Options::NOERROR
21
+ assert_equal(LibXML::XML::HTMLParser::Options::NOERROR, context.options)
22
+ end
23
23
  end