smile-xml 1.0.0-jruby → 1.0.2-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/lib/smile-xml.jar +0 -0
  2. data/src/main/java/smile/xml/AttrJ.java +160 -0
  3. data/src/main/java/smile/xml/AttributesJ.java +212 -0
  4. data/src/main/java/smile/xml/BaseJ.java +60 -0
  5. data/src/main/java/smile/xml/DocumentJ.java +435 -0
  6. data/src/main/java/smile/xml/EncodingJ.java +94 -0
  7. data/src/main/java/smile/xml/ErrorJ.java +162 -0
  8. data/src/main/java/smile/xml/NamespaceJ.java +67 -0
  9. data/src/main/java/smile/xml/NamespacesJ.java +62 -0
  10. data/src/main/java/smile/xml/NodeJ.java +1029 -0
  11. data/src/main/java/smile/xml/NodeSetJ.java +90 -0
  12. data/src/main/java/smile/xml/ParserContextJ.java +44 -0
  13. data/src/main/java/smile/xml/ParserJ.java +196 -0
  14. data/src/main/java/smile/xml/ParserOptionsJ.java +58 -0
  15. data/src/main/java/smile/xml/ReaderJ.java +34 -0
  16. data/src/main/java/smile/xml/SchemaJ.java +66 -0
  17. data/src/main/java/smile/xml/SmileXML.java +65 -0
  18. data/src/main/java/smile/xml/XmlJ.java +58 -0
  19. data/src/main/java/smile/xml/sax/CallbackHandler.java +113 -0
  20. data/src/main/java/smile/xml/sax/SaxParserCallbacksJ.java +71 -0
  21. data/src/main/java/smile/xml/sax/SaxParserJ.java +153 -0
  22. data/src/main/java/smile/xml/util/UtilJ.java +424 -0
  23. data/src/main/java/smile/xml/xpath/CustomNamespaceContext.java +59 -0
  24. data/src/main/java/smile/xml/xpath/XPathContextJ.java +154 -0
  25. data/src/main/java/smile/xml/xpath/XPathExpressionJ.java +62 -0
  26. data/src/main/java/smile/xml/xpath/XPathJ.java +36 -0
  27. data/src/main/java/smile/xml/xpath/XPathObjectJ.java +196 -0
  28. data/src/main/java/smile/xml/xpath/XPointerJ.java +32 -0
  29. data/src/main/ruby/xml/libxml.rb +1 -0
  30. data/src/main/ruby/xml.rb +5 -0
  31. data/src/test/ruby/etc_doc_to_s.rb +21 -0
  32. data/src/test/ruby/ets_doc_file.rb +17 -0
  33. data/src/test/ruby/ets_doc_to_s.rb +23 -0
  34. data/src/test/ruby/ets_gpx.rb +28 -0
  35. data/src/test/ruby/ets_node_gc.rb +23 -0
  36. data/src/test/ruby/ets_test.xml +2 -0
  37. data/src/test/ruby/ets_tsr.rb +11 -0
  38. data/src/test/ruby/model/atom.xml +13 -0
  39. data/src/test/ruby/model/bands.iso-8859-1.xml +5 -0
  40. data/src/test/ruby/model/bands.utf-8.xml +5 -0
  41. data/src/test/ruby/model/bands.xml +5 -0
  42. data/src/test/ruby/model/books.xml +146 -0
  43. data/src/test/ruby/model/merge_bug_data.xml +58 -0
  44. data/src/test/ruby/model/ruby-lang.html +238 -0
  45. data/src/test/ruby/model/rubynet.xml +79 -0
  46. data/src/test/ruby/model/shiporder.rnc +28 -0
  47. data/src/test/ruby/model/shiporder.rng +86 -0
  48. data/src/test/ruby/model/shiporder.xml +23 -0
  49. data/src/test/ruby/model/shiporder.xsd +31 -0
  50. data/src/test/ruby/model/soap.xml +27 -0
  51. data/src/test/ruby/model/xinclude.xml +5 -0
  52. data/src/test/ruby/smile_xml_test.rb +64 -0
  53. data/src/test/ruby/tc_attr.rb +191 -0
  54. data/src/test/ruby/tc_attr_decl.rb +133 -0
  55. data/src/test/ruby/tc_attributes.rb +135 -0
  56. data/src/test/ruby/tc_deprecated_require.rb +13 -0
  57. data/src/test/ruby/tc_document.rb +162 -0
  58. data/src/test/ruby/tc_document_write.rb +212 -0
  59. data/src/test/ruby/tc_dtd.rb +125 -0
  60. data/src/test/ruby/tc_error.rb +150 -0
  61. data/src/test/ruby/tc_html_parser.rb +140 -0
  62. data/src/test/ruby/tc_namespace.rb +62 -0
  63. data/src/test/ruby/tc_namespaces.rb +210 -0
  64. data/src/test/ruby/tc_node.rb +273 -0
  65. data/src/test/ruby/tc_node_cdata.rb +51 -0
  66. data/src/test/ruby/tc_node_comment.rb +33 -0
  67. data/src/test/ruby/tc_node_copy.rb +42 -0
  68. data/src/test/ruby/tc_node_edit.rb +178 -0
  69. data/src/test/ruby/tc_node_text.rb +73 -0
  70. data/src/test/ruby/tc_node_write.rb +108 -0
  71. data/src/test/ruby/tc_node_xlink.rb +29 -0
  72. data/src/test/ruby/tc_parser.rb +371 -0
  73. data/src/test/ruby/tc_parser_context.rb +189 -0
  74. data/src/test/ruby/tc_properties.rb +40 -0
  75. data/src/test/ruby/tc_reader.rb +306 -0
  76. data/src/test/ruby/tc_relaxng.rb +54 -0
  77. data/src/test/ruby/tc_sax_parser.rb +340 -0
  78. data/src/test/ruby/tc_schema.rb +59 -0
  79. data/src/test/ruby/tc_traversal.rb +222 -0
  80. data/src/test/ruby/tc_xinclude.rb +21 -0
  81. data/src/test/ruby/tc_xml.rb +226 -0
  82. data/src/test/ruby/tc_xpath.rb +210 -0
  83. data/src/test/ruby/tc_xpath_context.rb +80 -0
  84. data/src/test/ruby/tc_xpath_expression.rb +38 -0
  85. data/src/test/ruby/tc_xpointer.rb +74 -0
  86. data/src/test/ruby/test_helper.rb +23 -0
  87. data/src/test/ruby/test_suite.rb +41 -0
  88. metadata +91 -5
