libxml-ruby 1.1.3-x86-mswin32-60 → 1.1.4-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/CHANGES +1 -1
  2. data/LICENSE +22 -22
  3. data/README +160 -160
  4. data/Rakefile +0 -9
  5. data/ext/libxml/Makefile +156 -0
  6. data/ext/libxml/extconf.h +5 -0
  7. data/ext/libxml/extconf.rb +4 -160
  8. data/ext/libxml/libxml-ruby.so.a +0 -0
  9. data/ext/libxml/libxml.o +0 -0
  10. data/ext/libxml/libxml_ruby.so +0 -0
  11. data/ext/libxml/mkmf.log +129 -0
  12. data/ext/libxml/ruby_xml.o +0 -0
  13. data/ext/libxml/ruby_xml_attr.c +1 -1
  14. data/ext/libxml/ruby_xml_attr.h +1 -1
  15. data/ext/libxml/ruby_xml_attr.o +0 -0
  16. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  17. data/ext/libxml/ruby_xml_attributes.o +0 -0
  18. data/ext/libxml/ruby_xml_cbg.o +0 -0
  19. data/ext/libxml/ruby_xml_document.c +936 -936
  20. data/ext/libxml/ruby_xml_document.h +1 -1
  21. data/ext/libxml/ruby_xml_document.o +0 -0
  22. data/ext/libxml/ruby_xml_dtd.o +0 -0
  23. data/ext/libxml/ruby_xml_encoding.o +0 -0
  24. data/ext/libxml/ruby_xml_error.o +0 -0
  25. data/ext/libxml/ruby_xml_html_parser.c +1 -1
  26. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  29. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  30. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  31. data/ext/libxml/ruby_xml_io.o +0 -0
  32. data/ext/libxml/ruby_xml_namespace.c +1 -1
  33. data/ext/libxml/ruby_xml_namespace.h +1 -1
  34. data/ext/libxml/ruby_xml_namespace.o +0 -0
  35. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  36. data/ext/libxml/ruby_xml_node.c +1386 -1386
  37. data/ext/libxml/ruby_xml_node.h +1 -1
  38. data/ext/libxml/ruby_xml_node.o +0 -0
  39. data/ext/libxml/ruby_xml_parser.c +1 -1
  40. data/ext/libxml/ruby_xml_parser.h +1 -1
  41. data/ext/libxml/ruby_xml_parser.o +0 -0
  42. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  43. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  44. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  45. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  46. data/ext/libxml/ruby_xml_reader.o +0 -0
  47. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  48. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  49. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  50. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  51. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  52. data/ext/libxml/ruby_xml_schema.o +0 -0
  53. data/ext/libxml/ruby_xml_version.h +3 -3
  54. data/ext/libxml/ruby_xml_xinclude.c +1 -1
  55. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  56. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  57. data/ext/libxml/ruby_xml_xpath.c +1 -1
  58. data/ext/libxml/ruby_xml_xpath.h +1 -1
  59. data/ext/libxml/ruby_xml_xpath.o +0 -0
  60. data/ext/libxml/ruby_xml_xpath_context.c +1 -1
  61. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  62. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  63. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  64. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  65. data/ext/libxml/ruby_xml_xpointer.c +1 -1
  66. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  67. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  68. data/ext/mingw/build.rake +3 -3
  69. data/ext/mingw/libiconv-2.dll +0 -0
  70. data/ext/mingw/libxml2-2.dll +0 -0
  71. data/ext/mingw/libxml_ruby.dll.a +0 -0
  72. data/ext/mingw/libxml_ruby.so +0 -0
  73. data/lib/libxml.rb +29 -29
  74. data/test/model/merge_bug_data.xml +58 -58
  75. data/test/model/rubynet.xml +79 -79
  76. data/test/model/xinclude.xml +4 -4
  77. data/test/tc_attr.rb +170 -170
  78. data/test/tc_document.rb +113 -113
  79. data/test/tc_document_write.rb +117 -117
  80. data/test/tc_dtd.rb +123 -123
  81. data/test/tc_html_parser.rb +137 -137
  82. data/test/tc_node.rb +180 -180
  83. data/test/tc_node_cdata.rb +49 -49
  84. data/test/tc_node_comment.rb +30 -30
  85. data/test/tc_node_edit.rb +157 -157
  86. data/test/tc_node_xlink.rb +26 -26
  87. data/test/tc_parser.rb +329 -329
  88. data/test/tc_parser_context.rb +185 -185
  89. data/test/tc_reader.rb +283 -283
  90. data/test/tc_sax_parser.rb +273 -273
  91. data/test/tc_schema.rb +51 -51
  92. data/test/tc_xinclude.rb +19 -19
  93. data/test/tc_xpath.rb +193 -193
  94. data/test/tc_xpointer.rb +72 -72
  95. metadata +55 -14
  96. data/ext/libxml/build.log +0 -4
