libxml-ruby 5.0.6 → 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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/{HISTORY → CHANGELOG.md} +875 -930
  3. data/LICENSE +20 -20
  4. data/README.md +67 -0
  5. data/Rakefile +13 -34
  6. data/ext/libxml/extconf.rb +34 -20
  7. data/ext/libxml/libxml.c +2 -14
  8. data/ext/libxml/ruby_libxml.h +1 -1
  9. data/ext/libxml/ruby_xml_attr.c +27 -22
  10. data/ext/libxml/ruby_xml_attr.h +1 -0
  11. data/ext/libxml/ruby_xml_attr_decl.c +19 -12
  12. data/ext/libxml/ruby_xml_attributes.c +18 -9
  13. data/ext/libxml/ruby_xml_document.c +111 -98
  14. data/ext/libxml/ruby_xml_document.h +1 -0
  15. data/ext/libxml/ruby_xml_dtd.c +49 -19
  16. data/ext/libxml/ruby_xml_dtd.h +1 -0
  17. data/ext/libxml/ruby_xml_html_parser.c +1 -1
  18. data/ext/libxml/ruby_xml_html_parser_context.c +19 -6
  19. data/ext/libxml/ruby_xml_html_parser_context.h +1 -0
  20. data/ext/libxml/ruby_xml_input_cbg.c +45 -17
  21. data/ext/libxml/ruby_xml_io.c +3 -1
  22. data/ext/libxml/ruby_xml_namespace.c +20 -12
  23. data/ext/libxml/ruby_xml_namespace.h +1 -0
  24. data/ext/libxml/ruby_xml_namespaces.c +40 -20
  25. data/ext/libxml/ruby_xml_node.c +71 -32
  26. data/ext/libxml/ruby_xml_node.h +2 -0
  27. data/ext/libxml/ruby_xml_parser.c +1 -1
  28. data/ext/libxml/ruby_xml_parser_context.c +54 -47
  29. data/ext/libxml/ruby_xml_parser_context.h +1 -0
  30. data/ext/libxml/ruby_xml_reader.c +25 -15
  31. data/ext/libxml/ruby_xml_registry.c +31 -0
  32. data/ext/libxml/ruby_xml_registry.h +22 -0
  33. data/ext/libxml/ruby_xml_relaxng.c +21 -5
  34. data/ext/libxml/ruby_xml_relaxng.h +1 -0
  35. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  36. data/ext/libxml/ruby_xml_schema.c +18 -11
  37. data/ext/libxml/ruby_xml_schema.h +1 -0
  38. data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
  39. data/ext/libxml/ruby_xml_schema_element.c +8 -8
  40. data/ext/libxml/ruby_xml_schema_facet.c +7 -7
  41. data/ext/libxml/ruby_xml_schema_type.c +12 -19
  42. data/ext/libxml/ruby_xml_version.h +4 -4
  43. data/ext/libxml/ruby_xml_writer.c +18 -6
  44. data/ext/libxml/ruby_xml_xpath.c +2 -2
  45. data/ext/libxml/ruby_xml_xpath.h +1 -1
  46. data/ext/libxml/ruby_xml_xpath_context.c +72 -26
  47. data/ext/libxml/ruby_xml_xpath_expression.c +11 -5
  48. data/ext/libxml/ruby_xml_xpath_expression.h +1 -0
  49. data/ext/libxml/ruby_xml_xpath_object.c +69 -54
  50. data/ext/libxml/ruby_xml_xpath_object.h +3 -1
  51. data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
  52. data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
  53. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  54. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  55. data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
  56. data/lib/libxml/document.rb +0 -29
  57. data/lib/libxml/error.rb +30 -3
  58. data/lib/libxml/html_parser.rb +0 -16
  59. data/lib/libxml/node.rb +1 -3
  60. data/lib/libxml/parser.rb +0 -8
  61. data/lib/libxml/schema/attribute.rb +27 -19
  62. data/lib/libxml/schema/element.rb +20 -0
  63. data/lib/libxml/schema/type.rb +44 -21
  64. data/lib/libxml/schema.rb +47 -47
  65. data/lib/libxml-ruby.rb +30 -30
  66. data/libxml-ruby.gemspec +12 -16
  67. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  68. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  69. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  70. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  71. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  72. data/test/c14n/result/with-comments/example-1 +5 -5
  73. data/test/c14n/result/with-comments/example-2 +10 -10
  74. data/test/c14n/result/with-comments/example-3 +13 -13
  75. data/test/c14n/result/with-comments/example-4 +8 -8
  76. data/test/c14n/result/with-comments/example-5 +3 -3
  77. data/test/c14n/result/without-comments/example-1 +3 -3
  78. data/test/c14n/result/without-comments/example-2 +10 -10
  79. data/test/c14n/result/without-comments/example-3 +13 -13
  80. data/test/c14n/result/without-comments/example-4 +8 -8
  81. data/test/c14n/result/without-comments/example-5 +2 -2
  82. data/test/test_attr.rb +179 -180
  83. data/test/test_attr_decl.rb +131 -131
  84. data/test/test_attributes.rb +135 -135
  85. data/test/test_canonicalize.rb +122 -120
  86. data/test/test_document.rb +2 -4
  87. data/test/test_dtd.rb +12 -4
  88. data/test/test_encoding_sax.rb +114 -114
  89. data/test/test_error.rb +1 -1
  90. data/test/test_html_parser.rb +6 -2
  91. data/test/test_html_parser_context.rb +22 -22
  92. data/test/test_input_callbacks.rb +36 -0
  93. data/test/test_namespace.rb +1 -1
  94. data/test/test_namespaces.rb +200 -200
  95. data/test/test_node.rb +16 -0
  96. data/test/test_node_cdata.rb +50 -50
  97. data/test/test_node_comment.rb +32 -32
  98. data/test/test_node_copy.rb +40 -40
  99. data/test/test_node_edit.rb +176 -158
  100. data/test/test_node_pi.rb +37 -37
  101. data/test/test_node_text.rb +69 -69
  102. data/test/test_node_xlink.rb +28 -28
  103. data/test/test_parser.rb +5 -41
  104. data/test/test_parser_context.rb +198 -198
  105. data/test/test_properties.rb +38 -38
  106. data/test/test_reader.rb +55 -6
  107. data/test/test_relaxng.rb +59 -53
  108. data/test/test_sax_parser.rb +345 -345
  109. data/test/test_schema.rb +28 -0
  110. data/test/test_traversal.rb +152 -152
  111. data/test/test_writer.rb +0 -31
  112. data/test/test_xinclude.rb +20 -20
  113. data/test/test_xml.rb +3 -7
  114. data/test/test_xpath.rb +244 -244
  115. data/test/test_xpath_context.rb +87 -87
  116. data/test/test_xpath_expression.rb +37 -37
  117. metadata +32 -25
  118. data/README.rdoc +0 -208
  119. data/ext/libxml/extconf.h +0 -4
  120. data/ext/libxml/ruby_xml_cbg.c +0 -85
  121. data/lib/libxml/hpricot.rb +0 -78
  122. data/lib/libxml.rb +0 -5
  123. data/lib/xml/libxml.rb +0 -10
  124. data/lib/xml.rb +0 -14
  125. data/script/benchmark/depixelate +0 -634
  126. data/script/benchmark/hamlet.xml +0 -9055
  127. data/script/benchmark/parsecount +0 -170
  128. data/script/benchmark/sock_entries.xml +0 -507
  129. data/script/benchmark/throughput +0 -41
  130. data/script/test +0 -6
  131. 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