@@ -0,0 +1,306 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'stringio'
5
+ require 'test/unit'
6
+
7
+ class TestReader < Test::Unit::TestCase
8
+ XML_FILE = File.join(File.dirname(__FILE__), 'model/atom.xml')
9
+
10
+ def verify_simple(reader)
11
+ node_types = []
12
+
13
+ # Read each node
14
+ 26.times do
15
+ assert(reader.read)
16
+ node_types << reader.node_type
17
+ end
18
+
19
+ # There are no more nodes
20
+ assert(!reader.read)
21
+
22
+ # Check what was read
23
+ expected = [XML::Reader::TYPE_PROCESSING_INSTRUCTION,
24
+ XML::Reader::TYPE_ELEMENT,
25
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
26
+ XML::Reader::TYPE_COMMENT,
27
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
28
+ XML::Reader::TYPE_ELEMENT,
29
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
30
+ XML::Reader::TYPE_ELEMENT,
31
+ XML::Reader::TYPE_CDATA,
32
+ XML::Reader::TYPE_END_ELEMENT,
33
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
34
+ XML::Reader::TYPE_ELEMENT,
35
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
36
+ XML::Reader::TYPE_ELEMENT,
37
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
38
+ XML::Reader::TYPE_ELEMENT,
39
+ XML::Reader::TYPE_TEXT,
40
+ XML::Reader::TYPE_END_ELEMENT,
41
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
42
+ XML::Reader::TYPE_END_ELEMENT,
43
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
44
+ XML::Reader::TYPE_END_ELEMENT,
45
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
46
+ XML::Reader::TYPE_END_ELEMENT,
47
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
48
+ XML::Reader::TYPE_END_ELEMENT]
49
+
50
+ assert_equal(expected, node_types)
51
+ end
52
+
53
+ def test_document
54
+ reader = XML::Reader.document(XML::Document.file(XML_FILE))
55
+ verify_simple(reader)
56
+ end
57
+
58
+ def test_file
59
+ reader = XML::Reader.file(XML_FILE)
60
+ verify_simple(reader)
61
+ end
62
+
63
+ def test_invalid_file
64
+ assert_raise(XML::Error) do
65
+ XML::Reader.file('/does/not/exist')
66
+ end
67
+ end
68
+
69
+ def test_string
70
+ reader = XML::Reader.string(File.read(XML_FILE))
71
+ verify_simple(reader)
72
+ end
73
+
74
+ def test_io
75
+ File.open(XML_FILE, 'rb') do |io|
76
+ reader = XML::Reader.io(io)
77
+ verify_simple(reader)
78
+ end
79
+ end
80
+
81
+ def test_io_gc
82
+ # Test that the reader keeps a reference
83
+ # to the io object
84
+ file = File.open(XML_FILE, 'rb')
85
+ reader = XML::Reader.io(file)
86
+ file = nil
87
+ GC.start
88
+ assert(reader.read)
89
+ end
90
+
91
+ def test_string_io
92
+ data = File.read(XML_FILE)
93
+ string_io = StringIO.new(data)
94
+ reader = XML::Reader.io(string_io)
95
+ verify_simple(reader)
96
+ end
97
+
98
+ def test_error
99
+ reader = XML::Reader.string('<foo blah')
100
+
101
+ error = assert_raise(XML::Error) do
102
+ reader.read
103
+ end
104
+ assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", error.to_s)
105
+ end
106
+
107
+ def test_deprecated_error_handler
108
+ called = false
109
+ reader = XML::Reader.string('<foo blah')
110
+ reader.set_error_handler do |error|
111
+ called = true
112
+ end
113
+
114
+ assert_raise(XML::Error) do
115
+ reader.read
116
+ end
117
+
118
+ assert(called)
119
+ end
120
+
121
+ def test_deprecated_reset_error_handler
122
+ called = false
123
+ reader = XML::Reader.string('<foo blah')
124
+ reader.set_error_handler do |error|
125
+ called = true
126
+ end
127
+ reader.reset_error_handler
128
+
129
+ assert_raise(XML::Error) do
130
+ reader.read
131
+ end
132
+
133
+ assert(!called)
134
+ end
135
+
136
+ def test_attr
137
+ parser = XML::Reader.string("<foo x='1' y='2'/>")
138
+ assert(parser.read)
139
+ assert_equal('foo', parser.name)
140
+ assert_equal('1', parser['x'])
141
+ assert_equal('1', parser[0])
142
+ assert_equal('2', parser['y'])
143
+ assert_equal('2', parser[1])
144
+ assert_equal(nil, parser['z'])
145
+ assert_equal(nil, parser[2])
146
+ end
147
+
148
+ def test_value
149
+ parser = XML::Reader.string("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
150
+ assert(parser.read)
151
+ assert_equal('foo', parser.name)
152
+ assert_equal(nil, parser.value)
153
+ 3.times do |i|
154
+ assert(parser.read)
155
+ assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
156
+ assert_equal('bar', parser.name)
157
+ assert(parser.read)
158
+ assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
159
+ assert_equal((i + 1).to_s, parser.value)
160
+ assert(parser.read)
161
+ assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
162
+ end
163
+ end
164
+
165
+ def test_expand
166
+ reader = XML::Reader.file(XML_FILE)
167
+ reader.read.to_s
168
+ reader.read
169
+
170
+ # Read a node
171
+ node = reader.expand
172
+ assert_equal('feed', node.name)
173
+ assert_equal(::Encoding::UTF_8, node.name.encoding) if defined?(::Encoding)
174
+
175
+ # Try to access the document
176
+ error = assert_raise(XML::Error) do
177
+ assert_not_nil(node.doc)
178
+ end
179
+ assert_equal(" Document is not accessible to Ruby (hint - did you call Reader#expand?).", error.to_s)
180
+ end
181
+
182
+ def test_mode
183
+ reader = XML::Reader.string('<xml/>')
184
+ assert_equal(XML::Reader::MODE_INITIAL, reader.read_state)
185
+ reader.read
186
+ assert_equal(XML::Reader::MODE_EOF, reader.read_state)
187
+ end
188
+
189
+ def test_bytes_consumed
190
+ reader = XML::Reader.file(XML_FILE)
191
+ reader.read
192
+ assert_equal(416, reader.byte_consumed)
193
+ end
194
+
195
+ def test_node
196
+ XML.default_line_numbers = true
197
+ reader = XML::Reader.file(XML_FILE)
198
+
199
+ # first try to get a node
200
+ assert_nil(reader.node)
201
+
202
+ reader.read
203
+ assert_instance_of(XML::Node, reader.node)
204
+ end
205
+
206
+ def test_base_uri
207
+ # UTF8:
208
+ # ö - c3 b6 in hex, \303\266 in octal
209
+ # ü - c3 bc in hex, \303\274 in octal
210
+ xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
211
+ reader = XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org")
212
+
213
+ reader.read
214
+ assert_equal(reader.base_uri, "http://libxml.rubyforge.org")
215
+ assert_equal(::Encoding::UTF_8, reader.base_uri.encoding) if defined?(::Encoding)
216
+ end
217
+
218
+ def test_options
219
+ xml = <<-EOS
220
+ <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
221
+ <test>
222
+ <cdata><![CDATA[something]]></cdata>
223
+ <entity>&foo;</entity>
224
+ </test>
225
+ EOS
226
+
227
+ # Parse normally
228
+ reader = XML::Reader.string(xml)
229
+ reader.read # foo
230
+ reader.read # test
231
+ reader.read # text
232
+ reader.read # cdata
233
+ reader.read # cdata-section
234
+ assert_equal(XML::Node::CDATA_SECTION_NODE, reader.node_type)
235
+
236
+ # Convert cdata section to text
237
+ reader = XML::Reader.string(xml, :options => XML::Parser::Options::NOCDATA)
238
+ reader.read # foo
239
+ reader.read # test
240
+ reader.read # text
241
+ reader.read # cdata
242
+ reader.read # cdata-section
243
+ assert_equal(XML::Node::TEXT_NODE, reader.node_type)
244
+ end
245
+
246
+ def test_encoding
247
+ # ISO_8859_1:
248
+ # ö - f6 in hex, \366 in octal
249
+ # ü - fc in hex, \374 in octal
250
+ xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
251
+
252
+ reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
253
+ reader.read
254
+
255
+ if defined?(Encoding)
256
+ assert_equal(Encoding::ISO8859_1, reader.read_outer_xml.encoding)
257
+ assert_equal(Encoding::ISO8859_1, reader.read_inner_xml.encoding)
258
+ assert_equal(Encoding::ISO8859_1, reader.read_string.encoding)
259
+
260
+ assert_equal("<bands genre=\"metal\">\n <m\xC3\xB6tley_cr\xC3\xBCe country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\xC3\xB6tley_cr\xC3\xBCe>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>".force_encoding(Encoding::ISO8859_1),
261
+ reader.read_outer_xml)
262
+ assert_equal("\n <m\xC3\xB6tley_cr\xC3\xBCe country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\xC3\xB6tley_cr\xC3\xBCe>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n".force_encoding(Encoding::ISO8859_1),
263
+ reader.read_inner_xml)
264
+ assert_equal("\n An American heavy metal band formed in Los Angeles, California in 1981.\n British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1),
265
+ reader.read_string)
266
+ else
267
+ assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
268
+ reader.read_outer_xml)
269
+ end
270
+ end
271
+
272
+ def test_invalid_encoding
273
+ # ISO_8859_1:
274
+ # ö - f6 in hex, \366 in octal
275
+ # ü - fc in hex, \374 in octal
276
+ xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
277
+
278
+ reader = XML::Reader.string(xml)
279
+ error = assert_raise(XML::Error) do
280
+ node = reader.read
281
+ end
282
+
283
+ assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
284
+ error.to_s)
285
+
286
+ end
287
+
288
+ def test_file_encoding
289
+ reader = XML::Reader.file(XML_FILE)
290
+ reader.read
291
+ assert_equal(XML::Encoding::UTF_8, reader.encoding)
292
+ assert_equal(Encoding::UTF_8, reader.value.encoding) if defined?(Encoding)
293
+ end
294
+
295
+ def test_string_encoding
296
+ # ISO_8859_1:
297
+ # ö - f6 in hex, \366 in octal
298
+ # ü - fc in hex, \374 in octal
299
+ xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
300
+ reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
301
+ reader.read
302
+
303
+ # Encoding is always null for strings, very annoying!
304
+ assert_equal(reader.encoding, XML::Encoding::NONE)
305
+ end
306
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+ class TestRelaxNG < Test::Unit::TestCase
8
+ def setup
9
+ file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
10
+ @doc = XML::Document.file(file)
11
+ end
12
+
13
+ def teardown
14
+ @doc = nil
15
+ end
16
+
17
+ def relaxng
18
+ document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.rng'))
19
+ relaxng = XML::RelaxNG.document(document)
20
+ end
21
+
22
+ def test_from_doc
23
+ assert_instance_of(XML::RelaxNG, relaxng)
24
+ end
25
+
26
+ def test_valid
27
+ assert(@doc.validate_relaxng(relaxng))
28
+ end
29
+
30
+ def test_invalid
31
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
32
+ @doc.root << new_node
33
+
34
+ error = assert_raise(XML::Error) do
35
+ @doc.validate_relaxng(relaxng)
36
+ end
37
+
38
+ assert_not_nil(error)
39
+ assert_kind_of(XML::Error, error)
40
+ assert(error.message.match(/Error: Did not expect element invalid there/))
41
+ assert_equal(XML::Error::RELAXNGV, error.domain)
42
+ assert_equal(XML::Error::LT_IN_ATTRIBUTE, error.code)
43
+ assert_equal(XML::Error::ERROR, error.level)
44
+ assert(error.file.match(/shiporder\.xml/))
45
+ assert_nil(error.line)
46
+ assert_equal('invalid', error.str1)
47
+ assert_nil(error.str2)
48
+ assert_nil(error.str3)
49
+ assert_equal(0, error.int1)
50
+ assert_equal(0, error.int2)
51
+ assert_not_nil(error.node)
52
+ assert_equal('invalid', error.node.name)
53
+ end
54
+ end
@@ -0,0 +1,340 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'stringio'
5
+ require 'test/unit'
6
+
7
+ class DocTypeCallback
8
+ include XML::SaxParser::Callbacks
9
+ def on_start_element(element, attributes)
10
+ end
11
+ end
12
+
13
+ class TestCaseCallbacks
14
+ include XML::SaxParser::Callbacks
15
+
16
+ attr_accessor :result
17
+
18
+ def initialize
19
+ @result = Array.new
20
+ end
21
+
22
+ def on_cdata_block(cdata)
23
+ @result << "cdata: #{cdata}"
24
+ end
25
+
26
+ def on_characters(chars)
27
+ @result << "characters: #{chars}"
28
+ end
29
+
30
+ def on_comment(text)
31
+ @result << "comment: #{text}"
32
+ end
33
+
34
+ def on_end_document
35
+ @result << "end_document"
36
+ end
37
+
38
+ def on_end_element(name)
39
+ @result << "end_element: #{name}"
40
+ end
41
+
42
+ def on_end_element_ns(name, prefix, uri)
43
+ @result << "end_element_ns #{name}, prefix: #{prefix}, uri: #{uri}"
44
+ end
45
+
46
+ # Called for parser errors.
47
+ def on_error(error)
48
+ @result << "error: #{error}"
49
+ end
50
+
51
+ def on_processing_instruction(target, data)
52
+ @result << "pi: #{target} #{data}"
53
+ end
54
+
55
+ def on_start_document
56
+ @result << "startdoc"
57
+ end
58
+
59
+ def on_start_element(name, attributes)
60
+ attributes ||= Hash.new
61
+ @result << "start_element: #{name}, attr: #{attributes.inspect}"
62
+ end
63
+
64
+ def on_start_element_ns(name, attributes, prefix, uri, namespaces)
65
+ attributes ||= Hash.new
66
+ namespaces ||= Hash.new
67
+ @result << "start_element_ns: #{name}, attr: #{attributes.inspect}, prefix: #{prefix}, uri: #{uri}, ns: #{namespaces.inspect}"
68
+ end
69
+ end
70
+
71
+ class TestSaxParser < Test::Unit::TestCase
72
+ def saxtest_file
73
+ File.join(File.dirname(__FILE__), 'model/atom.xml')
74
+ end
75
+
76
+ def verify(parser)
77
+ result = parser.callbacks.result
78
+
79
+ i = -1
80
+ assert_equal("startdoc", result[i+=1])
81
+ assert_equal("pi: xml-stylesheet type=\"text/xsl\" href=\"my_stylesheet.xsl\"", result[i+=1])
82
+ assert_equal("start_element: feed, attr: {}", result[i+=1])
83
+ puts "TODO #{__FILE__} #{__LINE__}"
84
+ #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])
85
+ assert_equal("characters: \n ", result[i+=1])
86
+ assert_equal("comment: Not a valid atom entry ", result[i+=1])
87
+ assert_equal("characters: \n ", result[i+=1])
88
+ assert_equal("start_element: entry, attr: {}", result[i+=1])
89
+ puts "TODO #{__FILE__} #{__LINE__}"
90
+ #assert_equal("start_element_ns: entry, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
91
+ assert_equal("characters: \n ", result[i+=1])
92
+ assert_equal("start_element: title, attr: {\"type\"=>\"html\"}", result[i+=1])
93
+ puts "TODO #{__FILE__} #{__LINE__}"
94
+ #assert_equal("start_element_ns: title, attr: {\"type\"=>\"html\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
95
+ assert_equal("cdata: <<strong>>", result[i+=1])
96
+ assert_equal("end_element: title", result[i+=1])
97
+ puts "TODO #{__FILE__} #{__LINE__}"
98
+ #assert_equal("end_element_ns title, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
99
+ assert_equal("characters: \n ", result[i+=1])
100
+ assert_equal("start_element: content, attr: {\"type\"=>\"xhtml\"}", result[i+=1])
101
+ puts "TODO #{__FILE__} #{__LINE__}"
102
+ #assert_equal("start_element_ns: content, attr: {\"type\"=>\"xhtml\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
103
+ assert_equal("characters: \n ", result[i+=1])
104
+ assert_equal("start_element: xhtml:div, attr: {}", result[i+=1])
105
+ puts "TODO #{__FILE__} #{__LINE__}"
106
+ #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])
107
+ assert_equal("characters: \n ", result[i+=1])
108
+ assert_equal("start_element: xhtml:p, attr: {}", result[i+=1])
109
+ puts "TODO #{__FILE__} #{__LINE__}"
110
+ #assert_equal("start_element_ns: p, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
111
+ assert_equal("characters: hi there", result[i+=1])
112
+ assert_equal("end_element: xhtml:p", result[i+=1])
113
+ puts "TODO #{__FILE__} #{__LINE__}"
114
+ #assert_equal("end_element_ns p, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
115
+ assert_equal("characters: \n ", result[i+=1])
116
+ assert_equal("end_element: xhtml:div", result[i+=1])
117
+ puts "TODO #{__FILE__} #{__LINE__}"
118
+ #assert_equal("end_element_ns div, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
119
+ assert_equal("characters: \n ", result[i+=1])
120
+ assert_equal("end_element: content", result[i+=1])
121
+ puts "TODO #{__FILE__} #{__LINE__}"
122
+ #assert_equal("end_element_ns content, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
123
+ assert_equal("characters: \n ", result[i+=1])
124
+ assert_equal("end_element: entry", result[i+=1])
125
+ puts "TODO #{__FILE__} #{__LINE__}"
126
+ #assert_equal("end_element_ns entry, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
127
+ assert_equal("characters: \n", result[i+=1])
128
+ assert_equal("end_element: feed", result[i+=1])
129
+ puts "TODO #{__FILE__} #{__LINE__}"
130
+ #assert_equal("end_element_ns feed, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
131
+ assert_equal("end_document", result[i+=1])
132
+ end
133
+
134
+ def test_file
135
+ parser = XML::SaxParser.file(saxtest_file)
136
+ parser.callbacks = TestCaseCallbacks.new
137
+ parser.parse
138
+ verify(parser)
139
+ end
140
+
141
+ def test_file_no_callbacks
142
+ parser = XML::SaxParser.file(saxtest_file)
143
+ assert_equal true, parser.parse
144
+ end
145
+
146
+ def test_noexistent_file
147
+ error = assert_raise(XML::Error) do
148
+ XML::SaxParser.file('i_dont_exist.xml')
149
+ end
150
+
151
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
152
+ end
153
+
154
+ def test_nil_file
155
+ error = assert_raise(TypeError) do
156
+ XML::SaxParser.file(nil)
157
+ end
158
+
159
+ assert_equal("can't convert nil into String", error.to_s)
160
+ end
161
+
162
+ def test_io
163
+ File.open(saxtest_file) do |file|
164
+ parser = XML::SaxParser.io(file)
165
+ parser.callbacks = TestCaseCallbacks.new
166
+ parser.parse
167
+ verify(parser)
168
+ end
169
+ end
170
+
171
+ def test_string_no_callbacks
172
+ xml = File.read(saxtest_file)
173
+ parser = XML::SaxParser.string(xml)
174
+ assert_equal true, parser.parse
175
+ end
176
+
177
+ def test_string
178
+ xml = File.read(saxtest_file)
179
+ parser = XML::SaxParser.string(xml)
180
+ parser.callbacks = TestCaseCallbacks.new
181
+ parser.parse
182
+ verify(parser)
183
+ end
184
+
185
+ def test_string_io
186
+ xml = File.read(saxtest_file)
187
+ io = StringIO.new(xml)
188
+ parser = XML::SaxParser.io(io)
189
+
190
+ parser.callbacks = TestCaseCallbacks.new
191
+ parser.parse
192
+ verify(parser)
193
+ end
194
+
195
+ def test_nil_string
196
+ error = assert_raise(TypeError) do
197
+ XML::SaxParser.string(nil)
198
+ end
199
+
200
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
201
+ end
202
+
203
+ def test_doctype
204
+ xml = <<-EOS
205
+ <?xml version="1.0" encoding="UTF-8"?>
206
+ <!DOCTYPE Results SYSTEM "results.dtd">
207
+ <Results>
208
+ <a>a1</a>
209
+ </Results>
210
+ EOS
211
+ parser = XML::SaxParser.string(xml)
212
+ parser.callbacks = DocTypeCallback.new
213
+ doc = parser.parse
214
+ assert_not_nil(doc)
215
+ end
216
+
217
+ def test_parse_warning
218
+ # Two xml PIs is a warning
219
+ xml = <<-EOS
220
+ <?xml version="1.0" encoding="utf-8"?>
221
+ <?xml-invalid?>
222
+ <Test/>
223
+ EOS
224
+
225
+ parser = XML::SaxParser.string(xml)
226
+ parser.callbacks = TestCaseCallbacks.new
227
+
228
+ parser.parse
229
+
230
+ # Check callbacks
231
+ result = parser.callbacks.result
232
+ i = -1
233
+ assert_equal("startdoc", result[i+=1])
234
+ puts "TODO #{__FILE__} #{__LINE__}"
235
+ #assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
236
+ assert_equal("pi: xml-invalid ", result[i+=1])
237
+ assert_equal("start_element: Test, attr: {}", result[i+=1])
238
+ puts "TODO #{__FILE__} #{__LINE__}"
239
+ #assert_equal("start_element_ns: Test, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
240
+ assert_equal("end_element: Test", result[i+=1])
241
+ puts "TODO #{__FILE__} #{__LINE__}"
242
+ #assert_equal("end_element_ns Test, prefix: , uri: ", result[i+=1])
243
+ assert_equal("end_document", result[i+=1])
244
+ end
245
+
246
+ def test_parse_error
247
+ xml = <<-EOS
248
+ <Results>
249
+ EOS
250
+ parser = XML::SaxParser.string(xml)
251
+ parser.callbacks = TestCaseCallbacks.new
252
+
253
+ error = assert_raise(XML::Error) do
254
+ doc = parser.parse
255
+ end
256
+
257
+ # Check callbacks
258
+ result = parser.callbacks.result
259
+
260
+ i = -1
261
+ assert_equal("startdoc", result[i+=1])
262
+ assert_equal("start_element: Results, attr: {}", result[i+=1])
263
+ puts "TODO #{__FILE__} #{__LINE__}"
264
+ #assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
265
+ #assert_equal("characters: \n", result[i+=1])
266
+ #assert_equal("error: Fatal error: Premature end of data in tag Results line 1 at :2.", result[i+=1])
267
+ #assert_equal("end_document", result[i+=1])
268
+
269
+ # assert_not_nil(error)
270
+ # assert_kind_of(XML::Error, error)
271
+ # assert_equal("Fatal error: Premature end of data in tag Results line 1 at :2.", error.message)
272
+ # assert_equal(XML::Error::PARSER, error.domain)
273
+ # assert_equal(XML::Error::TAG_NOT_FINISHED, error.code)
274
+ # assert_equal(XML::Error::FATAL, error.level)
275
+ # assert_nil(error.file)
276
+ # assert_equal(2, error.line)
277
+ # assert_equal('Results', error.str1)
278
+ # assert_nil(error.str2)
279
+ # assert_nil(error.str3)
280
+ # assert_equal(1, error.int1)
281
+ # assert_equal(1, error.int2)
282
+ # assert_nil(error.node)
283
+ end
284
+ #
285
+ def test_parse_seg_fail
286
+ xml = <<-EOS
287
+ <?xml version="1.0" encoding="ISO-8859-1" ?>
288
+ <Products>
289
+ <Product>
290
+ <ProductDescription>
291
+ AQUALIA THERMAL Lichte cr├иme - Versterkende & kalmerende 24 u hydraterende verzorging<br />
292
+ Huid wordt continu gehydrateerd, intens versterkt en gekalmeerd.<br />
293
+ Hypoallergeen. Geschikt voor de gevoelige huid.<br />
294
+ <br />
295
+ 01.EFFECTIVITEIT<br />
296
+ 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 />
297
+ <br />
298
+ 02.GEBRUIK<br />
299
+ 's Morgens en/ of 's avonds aanbrengen. <br />
300
+ <br />
301
+ 03.ACTIEVE INGREDIENTEN<br />
302
+ 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 />
303
+ <br />
304
+ 04.TEXTUUR<br />
305
+ De lichte cr├иme is verfrissend en trekt makkelijk in. Niet vet en niet kleverig. Zonder 'maskereffect'. <br />
306
+ <br />
307
+ 05.GEUR<br />
308
+ Geparfumeerd <br />
309
+ <br />
310
+ 06.INHOUD<br />
311
+ 40 ml tube <br />
312
+ </ProductDescription>
313
+ </Product>
314
+ </Products>
315
+ EOS
316
+
317
+ parser = XML::SaxParser.string(xml)
318
+ parser.callbacks = TestCaseCallbacks.new
319
+
320
+ error = assert_raise(XML::Error) do
321
+ parser.parse
322
+ end
323
+ puts "TODO #{__FILE__} #{__LINE__}"
324
+ #assert_equal("Fatal error: xmlParseEntityRef: no name at :5.", error.to_s)
325
+
326
+ # Check callbacks
327
+ result = parser.callbacks.result
328
+ end
329
+
330
+
331
+ def test_nil_io
332
+ puts "TODO #{__FILE__} #{__LINE__}"
333
+ # error = assert_raise(TypeError) do
334
+ # XML::HTMLParser.io(nil)
335
+ # end
336
+ #
337
+ # assert_equal("Must pass in an IO object", error.to_s)
338
+ end
339
+
340
+ end