@@ -1,274 +1,274 @@
1
- require 'xml'
2
- require 'stringio'
3
- require 'test/unit'
4
-
5
- class DocTypeCallback
6
- include XML::SaxParser::Callbacks
7
- def on_start_element(element, attributes)
8
- end
9
- end
10
-
11
- class TestCaseCallbacks
12
- include XML::SaxParser::Callbacks
13
-
14
- attr_accessor :result
15
-
16
- def initialize
17
- @result = Array.new
18
- end
19
-
20
- def on_cdata_block(cdata)
21
- @result << "cdata: #{cdata}"
22
- end
23
-
24
- def on_characters(chars)
25
- @result << "characters: #{chars}"
26
- end
27
-
28
- def on_comment(text)
29
- @result << "comment: #{text}"
30
- end
31
-
32
- def on_end_document
33
- @result << "end_document"
34
- end
35
-
36
- def on_end_element(name)
37
- @result << "end_element: #{name}"
38
- end
39
-
40
- def on_end_element_ns(name, prefix, uri)
41
- @result << "end_element_ns #{name}, prefix: #{prefix}, uri: #{uri}"
42
- end
43
-
44
- # Called for parser errors.
45
- def on_error(error)
46
- @result << "error: #{error}"
47
- end
48
-
49
- def on_processing_instruction(target, data)
50
- @result << "pi: #{target} #{data}"
51
- end
52
-
53
- def on_start_document
54
- @result << "startdoc"
55
- end
56
-
57
- def on_start_element(name, attributes)
58
- attributes ||= Hash.new
59
- @result << "start_element: #{name}, attr: #{attributes.inspect}"
60
- end
61
-
62
- def on_start_element_ns(name, attributes, prefix, uri, namespaces)
63
- attributes ||= Hash.new
64
- namespaces ||= Hash.new
65
- @result << "start_element_ns: #{name}, attr: #{attributes.inspect}, prefix: #{prefix}, uri: #{uri}, ns: #{namespaces.inspect}"
66
- end
67
- end
68
-
69
- class TestSaxParser < Test::Unit::TestCase
70
- def saxtest_file
71
- File.join(File.dirname(__FILE__), 'model/atom.xml')
72
- end
73
-
74
- def verify(parser)
75
- result = parser.callbacks.result
76
-
77
- i = -1
78
- assert_equal("startdoc", result[i+=1])
79
- assert_equal("pi: xml-stylesheet type=\"text/xsl\" href=\"my_stylesheet.xsl\"", result[i+=1])
80
- assert_equal("start_element: feed, attr: {}", result[i+=1])
81
- 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])
82
- assert_equal("characters: \n ", result[i+=1])
83
- assert_equal("comment: Not a valid atom entry ", result[i+=1])
84
- assert_equal("characters: \n ", result[i+=1])
85
- assert_equal("start_element: entry, attr: {}", result[i+=1])
86
- assert_equal("start_element_ns: entry, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
87
- assert_equal("characters: \n ", result[i+=1])
88
- assert_equal("start_element: title, attr: {\"type\"=>\"html\"}", result[i+=1])
89
- assert_equal("start_element_ns: title, attr: {\"type\"=>\"html\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
90
- assert_equal("cdata: <<strong>>", result[i+=1])
91
- assert_equal("end_element: title", result[i+=1])
92
- assert_equal("end_element_ns title, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
93
- assert_equal("characters: \n ", result[i+=1])
94
- assert_equal("start_element: content, attr: {\"type\"=>\"xhtml\"}", result[i+=1])
95
- assert_equal("start_element_ns: content, attr: {\"type\"=>\"xhtml\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
96
- assert_equal("characters: \n ", result[i+=1])
97
- assert_equal("start_element: xhtml:div, attr: {}", result[i+=1])
98
- 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])
99
- assert_equal("characters: \n ", result[i+=1])
100
- assert_equal("start_element: xhtml:p, attr: {}", result[i+=1])
101
- assert_equal("start_element_ns: p, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
102
- assert_equal("characters: hi there", result[i+=1])
103
- assert_equal("end_element: xhtml:p", result[i+=1])
104
- assert_equal("end_element_ns p, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
105
- assert_equal("characters: \n ", result[i+=1])
106
- assert_equal("end_element: xhtml:div", result[i+=1])
107
- assert_equal("end_element_ns div, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
108
- assert_equal("characters: \n ", result[i+=1])
109
- assert_equal("end_element: content", result[i+=1])
110
- assert_equal("end_element_ns content, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
111
- assert_equal("characters: \n ", result[i+=1])
112
- assert_equal("end_element: entry", result[i+=1])
113
- assert_equal("end_element_ns entry, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
114
- assert_equal("characters: \n", result[i+=1])
115
- assert_equal("end_element: feed", result[i+=1])
116
- assert_equal("end_element_ns feed, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
117
- assert_equal("end_document", result[i+=1])
118
- end
119
-
120
- def test_file
121
- parser = XML::SaxParser.file(saxtest_file)
122
- parser.callbacks = TestCaseCallbacks.new
123
- parser.parse
124
- verify(parser)
125
- end
126
-
127
- def test_file_no_callbacks
128
- parser = XML::SaxParser.file(saxtest_file)
129
- assert_equal true, parser.parse
130
- end
131
-
132
- def test_noexistent_file
133
- error = assert_raise(XML::Error) do
134
- XML::SaxParser.file('i_dont_exist.xml')
135
- end
136
-
137
- assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
138
- end
139
-
140
- def test_nil_file
141
- error = assert_raise(TypeError) do
142
- XML::SaxParser.file(nil)
143
- end
144
-
145
- assert_equal("can't convert nil into String", error.to_s)
146
- end
147
-
148
- def test_io
149
- File.open(saxtest_file) do |file|
150
- parser = XML::SaxParser.io(file)
151
- parser.callbacks = TestCaseCallbacks.new
152
- parser.parse
153
- verify(parser)
154
- end
155
- end
156
-
157
- def test_nil_io
158
- error = assert_raise(TypeError) do
159
- XML::HTMLParser.io(nil)
160
- end
161
-
162
- assert_equal("Must pass in an IO object", error.to_s)
163
- end
164
-
165
- def test_string_no_callbacks
166
- xml = File.read(saxtest_file)
167
- parser = XML::SaxParser.string(xml)
168
- assert_equal true, parser.parse
169
- end
170
-
171
- def test_string
172
- xml = File.read(saxtest_file)
173
- parser = XML::SaxParser.string(xml)
174
- parser.callbacks = TestCaseCallbacks.new
175
- parser.parse
176
- verify(parser)
177
- end
178
-
179
- def test_string_io
180
- xml = File.read(saxtest_file)
181
- io = StringIO.new(xml)
182
- parser = XML::SaxParser.io(io)
183
-
184
- parser.callbacks = TestCaseCallbacks.new
185
- parser.parse
186
- verify(parser)
187
- end
188
-
189
- def test_nil_string
190
- error = assert_raise(TypeError) do
191
- XML::SaxParser.string(nil)
192
- end
193
-
194
- assert_equal("wrong argument type nil (expected String)", error.to_s)
195
- end
196
-
197
- def test_doctype
198
- xml = <<-EOS
199
- <?xml version="1.0" encoding="UTF-8"?>
200
- <!DOCTYPE Results SYSTEM "results.dtd">
201
- <Results>
202
- <a>a1</a>
203
- </Results>
204
- EOS
205
- parser = XML::SaxParser.string(xml)
206
- parser.callbacks = DocTypeCallback.new
207
- doc = parser.parse
208
- assert_not_nil(doc)
209
- end
210
-
211
- def test_parse_warning
212
- # Two xml PIs is a warning
213
- xml = <<-EOS
214
- <?xml version="1.0" encoding="utf-8"?>
215
- <?xml-invalid?>
216
- <Test/>
217
- EOS
218
-
219
- parser = XML::SaxParser.string(xml)
220
- parser.callbacks = TestCaseCallbacks.new
221
-
222
- parser.parse
223
-
224
- # Check callbacks
225
- result = parser.callbacks.result
226
- i = -1
227
- assert_equal("startdoc", result[i+=1])
228
- assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
229
- assert_equal("pi: xml-invalid ", result[i+=1])
230
- assert_equal("start_element: Test, attr: {}", result[i+=1])
231
- assert_equal("start_element_ns: Test, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
232
- assert_equal("end_element: Test", result[i+=1])
233
- assert_equal("end_element_ns Test, prefix: , uri: ", result[i+=1])
234
- assert_equal("end_document", result[i+=1])
235
- end
236
-
237
- def test_parse_error
238
- xml = <<-EOS
239
- <Results>
240
- EOS
241
- parser = XML::SaxParser.string(xml)
242
- parser.callbacks = TestCaseCallbacks.new
243
-
244
- error = assert_raise(XML::Error) do
245
- doc = parser.parse
246
- end
247
-
248
- # Check callbacks
249
- result = parser.callbacks.result
250
-
251
- i = -1
252
- assert_equal("startdoc", result[i+=1])
253
- assert_equal("start_element: Results, attr: {}", result[i+=1])
254
- assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
255
- assert_equal("characters: \n", result[i+=1])
256
- assert_equal("error: Fatal error: Premature end of data in tag Results line 1 at :2.", result[i+=1])
257
- assert_equal("end_document", result[i+=1])
258
-
259
- assert_not_nil(error)
260
- assert_kind_of(XML::Error, error)
261
- assert_equal("Fatal error: Premature end of data in tag Results line 1 at :2.", error.message)
262
- assert_equal(XML::Error::PARSER, error.domain)
263
- assert_equal(XML::Error::TAG_NOT_FINISHED, error.code)
264
- assert_equal(XML::Error::FATAL, error.level)
265
- assert_nil(error.file)
266
- assert_equal(2, error.line)
267
- assert_equal('Results', error.str1)
268
- assert_nil(error.str2)
269
- assert_nil(error.str3)
270
- assert_equal(1, error.int1)
271
- assert_equal(1, error.int2)
272
- assert_nil(error.node)
273
- end
1
+ require 'xml'
2
+ require 'stringio'
3
+ require 'test/unit'
4
+
5
+ class DocTypeCallback
6
+ include XML::SaxParser::Callbacks
7
+ def on_start_element(element, attributes)
8
+ end
9
+ end
10
+
11
+ class TestCaseCallbacks
12
+ include XML::SaxParser::Callbacks
13
+
14
+ attr_accessor :result
15
+
16
+ def initialize
17
+ @result = Array.new
18
+ end
19
+
20
+ def on_cdata_block(cdata)
21
+ @result << "cdata: #{cdata}"
22
+ end
23
+
24
+ def on_characters(chars)
25
+ @result << "characters: #{chars}"
26
+ end
27
+
28
+ def on_comment(text)
29
+ @result << "comment: #{text}"
30
+ end
31
+
32
+ def on_end_document
33
+ @result << "end_document"
34
+ end
35
+
36
+ def on_end_element(name)
37
+ @result << "end_element: #{name}"
38
+ end
39
+
40
+ def on_end_element_ns(name, prefix, uri)
41
+ @result << "end_element_ns #{name}, prefix: #{prefix}, uri: #{uri}"
42
+ end
43
+
44
+ # Called for parser errors.
45
+ def on_error(error)
46
+ @result << "error: #{error}"
47
+ end
48
+
49
+ def on_processing_instruction(target, data)
50
+ @result << "pi: #{target} #{data}"
51
+ end
52
+
53
+ def on_start_document
54
+ @result << "startdoc"
55
+ end
56
+
57
+ def on_start_element(name, attributes)
58
+ attributes ||= Hash.new
59
+ @result << "start_element: #{name}, attr: #{attributes.inspect}"
60
+ end
61
+
62
+ def on_start_element_ns(name, attributes, prefix, uri, namespaces)
63
+ attributes ||= Hash.new
64
+ namespaces ||= Hash.new
65
+ @result << "start_element_ns: #{name}, attr: #{attributes.inspect}, prefix: #{prefix}, uri: #{uri}, ns: #{namespaces.inspect}"
66
+ end
67
+ end
68
+
69
+ class TestSaxParser < Test::Unit::TestCase
70
+ def saxtest_file
71
+ File.join(File.dirname(__FILE__), 'model/atom.xml')
72
+ end
73
+
74
+ def verify(parser)
75
+ result = parser.callbacks.result
76
+
77
+ i = -1
78
+ assert_equal("startdoc", result[i+=1])
79
+ assert_equal("pi: xml-stylesheet type=\"text/xsl\" href=\"my_stylesheet.xsl\"", result[i+=1])
80
+ assert_equal("start_element: feed, attr: {}", result[i+=1])
81
+ 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])
82
+ assert_equal("characters: \n ", result[i+=1])
83
+ assert_equal("comment: Not a valid atom entry ", result[i+=1])
84
+ assert_equal("characters: \n ", result[i+=1])
85
+ assert_equal("start_element: entry, attr: {}", result[i+=1])
86
+ assert_equal("start_element_ns: entry, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
87
+ assert_equal("characters: \n ", result[i+=1])
88
+ assert_equal("start_element: title, attr: {\"type\"=>\"html\"}", result[i+=1])
89
+ assert_equal("start_element_ns: title, attr: {\"type\"=>\"html\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
90
+ assert_equal("cdata: <<strong>>", result[i+=1])
91
+ assert_equal("end_element: title", result[i+=1])
92
+ assert_equal("end_element_ns title, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
93
+ assert_equal("characters: \n ", result[i+=1])
94
+ assert_equal("start_element: content, attr: {\"type\"=>\"xhtml\"}", result[i+=1])
95
+ assert_equal("start_element_ns: content, attr: {\"type\"=>\"xhtml\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
96
+ assert_equal("characters: \n ", result[i+=1])
97
+ assert_equal("start_element: xhtml:div, attr: {}", result[i+=1])
98
+ 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])
99
+ assert_equal("characters: \n ", result[i+=1])
100
+ assert_equal("start_element: xhtml:p, attr: {}", result[i+=1])
101
+ assert_equal("start_element_ns: p, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
102
+ assert_equal("characters: hi there", result[i+=1])
103
+ assert_equal("end_element: xhtml:p", result[i+=1])
104
+ assert_equal("end_element_ns p, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
105
+ assert_equal("characters: \n ", result[i+=1])
106
+ assert_equal("end_element: xhtml:div", result[i+=1])
107
+ assert_equal("end_element_ns div, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
108
+ assert_equal("characters: \n ", result[i+=1])
109
+ assert_equal("end_element: content", result[i+=1])
110
+ assert_equal("end_element_ns content, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
111
+ assert_equal("characters: \n ", result[i+=1])
112
+ assert_equal("end_element: entry", result[i+=1])
113
+ assert_equal("end_element_ns entry, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
114
+ assert_equal("characters: \n", result[i+=1])
115
+ assert_equal("end_element: feed", result[i+=1])
116
+ assert_equal("end_element_ns feed, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
117
+ assert_equal("end_document", result[i+=1])
118
+ end
119
+
120
+ def test_file
121
+ parser = XML::SaxParser.file(saxtest_file)
122
+ parser.callbacks = TestCaseCallbacks.new
123
+ parser.parse
124
+ verify(parser)
125
+ end
126
+
127
+ def test_file_no_callbacks
128
+ parser = XML::SaxParser.file(saxtest_file)
129
+ assert_equal true, parser.parse
130
+ end
131
+
132
+ def test_noexistent_file
133
+ error = assert_raise(XML::Error) do
134
+ XML::SaxParser.file('i_dont_exist.xml')
135
+ end
136
+
137
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
138
+ end
139
+
140
+ def test_nil_file
141
+ error = assert_raise(TypeError) do
142
+ XML::SaxParser.file(nil)
143
+ end
144
+
145
+ assert_equal("can't convert nil into String", error.to_s)
146
+ end
147
+
148
+ def test_io
149
+ File.open(saxtest_file) do |file|
150
+ parser = XML::SaxParser.io(file)
151
+ parser.callbacks = TestCaseCallbacks.new
152
+ parser.parse
153
+ verify(parser)
154
+ end
155
+ end
156
+
157
+ def test_nil_io
158
+ error = assert_raise(TypeError) do
159
+ XML::HTMLParser.io(nil)
160
+ end
161
+
162
+ assert_equal("Must pass in an IO object", error.to_s)
163
+ end
164
+
165
+ def test_string_no_callbacks
166
+ xml = File.read(saxtest_file)
167
+ parser = XML::SaxParser.string(xml)
168
+ assert_equal true, parser.parse
169
+ end
170
+
171
+ def test_string
172
+ xml = File.read(saxtest_file)
173
+ parser = XML::SaxParser.string(xml)
174
+ parser.callbacks = TestCaseCallbacks.new
175
+ parser.parse
176
+ verify(parser)
177
+ end
178
+
179
+ def test_string_io
180
+ xml = File.read(saxtest_file)
181
+ io = StringIO.new(xml)
182
+ parser = XML::SaxParser.io(io)
183
+
184
+ parser.callbacks = TestCaseCallbacks.new
185
+ parser.parse
186
+ verify(parser)
187
+ end
188
+
189
+ def test_nil_string
190
+ error = assert_raise(TypeError) do
191
+ XML::SaxParser.string(nil)
192
+ end
193
+
194
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
195
+ end
196
+
197
+ def test_doctype
198
+ xml = <<-EOS
199
+ <?xml version="1.0" encoding="UTF-8"?>
200
+ <!DOCTYPE Results SYSTEM "results.dtd">
201
+ <Results>
202
+ <a>a1</a>
203
+ </Results>
204
+ EOS
205
+ parser = XML::SaxParser.string(xml)
206
+ parser.callbacks = DocTypeCallback.new
207
+ doc = parser.parse
208
+ assert_not_nil(doc)
209
+ end
210
+
211
+ def test_parse_warning
212
+ # Two xml PIs is a warning
213
+ xml = <<-EOS
214
+ <?xml version="1.0" encoding="utf-8"?>
215
+ <?xml-invalid?>
216
+ <Test/>
217
+ EOS
218
+
219
+ parser = XML::SaxParser.string(xml)
220
+ parser.callbacks = TestCaseCallbacks.new
221
+
222
+ parser.parse
223
+
224
+ # Check callbacks
225
+ result = parser.callbacks.result
226
+ i = -1
227
+ assert_equal("startdoc", result[i+=1])
228
+ assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
229
+ assert_equal("pi: xml-invalid ", result[i+=1])
230
+ assert_equal("start_element: Test, attr: {}", result[i+=1])
231
+ assert_equal("start_element_ns: Test, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
232
+ assert_equal("end_element: Test", result[i+=1])
233
+ assert_equal("end_element_ns Test, prefix: , uri: ", result[i+=1])
234
+ assert_equal("end_document", result[i+=1])
235
+ end
236
+
237
+ def test_parse_error
238
+ xml = <<-EOS
239
+ <Results>
240
+ EOS
241
+ parser = XML::SaxParser.string(xml)
242
+ parser.callbacks = TestCaseCallbacks.new
243
+
244
+ error = assert_raise(XML::Error) do
245
+ doc = parser.parse
246
+ end
247
+
248
+ # Check callbacks
249
+ result = parser.callbacks.result
250
+
251
+ i = -1
252
+ assert_equal("startdoc", result[i+=1])
253
+ assert_equal("start_element: Results, attr: {}", result[i+=1])
254
+ assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
255
+ assert_equal("characters: \n", result[i+=1])
256
+ assert_equal("error: Fatal error: Premature end of data in tag Results line 1 at :2.", result[i+=1])
257
+ assert_equal("end_document", result[i+=1])
258
+
259
+ assert_not_nil(error)
260
+ assert_kind_of(XML::Error, error)
261
+ assert_equal("Fatal error: Premature end of data in tag Results line 1 at :2.", error.message)
262
+ assert_equal(XML::Error::PARSER, error.domain)
263
+ assert_equal(XML::Error::TAG_NOT_FINISHED, error.code)
264
+ assert_equal(XML::Error::FATAL, error.level)
265
+ assert_nil(error.file)
266
+ assert_equal(2, error.line)
267
+ assert_equal('Results', error.str1)
268
+ assert_nil(error.str2)
269
+ assert_nil(error.str3)
270
+ assert_equal(1, error.int1)
271
+ assert_equal(1, error.int2)
272
+ assert_nil(error.node)
273
+ end
274
274
  end