@@ -154,7 +154,7 @@ class TestError < Minitest::Test
154
154
  end
155
155
 
156
156
  def test_double_parse_register_handler
157
- LibXML::XML::Parser.register_error_handler(lambda {|msg| nil })
157
+ LibXML::XML::Error.set_handler {|msg| nil }
158
158
  parser = LibXML::XML::Parser.string("<test>something</test>")
159
159
  parser.parse
160
160
 
@@ -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
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative './test_helper'
4
+
5
+ class InputCallbacksGCStressRepro
6
+ def run
7
+ scheme_name = 'input-callback-gc://'
8
+
9
+ callback_class = Class.new do
10
+ def self.document_query(_uri)
11
+ '<root/>'
12
+ end
13
+ end
14
+ LibXML::XML::InputCallbacks.add_scheme(scheme_name, callback_class)
15
+ callback_class = nil
16
+
17
+ document = LibXML::XML::Document.file("#{scheme_name}fixture.xml")
18
+ document.root.name
19
+ ensure
20
+ LibXML::XML::InputCallbacks.remove_scheme(scheme_name)
21
+ end
22
+ end
23
+
24
+ class TestInputCallbacks < Minitest::Test
25
+ def setup
26
+ GC.stress = true
27
+ end
28
+
29
+ def teardown
30
+ GC.stress = false
31
+ end
32
+
33
+ def test_add_scheme_auto_registers_and_survives_gc_stress
34
+ assert_equal('root', InputCallbacksGCStressRepro.new.run)
35
+ end
36
+ end
@@ -31,7 +31,7 @@ class TestNS < Minitest::Test
31
31
  error = assert_raises(TypeError) do
32
32
  LibXML::XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
33
33
  end
34
- assert_equal('wrong argument type nil (expected Data)', error.to_s)
34
+ assert_match(/wrong argument type nil/, error.to_s)
35
35
  end
36
36
 
37
37
  def test_duplicate_ns