libxml-ruby 2.9.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +790 -0
  3. data/LICENSE +21 -0
  4. data/MANIFEST +166 -0
  5. data/README.rdoc +184 -0
  6. data/Rakefile +81 -0
  7. data/ext/libxml/extconf.h +4 -0
  8. data/ext/libxml/extconf.rb +57 -0
  9. data/ext/libxml/libxml.c +80 -0
  10. data/ext/libxml/libxml_ruby.def +35 -0
  11. data/ext/libxml/ruby_libxml.h +75 -0
  12. data/ext/libxml/ruby_xml.c +977 -0
  13. data/ext/libxml/ruby_xml.h +20 -0
  14. data/ext/libxml/ruby_xml_attr.c +333 -0
  15. data/ext/libxml/ruby_xml_attr.h +12 -0
  16. data/ext/libxml/ruby_xml_attr_decl.c +153 -0
  17. data/ext/libxml/ruby_xml_attr_decl.h +11 -0
  18. data/ext/libxml/ruby_xml_attributes.c +275 -0
  19. data/ext/libxml/ruby_xml_attributes.h +15 -0
  20. data/ext/libxml/ruby_xml_cbg.c +85 -0
  21. data/ext/libxml/ruby_xml_document.c +1133 -0
  22. data/ext/libxml/ruby_xml_document.h +11 -0
  23. data/ext/libxml/ruby_xml_dtd.c +261 -0
  24. data/ext/libxml/ruby_xml_dtd.h +9 -0
  25. data/ext/libxml/ruby_xml_encoding.c +262 -0
  26. data/ext/libxml/ruby_xml_encoding.h +19 -0
  27. data/ext/libxml/ruby_xml_error.c +996 -0
  28. data/ext/libxml/ruby_xml_error.h +12 -0
  29. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  30. data/ext/libxml/ruby_xml_html_parser.h +10 -0
  31. data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
  32. data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
  33. data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
  34. data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
  35. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  36. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  37. data/ext/libxml/ruby_xml_io.c +52 -0
  38. data/ext/libxml/ruby_xml_io.h +10 -0
  39. data/ext/libxml/ruby_xml_namespace.c +153 -0
  40. data/ext/libxml/ruby_xml_namespace.h +10 -0
  41. data/ext/libxml/ruby_xml_namespaces.c +293 -0
  42. data/ext/libxml/ruby_xml_namespaces.h +9 -0
  43. data/ext/libxml/ruby_xml_node.c +1446 -0
  44. data/ext/libxml/ruby_xml_node.h +11 -0
  45. data/ext/libxml/ruby_xml_parser.c +94 -0
  46. data/ext/libxml/ruby_xml_parser.h +12 -0
  47. data/ext/libxml/ruby_xml_parser_context.c +999 -0
  48. data/ext/libxml/ruby_xml_parser_context.h +10 -0
  49. data/ext/libxml/ruby_xml_parser_options.c +66 -0
  50. data/ext/libxml/ruby_xml_parser_options.h +12 -0
  51. data/ext/libxml/ruby_xml_reader.c +1226 -0
  52. data/ext/libxml/ruby_xml_reader.h +17 -0
  53. data/ext/libxml/ruby_xml_relaxng.c +110 -0
  54. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  55. data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
  56. data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
  57. data/ext/libxml/ruby_xml_sax_parser.c +120 -0
  58. data/ext/libxml/ruby_xml_sax_parser.h +10 -0
  59. data/ext/libxml/ruby_xml_schema.c +300 -0
  60. data/ext/libxml/ruby_xml_schema.h +809 -0
  61. data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
  62. data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
  63. data/ext/libxml/ruby_xml_schema_element.c +94 -0
  64. data/ext/libxml/ruby_xml_schema_element.h +14 -0
  65. data/ext/libxml/ruby_xml_schema_facet.c +52 -0
  66. data/ext/libxml/ruby_xml_schema_facet.h +13 -0
  67. data/ext/libxml/ruby_xml_schema_type.c +259 -0
  68. data/ext/libxml/ruby_xml_schema_type.h +9 -0
  69. data/ext/libxml/ruby_xml_version.h +9 -0
  70. data/ext/libxml/ruby_xml_writer.c +1136 -0
  71. data/ext/libxml/ruby_xml_writer.h +10 -0
  72. data/ext/libxml/ruby_xml_xinclude.c +16 -0
  73. data/ext/libxml/ruby_xml_xinclude.h +11 -0
  74. data/ext/libxml/ruby_xml_xpath.c +188 -0
  75. data/ext/libxml/ruby_xml_xpath.h +13 -0
  76. data/ext/libxml/ruby_xml_xpath_context.c +360 -0
  77. data/ext/libxml/ruby_xml_xpath_context.h +9 -0
  78. data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
  79. data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
  80. data/ext/libxml/ruby_xml_xpath_object.c +335 -0
  81. data/ext/libxml/ruby_xml_xpath_object.h +17 -0
  82. data/ext/libxml/ruby_xml_xpointer.c +99 -0
  83. data/ext/libxml/ruby_xml_xpointer.h +11 -0
  84. data/ext/vc/libxml_ruby.sln +26 -0
  85. data/lib/2.3/libxml_ruby.so +0 -0
  86. data/lib/libs/libiconv-2.dll +0 -0
  87. data/lib/libs/libxml2-2.dll +0 -0
  88. data/lib/libs/zlib1.dll +0 -0
  89. data/lib/libxml.rb +35 -0
  90. data/lib/libxml/attr.rb +123 -0
  91. data/lib/libxml/attr_decl.rb +80 -0
  92. data/lib/libxml/attributes.rb +14 -0
  93. data/lib/libxml/document.rb +194 -0
  94. data/lib/libxml/error.rb +95 -0
  95. data/lib/libxml/hpricot.rb +78 -0
  96. data/lib/libxml/html_parser.rb +96 -0
  97. data/lib/libxml/namespace.rb +62 -0
  98. data/lib/libxml/namespaces.rb +38 -0
  99. data/lib/libxml/node.rb +399 -0
  100. data/lib/libxml/ns.rb +22 -0
  101. data/lib/libxml/parser.rb +367 -0
  102. data/lib/libxml/properties.rb +23 -0
  103. data/lib/libxml/reader.rb +29 -0
  104. data/lib/libxml/sax_callbacks.rb +180 -0
  105. data/lib/libxml/sax_parser.rb +58 -0
  106. data/lib/libxml/schema.rb +67 -0
  107. data/lib/libxml/schema/attribute.rb +19 -0
  108. data/lib/libxml/schema/element.rb +27 -0
  109. data/lib/libxml/schema/type.rb +29 -0
  110. data/lib/libxml/tree.rb +29 -0
  111. data/lib/libxml/xpath_object.rb +16 -0
  112. data/lib/xml.rb +14 -0
  113. data/lib/xml/libxml.rb +10 -0
  114. data/libxml-ruby.gemspec +47 -0
  115. data/script/benchmark/depixelate +634 -0
  116. data/script/benchmark/hamlet.xml +9055 -0
  117. data/script/benchmark/parsecount +170 -0
  118. data/script/benchmark/sock_entries.xml +507 -0
  119. data/script/benchmark/throughput +41 -0
  120. data/script/test +6 -0
  121. data/setup.rb +1585 -0
  122. data/test/c14n/given/doc.dtd +1 -0
  123. data/test/c14n/given/example-1.xml +14 -0
  124. data/test/c14n/given/example-2.xml +11 -0
  125. data/test/c14n/given/example-3.xml +18 -0
  126. data/test/c14n/given/example-4.xml +9 -0
  127. data/test/c14n/given/example-5.xml +12 -0
  128. data/test/c14n/given/example-6.xml +2 -0
  129. data/test/c14n/given/example-7.xml +11 -0
  130. data/test/c14n/given/example-8.xml +11 -0
  131. data/test/c14n/given/example-8.xpath +10 -0
  132. data/test/c14n/given/world.txt +1 -0
  133. data/test/c14n/result/1-1-without-comments/example-1 +4 -0
  134. data/test/c14n/result/1-1-without-comments/example-2 +11 -0
  135. data/test/c14n/result/1-1-without-comments/example-3 +14 -0
  136. data/test/c14n/result/1-1-without-comments/example-4 +9 -0
  137. data/test/c14n/result/1-1-without-comments/example-5 +3 -0
  138. data/test/c14n/result/1-1-without-comments/example-6 +1 -0
  139. data/test/c14n/result/1-1-without-comments/example-7 +1 -0
  140. data/test/c14n/result/1-1-without-comments/example-8 +1 -0
  141. data/test/c14n/result/with-comments/example-1 +6 -0
  142. data/test/c14n/result/with-comments/example-2 +11 -0
  143. data/test/c14n/result/with-comments/example-3 +14 -0
  144. data/test/c14n/result/with-comments/example-4 +9 -0
  145. data/test/c14n/result/with-comments/example-5 +4 -0
  146. data/test/c14n/result/with-comments/example-6 +1 -0
  147. data/test/c14n/result/with-comments/example-7 +1 -0
  148. data/test/c14n/result/without-comments/example-1 +4 -0
  149. data/test/c14n/result/without-comments/example-2 +11 -0
  150. data/test/c14n/result/without-comments/example-3 +14 -0
  151. data/test/c14n/result/without-comments/example-4 +9 -0
  152. data/test/c14n/result/without-comments/example-5 +3 -0
  153. data/test/c14n/result/without-comments/example-6 +1 -0
  154. data/test/c14n/result/without-comments/example-7 +1 -0
  155. data/test/model/atom.xml +13 -0
  156. data/test/model/bands.iso-8859-1.xml +5 -0
  157. data/test/model/bands.utf-8.xml +5 -0
  158. data/test/model/bands.xml +5 -0
  159. data/test/model/books.xml +154 -0
  160. data/test/model/merge_bug_data.xml +58 -0
  161. data/test/model/ruby-lang.html +238 -0
  162. data/test/model/rubynet.xml +79 -0
  163. data/test/model/rubynet_project +1 -0
  164. data/test/model/shiporder.rnc +28 -0
  165. data/test/model/shiporder.rng +86 -0
  166. data/test/model/shiporder.xml +23 -0
  167. data/test/model/shiporder.xsd +40 -0
  168. data/test/model/soap.xml +27 -0
  169. data/test/model/xinclude.xml +5 -0
  170. data/test/tc_attr.rb +181 -0
  171. data/test/tc_attr_decl.rb +132 -0
  172. data/test/tc_attributes.rb +142 -0
  173. data/test/tc_canonicalize.rb +124 -0
  174. data/test/tc_deprecated_require.rb +12 -0
  175. data/test/tc_document.rb +125 -0
  176. data/test/tc_document_write.rb +195 -0
  177. data/test/tc_dtd.rb +128 -0
  178. data/test/tc_encoding.rb +126 -0
  179. data/test/tc_encoding_sax.rb +115 -0
  180. data/test/tc_error.rb +179 -0
  181. data/test/tc_html_parser.rb +161 -0
  182. data/test/tc_html_parser_context.rb +23 -0
  183. data/test/tc_namespace.rb +61 -0
  184. data/test/tc_namespaces.rb +209 -0
  185. data/test/tc_node.rb +215 -0
  186. data/test/tc_node_cdata.rb +50 -0
  187. data/test/tc_node_comment.rb +32 -0
  188. data/test/tc_node_copy.rb +41 -0
  189. data/test/tc_node_edit.rb +174 -0
  190. data/test/tc_node_pi.rb +39 -0
  191. data/test/tc_node_text.rb +70 -0
  192. data/test/tc_node_write.rb +107 -0
  193. data/test/tc_node_xlink.rb +28 -0
  194. data/test/tc_parser.rb +375 -0
  195. data/test/tc_parser_context.rb +204 -0
  196. data/test/tc_properties.rb +38 -0
  197. data/test/tc_reader.rb +399 -0
  198. data/test/tc_relaxng.rb +53 -0
  199. data/test/tc_sax_parser.rb +319 -0
  200. data/test/tc_schema.rb +161 -0
  201. data/test/tc_traversal.rb +152 -0
  202. data/test/tc_writer.rb +447 -0
  203. data/test/tc_xinclude.rb +20 -0
  204. data/test/tc_xml.rb +225 -0
  205. data/test/tc_xpath.rb +244 -0
  206. data/test/tc_xpath_context.rb +88 -0
  207. data/test/tc_xpath_expression.rb +37 -0
  208. data/test/tc_xpointer.rb +72 -0
  209. data/test/test_helper.rb +16 -0
  210. data/test/test_suite.rb +49 -0
  211. metadata +344 -0
