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,53 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+
6
+ class TestRelaxNG < Minitest::Test
7
+ def setup
8
+ file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
9
+ @doc = XML::Document.file(file)
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def relaxng
17
+ document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.rng'))
18
+ relaxng = XML::RelaxNG.document(document)
19
+ end
20
+
21
+ def test_from_doc
22
+ assert_instance_of(XML::RelaxNG, relaxng)
23
+ end
24
+
25
+ def test_valid
26
+ assert(@doc.validate_relaxng(relaxng))
27
+ end
28
+
29
+ def test_invalid
30
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
31
+ @doc.root << new_node
32
+
33
+ error = assert_raises(XML::Error) do
34
+ @doc.validate_relaxng(relaxng)
35
+ end
36
+
37
+ refute_nil(error)
38
+ assert_kind_of(XML::Error, error)
39
+ assert(error.message.match(/Error: Did not expect element invalid there/))
40
+ assert_equal(XML::Error::RELAXNGV, error.domain)
41
+ assert_equal(XML::Error::LT_IN_ATTRIBUTE, error.code)
42
+ assert_equal(XML::Error::ERROR, error.level)
43
+ assert(error.file.match(/shiporder\.xml/))
44
+ assert_nil(error.line)
45
+ assert_equal('invalid', error.str1)
46
+ assert_nil(error.str2)
47
+ assert_nil(error.str3)
48
+ assert_equal(0, error.int1)
49
+ assert_equal(0, error.int2)
50
+ refute_nil(error.node)
51
+ assert_equal('invalid', error.node.name)
52
+ end
53
+ end
@@ -0,0 +1,319 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'stringio'
5
+
6
+ class DocTypeCallback
7
+ include XML::SaxParser::Callbacks
8
+ def on_start_element(element, attributes)
9
+ end
10
+ end
11
+
12
+ class TestCaseCallbacks
13
+ include XML::SaxParser::Callbacks
14
+
15
+ attr_accessor :result
16
+
17
+ def initialize
18
+ @result = Array.new
19
+ end
20
+
21
+ def on_cdata_block(cdata)
22
+ @result << "cdata: #{cdata}"
23
+ end
24
+
25
+ def on_characters(chars)
26
+ @result << "characters: #{chars}"
27
+ end
28
+
29
+ def on_comment(text)
30
+ @result << "comment: #{text}"
31
+ end
32
+
33
+ def on_end_document
34
+ @result << "end_document"
35
+ end
36
+
37
+ def on_end_element(name)
38
+ @result << "end_element: #{name}"
39
+ end
40
+
41
+ def on_end_element_ns(name, prefix, uri)
42
+ @result << "end_element_ns #{name}, prefix: #{prefix}, uri: #{uri}"
43
+ end
44
+
45
+ # Called for parser errors.
46
+ def on_error(error)
47
+ @result << "error: #{error}"
48
+ end
49
+
50
+ def on_processing_instruction(target, data)
51
+ @result << "pi: #{target} #{data}"
52
+ end
53
+
54
+ def on_start_document
55
+ @result << "startdoc"
56
+ end
57
+
58
+ def on_start_element(name, attributes)
59
+ attributes ||= Hash.new
60
+ @result << "start_element: #{name}, attr: #{attributes.inspect}"
61
+ end
62
+
63
+ def on_start_element_ns(name, attributes, prefix, uri, namespaces)
64
+ attributes ||= Hash.new
65
+ namespaces ||= Hash.new
66
+ @result << "start_element_ns: #{name}, attr: #{attributes.inspect}, prefix: #{prefix}, uri: #{uri}, ns: #{namespaces.inspect}"
67
+ end
68
+ end
69
+
70
+ class TestSaxParser < Minitest::Test
71
+ def saxtest_file
72
+ File.join(File.dirname(__FILE__), 'model/atom.xml')
73
+ end
74
+
75
+ def verify(parser)
76
+ result = parser.callbacks.result
77
+
78
+ i = -1
79
+ assert_equal("startdoc", result[i+=1])
80
+ assert_equal("pi: xml-stylesheet type=\"text/xsl\" href=\"my_stylesheet.xsl\"", result[i+=1])
81
+ assert_equal("start_element: feed, attr: {}", result[i+=1])
82
+ assert_equal("start_element_ns: feed, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {nil=>\"http://www.w3.org/2005/Atom\"}", result[i+=1])
83
+ assert_equal("characters: \n ", result[i+=1])
84
+ assert_equal("comment: Not a valid atom entry ", result[i+=1])
85
+ assert_equal("characters: \n ", result[i+=1])
86
+ assert_equal("start_element: entry, attr: {}", result[i+=1])
87
+ assert_equal("start_element_ns: entry, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
88
+ assert_equal("characters: \n ", result[i+=1])
89
+ assert_equal("start_element: title, attr: {\"type\"=>\"html\"}", result[i+=1])
90
+ assert_equal("start_element_ns: title, attr: {\"type\"=>\"html\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
91
+ assert_equal("cdata: <<strong>>", result[i+=1])
92
+ assert_equal("end_element: title", result[i+=1])
93
+ assert_equal("end_element_ns title, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
94
+ assert_equal("characters: \n ", result[i+=1])
95
+ assert_equal("start_element: content, attr: {\"type\"=>\"xhtml\"}", result[i+=1])
96
+ assert_equal("start_element_ns: content, attr: {\"type\"=>\"xhtml\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
97
+ assert_equal("characters: \n ", result[i+=1])
98
+ assert_equal("start_element: xhtml:div, attr: {}", result[i+=1])
99
+ assert_equal("start_element_ns: div, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {\"xhtml\"=>\"http://www.w3.org/1999/xhtml\"}", result[i+=1])
100
+ assert_equal("characters: \n ", result[i+=1])
101
+ assert_equal("start_element: xhtml:p, attr: {}", result[i+=1])
102
+ assert_equal("start_element_ns: p, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
103
+ assert_equal("characters: hi there", result[i+=1])
104
+ assert_equal("end_element: xhtml:p", result[i+=1])
105
+ assert_equal("end_element_ns p, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
106
+ assert_equal("characters: \n ", result[i+=1])
107
+ assert_equal("end_element: xhtml:div", result[i+=1])
108
+ assert_equal("end_element_ns div, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
109
+ assert_equal("characters: \n ", result[i+=1])
110
+ assert_equal("end_element: content", result[i+=1])
111
+ assert_equal("end_element_ns content, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
112
+ assert_equal("characters: \n ", result[i+=1])
113
+ assert_equal("end_element: entry", result[i+=1])
114
+ assert_equal("end_element_ns entry, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
115
+ assert_equal("characters: \n", result[i+=1])
116
+ assert_equal("end_element: feed", result[i+=1])
117
+ assert_equal("end_element_ns feed, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
118
+ assert_equal("end_document", result[i+=1])
119
+ end
120
+
121
+ def test_file
122
+ parser = XML::SaxParser.file(saxtest_file)
123
+ parser.callbacks = TestCaseCallbacks.new
124
+ parser.parse
125
+ verify(parser)
126
+ end
127
+
128
+ def test_file_no_callbacks
129
+ parser = XML::SaxParser.file(saxtest_file)
130
+ assert_equal true, parser.parse
131
+ end
132
+
133
+ def test_noexistent_file
134
+ error = assert_raises(XML::Error) do
135
+ XML::SaxParser.file('i_dont_exist.xml')
136
+ end
137
+
138
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
139
+ end
140
+
141
+ def test_nil_file
142
+ error = assert_raises(TypeError) do
143
+ XML::SaxParser.file(nil)
144
+ end
145
+
146
+ assert_match(/nil into String/, error.to_s)
147
+ end
148
+
149
+ def test_io
150
+ File.open(saxtest_file) do |file|
151
+ parser = XML::SaxParser.io(file)
152
+ parser.callbacks = TestCaseCallbacks.new
153
+ parser.parse
154
+ verify(parser)
155
+ end
156
+ end
157
+
158
+ def test_nil_io
159
+ error = assert_raises(TypeError) do
160
+ XML::HTMLParser.io(nil)
161
+ end
162
+
163
+ assert_equal("Must pass in an IO object", error.to_s)
164
+ end
165
+
166
+ def test_string_no_callbacks
167
+ xml = File.read(saxtest_file)
168
+ parser = XML::SaxParser.string(xml)
169
+ assert_equal true, parser.parse
170
+ end
171
+
172
+ def test_string
173
+ xml = File.read(saxtest_file)
174
+ parser = XML::SaxParser.string(xml)
175
+ parser.callbacks = TestCaseCallbacks.new
176
+ parser.parse
177
+ verify(parser)
178
+ end
179
+
180
+ def test_string_io
181
+ xml = File.read(saxtest_file)
182
+ io = StringIO.new(xml)
183
+ parser = XML::SaxParser.io(io)
184
+
185
+ parser.callbacks = TestCaseCallbacks.new
186
+ parser.parse
187
+ verify(parser)
188
+ end
189
+
190
+ def test_nil_string
191
+ error = assert_raises(TypeError) do
192
+ XML::SaxParser.string(nil)
193
+ end
194
+
195
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
196
+ end
197
+
198
+ def test_doctype
199
+ xml = <<-EOS
200
+ <?xml version="1.0" encoding="UTF-8"?>
201
+ <!DOCTYPE Results SYSTEM "results.dtd">
202
+ <Results>
203
+ <a>a1</a>
204
+ </Results>
205
+ EOS
206
+ parser = XML::SaxParser.string(xml)
207
+ parser.callbacks = DocTypeCallback.new
208
+ doc = parser.parse
209
+ refute_nil(doc)
210
+ end
211
+
212
+ def test_parse_warning
213
+ # Two xml PIs is a warning
214
+ xml = <<-EOS
215
+ <?xml version="1.0" encoding="utf-8"?>
216
+ <?xml-invalid?>
217
+ <Test/>
218
+ EOS
219
+
220
+ parser = XML::SaxParser.string(xml)
221
+ parser.callbacks = TestCaseCallbacks.new
222
+
223
+ parser.parse
224
+
225
+ # Check callbacks
226
+ result = parser.callbacks.result
227
+ i = -1
228
+ assert_equal("startdoc", result[i+=1])
229
+ assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
230
+ assert_equal("pi: xml-invalid ", result[i+=1])
231
+ assert_equal("start_element: Test, attr: {}", result[i+=1])
232
+ assert_equal("start_element_ns: Test, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
233
+ assert_equal("end_element: Test", result[i+=1])
234
+ assert_equal("end_element_ns Test, prefix: , uri: ", result[i+=1])
235
+ assert_equal("end_document", result[i+=1])
236
+ end
237
+
238
+ def test_parse_error
239
+ xml = <<-EOS
240
+ <Results>
241
+ EOS
242
+ parser = XML::SaxParser.string(xml)
243
+ parser.callbacks = TestCaseCallbacks.new
244
+
245
+ error = assert_raises(XML::Error) do
246
+ doc = parser.parse
247
+ end
248
+
249
+ # Check callbacks
250
+ result = parser.callbacks.result
251
+
252
+ i = -1
253
+ assert_equal("startdoc", result[i+=1])
254
+ assert_equal("start_element: Results, attr: {}", result[i+=1])
255
+ assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
256
+ assert_equal("characters: \n", result[i+=1])
257
+ assert_equal("error: Fatal error: Premature end of data in tag Results line 1 at :2.", result[i+=1])
258
+ assert_equal("end_document", result[i+=1])
259
+
260
+ refute_nil(error)
261
+ assert_kind_of(XML::Error, error)
262
+ assert_equal("Fatal error: Premature end of data in tag Results line 1 at :2.", error.message)
263
+ assert_equal(XML::Error::PARSER, error.domain)
264
+ assert_equal(XML::Error::TAG_NOT_FINISHED, error.code)
265
+ assert_equal(XML::Error::FATAL, error.level)
266
+ assert_nil(error.file)
267
+ assert_equal(2, error.line)
268
+ assert_equal('Results', error.str1)
269
+ assert_nil(error.str2)
270
+ assert_nil(error.str3)
271
+ assert_equal(1, error.int1)
272
+ assert_equal(1, error.int2)
273
+ assert_nil(error.node)
274
+ end
275
+
276
+ def test_parse_seg_fail
277
+ xml = <<-EOS
278
+ <?xml version="1.0" encoding="ISO-8859-1" ?>
279
+ <Products>
280
+ <Product>
281
+ <ProductDescription>
282
+ AQUALIA THERMAL Lichte cr├иme - Versterkende & kalmerende 24 u hydraterende verzorging<br />
283
+ Huid wordt continu gehydrateerd, intens versterkt en gekalmeerd.<br />
284
+ Hypoallergeen. Geschikt voor de gevoelige huid.<br />
285
+ <br />
286
+ 01.EFFECTIVITEIT<br />
287
+ Intensief gehydrateerd, de huid voelt gekalmeerd. Ze voelt de hele dag soepel en fluweelzacht aan, zonder een trekkerig gevoel. De huid is elastischer, soepeler en stralender. Doeltreffendheid getest onder dermatologisch toezicht. <br />
288
+ <br />
289
+ 02.GEBRUIK<br />
290
+ 's Morgens en/ of 's avonds aanbrengen. <br />
291
+ <br />
292
+ 03.ACTIEVE INGREDIENTEN<br />
293
+ Technologische innovatie: 24 u continue cellulaire vochtnevel. Voor de 1ste keer worden Thermaal Bronwater van Vichy, rijk aan zeldzame mineralen en Actief HyaluronineтДв verwerkt in microcapsules, die deze vervolgens verspreiden in de cellen. <br />
294
+ <br />
295
+ 04.TEXTUUR<br />
296
+ De lichte cr├иme is verfrissend en trekt makkelijk in. Niet vet en niet kleverig. Zonder 'maskereffect'. <br />
297
+ <br />
298
+ 05.GEUR<br />
299
+ Geparfumeerd <br />
300
+ <br />
301
+ 06.INHOUD<br />
302
+ 40 ml tube <br />
303
+ </ProductDescription>
304
+ </Product>
305
+ </Products>
306
+ EOS
307
+
308
+ parser = XML::SaxParser.string(xml)
309
+ parser.callbacks = TestCaseCallbacks.new
310
+
311
+ error = assert_raises(XML::Error) do
312
+ parser.parse
313
+ end
314
+ assert_equal("Fatal error: xmlParseEntityRef: no name at :5.", error.to_s)
315
+
316
+ # Check callbacks
317
+ result = parser.callbacks.result
318
+ end
319
+ end
@@ -0,0 +1,161 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ class TestSchema < Minitest::Test
6
+ def setup
7
+ file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
8
+ @doc = XML::Document.file(file)
9
+ end
10
+
11
+ def teardown
12
+ @doc = nil
13
+ end
14
+
15
+ def schema
16
+ document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
17
+ XML::Schema.document(document)
18
+ end
19
+
20
+ def check_error(error)
21
+ refute_nil(error)
22
+ assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
23
+ assert_kind_of(XML::Error, error)
24
+ assert_equal(XML::Error::SCHEMASV, error.domain)
25
+ assert_equal(XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
26
+ assert_equal(XML::Error::ERROR, error.level)
27
+ assert(error.file.match(/shiporder.xml/)) if error.file
28
+ assert_nil(error.str1)
29
+ assert_nil(error.str2)
30
+ assert_nil(error.str3)
31
+ assert_equal(0, error.int1)
32
+ assert_equal(0, error.int2)
33
+ end
34
+
35
+ def test_load_from_doc
36
+ assert_instance_of(XML::Schema, schema)
37
+ end
38
+
39
+ def test_doc_valid
40
+ assert(@doc.validate_schema(schema))
41
+ end
42
+
43
+ def test_doc_invalid
44
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
45
+ @doc.root << new_node
46
+
47
+ error = assert_raises(XML::Error) do
48
+ @doc.validate_schema(schema)
49
+ end
50
+
51
+ check_error(error)
52
+ assert_nil(error.line)
53
+ refute_nil(error.node)
54
+ assert_equal('invalid', error.node.name)
55
+ end
56
+
57
+ def test_reader_valid
58
+ reader = XML::Reader.string(@doc.to_s)
59
+ assert(reader.schema_validate(schema))
60
+
61
+ while reader.read
62
+ end
63
+ end
64
+
65
+ def test_reader_invalid
66
+ # Set error handler
67
+ errors = Array.new
68
+ XML::Error.set_handler do |error|
69
+ errors << error
70
+ end
71
+
72
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
73
+ @doc.root << new_node
74
+ reader = XML::Reader.string(@doc.to_s)
75
+
76
+ # Set a schema
77
+ assert(reader.schema_validate(schema))
78
+
79
+ while reader.read
80
+ end
81
+
82
+ assert_equal(1, errors.length)
83
+
84
+ error = errors.first
85
+ check_error(error)
86
+ assert_equal(21, error.line)
87
+ ensure
88
+ XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
89
+ end
90
+
91
+
92
+ # Schema meta-data tests
93
+
94
+ def test_elements
95
+ assert_instance_of(Hash, schema.elements)
96
+ assert_equal(1, schema.elements.length)
97
+ assert_instance_of(XML::Schema::Element, schema.elements['shiporder'])
98
+ end
99
+
100
+ def test_types
101
+ assert_instance_of(Hash, schema.types)
102
+ assert_equal(1, schema.types.length)
103
+ assert_instance_of(XML::Schema::Type, schema.types['shiporder'])
104
+ end
105
+
106
+ def test_schema_type
107
+ type = schema.types['shiporder']
108
+
109
+ assert_equal('shiporder', type.name)
110
+ assert_equal(nil, type.namespace)
111
+ assert_equal("Shiporder type documentation", type.annotation)
112
+ assert_instance_of(XML::Node, type.node)
113
+ assert_equal(XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind)
114
+ assert_instance_of(XML::Schema::Type, type.base)
115
+ assert_equal("anyType", type.base.name)
116
+ assert_equal(XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind)
117
+
118
+ assert_instance_of(Hash, type.elements)
119
+ assert_equal(3, type.elements.length)
120
+ end
121
+
122
+ def test_schema_element
123
+ element = schema.types['shiporder'].elements['orderperson']
124
+
125
+ assert_equal('orderperson', element.name)
126
+ assert_equal(nil, element.namespace)
127
+ assert_equal("orderperson element documentation", element.annotation)
128
+ assert_equal(1, element.min_occurs)
129
+ assert_equal(1, element.max_occurs)
130
+
131
+
132
+ element = schema.types['shiporder'].elements['item']
133
+ assert_equal(Float::INFINITY, element.max_occurs)
134
+
135
+ element = schema.types['shiporder'].elements['item'].type.elements['note']
136
+ assert_equal(0, element.min_occurs)
137
+ assert_equal('string', element.type.name)
138
+ end
139
+
140
+ def test_schema_attributes
141
+ type = schema.types['shiporder']
142
+
143
+ assert_instance_of(Array, type.attributes)
144
+ assert_equal(2, type.attributes.length)
145
+ assert_instance_of(XML::Schema::Attribute, type.attributes.first)
146
+ end
147
+
148
+ def test_schema_attribute
149
+ attribute = schema.types['shiporder'].attributes.first
150
+
151
+ assert_equal("orderid", attribute.name)
152
+ assert_equal(nil, attribute.namespace)
153
+ assert_equal(1, attribute.occurs)
154
+ assert_equal('string', attribute.type.name)
155
+
156
+ attribute = schema.types['shiporder'].attributes[1]
157
+ assert_equal(2, attribute.occurs)
158
+ assert_equal('1', attribute.default)
159
+ assert_equal('integer', attribute.type.name)
160
+ end
161
+ end