@@ -0,0 +1,128 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+
6
+ class TestDtd < Minitest::Test
7
+ def setup
8
+ xp = XML::Parser.string(<<-EOS)
9
+ <root>
10
+ <head a="ee" id="1">Colorado</head>
11
+ <descr>Lots of nice mountains</descr>
12
+ </root>
13
+ EOS
14
+ @doc = xp.parse
15
+ end
16
+
17
+ def teardown
18
+ @doc = nil
19
+ end
20
+
21
+ def dtd
22
+ XML::Dtd.new(<<-EOS)
23
+ <!ELEMENT root (head, descr)>
24
+ <!ELEMENT head (#PCDATA)>
25
+ <!ATTLIST head
26
+ id NMTOKEN #REQUIRED
27
+ a CDATA #IMPLIED
28
+ >
29
+ <!ELEMENT descr (#PCDATA)>
30
+ EOS
31
+ end
32
+
33
+ def test_internal_subset
34
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true
35
+ assert xhtml_dtd.name.nil?
36
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
37
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
38
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
39
+
40
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true
41
+ assert_equal "xhtml1", xhtml_dtd.name
42
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
43
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
44
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
45
+ end
46
+
47
+ def test_external_subset
48
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil
49
+ assert xhtml_dtd.name.nil?
50
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
51
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
52
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
53
+
54
+ xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1"
55
+ assert_equal "xhtml1", xhtml_dtd.name
56
+ assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
57
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
58
+ assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
59
+ end
60
+
61
+ def test_valid
62
+ assert(@doc.validate(dtd))
63
+ end
64
+
65
+ def test_node_type
66
+ assert_equal(XML::Node::DTD_NODE, dtd.node_type)
67
+ end
68
+
69
+ def test_invalid
70
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
71
+ @doc.root << new_node
72
+
73
+ error = assert_raises(XML::Error) do
74
+ @doc.validate(dtd)
75
+ end
76
+
77
+ # Check the error worked
78
+ refute_nil(error)
79
+ assert_kind_of(XML::Error, error)
80
+ assert_equal("Error: No declaration for element invalid.", error.message)
81
+ assert_equal(XML::Error::VALID, error.domain)
82
+ assert_equal(XML::Error::DTD_UNKNOWN_ELEM, error.code)
83
+ assert_equal(XML::Error::ERROR, error.level)
84
+ assert_nil(error.file)
85
+ assert_nil(error.line)
86
+ assert_equal('invalid', error.str1)
87
+ assert_equal('invalid', error.str2)
88
+ assert_nil(error.str3)
89
+ assert_equal(0, error.int1)
90
+ assert_equal(0, error.int2)
91
+ refute_nil(error.node)
92
+ assert_equal('invalid', error.node.name)
93
+ end
94
+
95
+ def test_external_dtd
96
+ xml = <<-EOS
97
+ <!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []>
98
+ <test>
99
+ <title>T1</title>
100
+ </test>
101
+ EOS
102
+
103
+ errors = Array.new
104
+ XML::Error.set_handler do |error|
105
+ errors << error
106
+ end
107
+
108
+ XML.default_load_external_dtd = false
109
+ doc = XML::Parser.string(xml).parse
110
+ assert_equal(0, errors.length)
111
+
112
+ errors.clear
113
+ XML.default_load_external_dtd = true
114
+ doc = XML::Parser.string(xml).parse
115
+ assert_equal(1, errors.length)
116
+ assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
117
+ errors[0].to_s)
118
+
119
+ errors = Array.new
120
+ doc = XML::Parser.string(xml, :options => XML::Parser::Options::DTDLOAD).parse
121
+ assert_equal(1, errors.length)
122
+ assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
123
+ errors[0].to_s)
124
+ ensure
125
+ XML.default_load_external_dtd = false
126
+ XML::Error.reset_handler
127
+ end
128
+ end
@@ -0,0 +1,126 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ # Code UTF8 Latin1 Hex
6
+ # m 109 109 6D
7
+ # ö 195 182 246 C3 B6 / F6
8
+ # t 116 116 74
9
+ # l 108 108 6C
10
+ # e 101 101 65
11
+ # y 121 121 79
12
+ # _ 95 95 5F
13
+ # c 99 99 63
14
+ # r 114 114 72
15
+ # ü 195 188 252 C3 BC / FC
16
+ # e 101 101 65
17
+
18
+ # See:
19
+ # http://en.wikipedia.org/wiki/ISO/IEC_8859-1
20
+ # http://en.wikipedia.org/wiki/List_of_Unicode_characters
21
+
22
+ class TestEncoding < Minitest::Test
23
+ def setup
24
+ Encoding.default_internal = nil
25
+ end
26
+
27
+ def file_for_encoding(encoding)
28
+ file_name = "model/bands.#{encoding.name.downcase}.xml"
29
+ File.join(File.dirname(__FILE__), file_name)
30
+ end
31
+
32
+ def load_encoding(encoding)
33
+ @encoding = encoding
34
+ file = file_for_encoding(encoding)
35
+
36
+ # Strip spaces to make testing easier
37
+ XML.default_keep_blanks = false
38
+ @doc = XML::Document.file(file)
39
+ XML.default_keep_blanks = true
40
+ end
41
+
42
+ def test_encoding
43
+ doc = XML::Document.new
44
+ assert_equal(XML::Encoding::NONE, doc.encoding)
45
+ assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) if defined?(Encoding)
46
+
47
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
48
+ doc = XML::Document.file(file)
49
+ assert_equal(XML::Encoding::UTF_8, doc.encoding)
50
+ assert_equal(Encoding::UTF_8, doc.rb_encoding) if defined?(Encoding)
51
+
52
+ doc.encoding = XML::Encoding::ISO_8859_1
53
+ assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
54
+ assert_equal(Encoding::ISO8859_1, doc.rb_encoding) if defined?(Encoding)
55
+ end
56
+
57
+ def test_no_internal_encoding_iso_8859_1
58
+ Encoding.default_internal = nil
59
+ load_encoding(Encoding::ISO_8859_1)
60
+ node = @doc.root.children.first
61
+
62
+ name = node.name
63
+ assert_equal(Encoding::UTF_8, name.encoding)
64
+ assert_equal("m\u00F6tley_cr\u00FCe", name)
65
+ assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101",
66
+ name.bytes.to_a.join(" "))
67
+ assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.",
68
+ node.content)
69
+
70
+ name = name.encode(Encoding::ISO_8859_1)
71
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
72
+ assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name)
73
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
74
+ name.bytes.to_a.join(" "))
75
+ assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1),
76
+ node.content.encode(Encoding::ISO_8859_1))
77
+ end
78
+
79
+ def test_internal_encoding_iso_8859_1
80
+ Encoding.default_internal = Encoding::ISO_8859_1
81
+ load_encoding(Encoding::ISO_8859_1)
82
+ node = @doc.root.children.first
83
+
84
+ name = node.name
85
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
86
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
87
+ name.bytes.to_a.join(" "))
88
+ assert_equal("m\xF6tley_cr\xFCe".force_encoding(Encoding::ISO_8859_1), name)
89
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
90
+ name.bytes.to_a.join(" "))
91
+ assert_equal("M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(Encoding::ISO_8859_1),
92
+ node.content.encode(Encoding::ISO_8859_1))
93
+ end
94
+
95
+ def test_no_internal_encoding_utf_8
96
+ Encoding.default_internal = nil
97
+ load_encoding(Encoding::UTF_8)
98
+ node = @doc.root.children.first
99
+
100
+ name = node.name
101
+ assert_equal(@encoding, name.encoding)
102
+ assert_equal("109 195 182 116 108 101 121 95 99 114 195 188 101",
103
+ name.bytes.to_a.join(" "))
104
+
105
+ name = name.encode(Encoding::ISO_8859_1)
106
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
107
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
108
+ name.bytes.to_a.join(" "))
109
+ end
110
+
111
+ def test_internal_encoding_utf_8
112
+ Encoding.default_internal = Encoding::ISO_8859_1
113
+ load_encoding(Encoding::UTF_8)
114
+ node = @doc.root.children.first
115
+
116
+ name = node.name
117
+ assert_equal(Encoding::ISO_8859_1, name.encoding)
118
+ assert_equal("109 246 116 108 101 121 95 99 114 252 101",
119
+ name.bytes.to_a.join(" "))
120
+ end
121
+
122
+ def test_encoding_conversions
123
+ assert_equal("UTF-8", XML::Encoding.to_s(XML::Encoding::UTF_8))
124
+ assert_equal(XML::Encoding::UTF_8, XML::Encoding.from_s("UTF-8"))
125
+ end
126
+ end
@@ -0,0 +1,115 @@
1
+ # encoding: UTF-8
2
+ require './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 = 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 = XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
112
+ parser.callbacks = SaxEncodingCallbacks.new
113
+ parser.parse
114
+ end
115
+ end
@@ -0,0 +1,179 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'stringio'
5
+
6
+ class TestError < Minitest::Test
7
+ def test_error_codes
8
+ assert_equal(4, XML::Error::DTD)
9
+ assert_equal(4, XML::Error.const_get('DTD'))
10
+
11
+ assert_equal(4, XML::Error::DOCUMENT_EMPTY)
12
+ assert_equal(4, XML::Error.const_get('DOCUMENT_EMPTY'))
13
+ end
14
+
15
+ def test_invalid_handler
16
+ assert_raises(RuntimeError) do
17
+ XML::Error.set_handler
18
+ end
19
+ end
20
+
21
+ def test_handler
22
+ exception = nil
23
+ XML::Error.set_handler do |error|
24
+ exception = error
25
+ end
26
+
27
+ # Raise the error
28
+ error = assert_raises(XML::Error) do
29
+ XML::Reader.string('<foo').read
30
+ end
31
+ assert_equal(exception, error)
32
+
33
+ # Check the handler worked
34
+ refute_nil(exception)
35
+ assert_kind_of(XML::Error, exception)
36
+ assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
37
+ assert_equal(XML::Error::PARSER, exception.domain)
38
+ assert_equal(XML::Error::GT_REQUIRED, exception.code)
39
+ assert_equal(XML::Error::FATAL, exception.level)
40
+ assert_nil(exception.file)
41
+ assert_equal(1, exception.line)
42
+ assert_equal('foo', exception.str1)
43
+ assert_nil(exception.str2)
44
+ assert_nil(exception.str3)
45
+ assert_equal(0, exception.int1)
46
+ assert_equal(5, exception.int2)
47
+ assert_nil(exception.node)
48
+ end
49
+
50
+ def test_reset_handler
51
+ exception = nil
52
+ XML::Error.set_handler do |error|
53
+ exception = error
54
+ end
55
+
56
+ XML::Error.reset_handler
57
+ XML::Reader.string('<foo')
58
+ assert_nil(exception)
59
+ end
60
+
61
+ def test_get_handler
62
+ assert_respond_to(XML::Error, :get_handler)
63
+ assert_equal(0, XML::Error.method(:get_handler).arity)
64
+
65
+ saved_handler = XML::Error.get_handler
66
+ XML::Error.set_handler{ puts "New handler" }
67
+ refute_equal(XML::Error.get_handler, saved_handler)
68
+
69
+ XML::Error.set_handler(&saved_handler)
70
+ assert_equal(XML::Error.get_handler, saved_handler)
71
+ end
72
+
73
+ def test_verbose_handler
74
+ XML::Error.set_handler(&XML::Error::VERBOSE_HANDLER)
75
+ output = StringIO.new
76
+ original_stderr = Object::STDERR
77
+
78
+ Object.const_set(:STDERR, output)
79
+ begin
80
+ assert_raises(XML::Error) do
81
+ XML::Parser.string('<foo><bar/></foz>').parse
82
+ end
83
+ ensure
84
+ Object.const_set(:STDERR, original_stderr)
85
+ end
86
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string)
87
+ end
88
+
89
+ def test_no_hanlder
90
+ XML::Error.reset_handler
91
+ output = StringIO.new
92
+ original_stderr = Object::STDERR
93
+
94
+ Object.const_set(:STDERR, output)
95
+ begin
96
+ assert_raises(XML::Error) do
97
+ XML::Parser.string('<foo><bar/></foz>').parse
98
+ end
99
+ ensure
100
+ Object.const_set(:STDERR, original_stderr)
101
+ end
102
+ assert_equal('', output.string)
103
+ end
104
+
105
+ def test_parse_error
106
+ exception = assert_raises(XML::Error) do
107
+ XML::Parser.string('<foo><bar/></foz>').parse
108
+ end
109
+
110
+ assert_instance_of(XML::Error, exception)
111
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
112
+ assert_equal(XML::Error::PARSER, exception.domain)
113
+ assert_equal(XML::Error::TAG_NAME_MISMATCH, exception.code)
114
+ assert_equal(XML::Error::FATAL, exception.level)
115
+ assert_nil(exception.file)
116
+ assert_equal(1, exception.line)
117
+ end
118
+
119
+ def test_xpath_error
120
+ doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
121
+
122
+ exception = assert_raises(XML::Error) do
123
+ doc.find('/foo[bar=test')
124
+ end
125
+
126
+ assert_instance_of(XML::Error, exception)
127
+ assert_equal("Error: Invalid predicate.", exception.message)
128
+ assert_equal(XML::Error::XPATH, exception.domain)
129
+ assert_equal(XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code)
130
+ assert_equal(XML::Error::ERROR, exception.level)
131
+ assert_nil(exception.file)
132
+ assert_nil(nil)
133
+ end
134
+
135
+ def test_double_parse
136
+ XML::Parser.register_error_handler(lambda {|msg| nil })
137
+ parser = XML::Parser.string("<test>something</test>")
138
+ parser.parse
139
+
140
+ error = assert_raises(XML::Error) do
141
+ # Try parsing a second time
142
+ parser.parse
143
+ end
144
+
145
+ assert_equal(" LibXML::XML::Error.", error.to_s)
146
+ end
147
+
148
+ def test_libxml_parser_empty_string
149
+ xp = XML::Parser.new
150
+
151
+ error = assert_raises(TypeError) do
152
+ xp.string = nil
153
+ end
154
+ assert_equal('wrong argument type nil (expected String)', error.to_s)
155
+
156
+ error = assert_raises(ArgumentError) do
157
+ xp.string = ''
158
+ end
159
+ assert_equal('Must specify a string with one or more characters', error.to_s)
160
+ end
161
+
162
+ def test_error_domain_to_s
163
+ exception = assert_raises(XML::Error) do
164
+ XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
165
+ end
166
+
167
+ assert_equal(XML::Error::PARSER, exception.domain)
168
+ assert_equal("PARSER",exception.domain_to_s)
169
+ end
170
+
171
+ def test_error_code_to_s
172
+ exception = assert_raises(XML::Error) do
173
+ XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
174
+ end
175
+ assert_equal(XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
176
+ assert_equal("ENTITYREF_SEMICOL_MISSING",exception.code_to_s)
177
+ end
178
+
179
+ end