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,371 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+ require 'stringio'
6
+
7
+ class TestParser < Test::Unit::TestCase
8
+ def setup
9
+ XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
10
+ end
11
+
12
+ def teardown
13
+ GC.start
14
+ GC.start
15
+ GC.start
16
+ XML::Error.reset_handler()
17
+ end
18
+
19
+ # ----- Sources -------
20
+ def test_document
21
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
22
+ parser = XML::Parser.file(file)
23
+ doc = parser.parse
24
+
25
+ parser = XML::Parser.document(doc)
26
+
27
+ doc = parser.parse
28
+
29
+ assert_instance_of(XML::Document, doc)
30
+ assert_instance_of(XML::Parser::Context, parser.context)
31
+ end
32
+
33
+ def test_nil_document
34
+ error = assert_raise(TypeError) do
35
+ XML::Parser.document(nil)
36
+ end
37
+
38
+ assert_equal("Must pass an XML::Document object", error.to_s)
39
+ end
40
+
41
+ def test_file
42
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
43
+
44
+ parser = XML::Parser.file(file)
45
+ doc = parser.parse
46
+ assert_instance_of(XML::Document, doc)
47
+ assert_instance_of(XML::Parser::Context, parser.context)
48
+ end
49
+
50
+ def test_noexistent_file
51
+ error = assert_raise(XML::Error) do
52
+ XML::Parser.file('i_dont_exist.xml')
53
+ end
54
+
55
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
56
+ end
57
+
58
+ def test_nil_file
59
+ error = assert_raise(TypeError) do
60
+ XML::Parser.file(nil)
61
+ end
62
+
63
+ assert_equal("can't convert nil into String", error.to_s)
64
+ end
65
+
66
+ def test_file_encoding
67
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
68
+ parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
69
+
70
+ puts "TODO #{__FILE__} #{__LINE__}"
71
+ # error = assert_raise(XML::Error) do
72
+ # doc = parser.parse
73
+ # end
74
+ #
75
+ # assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
76
+ #
77
+ # parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
78
+ # doc = parser.parse
79
+ # assert_not_nil(doc)
80
+ end
81
+
82
+ def test_file_base_uri
83
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
84
+
85
+ parser = XML::Parser.file(file)
86
+ doc = parser.parse
87
+ assert(doc.child.base_uri.match(/test\/ruby\/model\/bands.utf-8.xml/))
88
+
89
+ parser = XML::Parser.file(file, :base_uri => "http://libxml.org")
90
+ doc = parser.parse
91
+ assert(doc.child.base_uri.match(/test\/ruby\/model\/bands.utf-8.xml/))
92
+ end
93
+
94
+ def test_io
95
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
96
+ parser = XML::Parser.io(io)
97
+ assert_instance_of(XML::Parser, parser)
98
+
99
+ doc = parser.parse
100
+ assert_instance_of(XML::Document, doc)
101
+ assert_instance_of(XML::Parser::Context, parser.context)
102
+ end
103
+ end
104
+
105
+ def test_io_gc
106
+ # Test that the reader keeps a reference
107
+ # to the io object
108
+ file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
109
+ parser = XML::Parser.io(file)
110
+ file = nil
111
+ GC.start
112
+ assert(parser.parse)
113
+ end
114
+
115
+ def test_nil_io
116
+ error = assert_raise(TypeError) do
117
+ XML::Parser.io(nil)
118
+ end
119
+
120
+ assert_equal("Must pass in an IO object", error.to_s)
121
+ end
122
+
123
+ def test_string_io
124
+ data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
125
+ string_io = StringIO.new(data)
126
+ parser = XML::Parser.io(string_io)
127
+
128
+ doc = parser.parse
129
+ assert_instance_of(XML::Document, doc)
130
+ assert_instance_of(XML::Parser::Context, parser.context)
131
+ end
132
+
133
+ def test_string_io_thread
134
+ thread = Thread.new do
135
+ data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
136
+ string_io = StringIO.new(data)
137
+ parser = XML::Parser.io(string_io)
138
+
139
+ doc = parser.parse
140
+ assert_instance_of(XML::Document, doc)
141
+ assert_instance_of(XML::Parser::Context, parser.context)
142
+ end
143
+
144
+ thread.join
145
+ assert(true)
146
+ end
147
+
148
+ def test_string
149
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
150
+
151
+ parser = XML::Parser.string(str)
152
+ assert_instance_of(XML::Parser, parser)
153
+
154
+ doc = parser.parse
155
+ assert_instance_of(XML::Document, doc)
156
+ assert_instance_of(XML::Parser::Context, parser.context)
157
+ end
158
+
159
+ def test_nil_string
160
+ error = assert_raise(TypeError) do
161
+ XML::Parser.string(nil)
162
+ end
163
+
164
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
165
+ end
166
+
167
+ def test_string_options
168
+ xml = <<-EOS
169
+ <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
170
+ <test>
171
+ <cdata><![CDATA[something]]></cdata>
172
+ <entity>&foo;</entity>
173
+ </test>
174
+ EOS
175
+
176
+ XML::default_substitute_entities = false
177
+
178
+ # Parse normally
179
+ parser = XML::Parser.string(xml)
180
+ doc = parser.parse
181
+ assert_nil(doc.child.base_uri)
182
+
183
+ # Cdata section should be cdata nodes
184
+ node = doc.find_first('/test/cdata').child
185
+ assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type)
186
+
187
+ # Entities should not be subtituted
188
+ node = doc.find_first('/test/entity')
189
+ puts "TODO #{__FILE__} #{__LINE__}"
190
+ #assert_equal('&foo;', node.child.to_s)
191
+
192
+ # Parse with options
193
+ parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
194
+ :options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT)
195
+ doc = parser.parse
196
+ puts "TODO #{__FILE__} #{__LINE__}"
197
+ #assert_equal( 'http://libxml.rubyforge.org', doc.child.base_uri)
198
+
199
+ # Cdata section should be text nodes
200
+ node = doc.find_first('/test/cdata').child
201
+ puts "TODO #{__FILE__} #{__LINE__}"
202
+ #assert_equal(XML::Node::TEXT_NODE, node.node_type)
203
+
204
+ # Entities should be subtituted
205
+ node = doc.find_first('/test/entity')
206
+ puts "TODO #{__FILE__} #{__LINE__}"
207
+ #assert_equal('bar', node.child.to_s)
208
+ end
209
+ #
210
+ def test_string_encoding
211
+ # ISO_8859_1:
212
+ # ö - f6 in hex, \366 in octal
213
+ # ü - fc in hex, \374 in octal
214
+
215
+ xml = <<-EOS
216
+ <bands>
217
+ <metal>m\366tley_cr\374e</metal>
218
+ </bands>
219
+ EOS
220
+
221
+ # Parse as UTF_8
222
+ parser = XML::Parser.string(xml, :encoding => XML::Encoding::UTF_8)
223
+
224
+ puts "TODO #{__FILE__} #{__LINE__}"
225
+ # error = assert_raise(XML::Error) do
226
+ # doc = parser.parse
227
+ # end
228
+ #
229
+ # assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
230
+ # error.to_s)
231
+
232
+ # Parse as ISO_8859_1:
233
+ parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1)
234
+ doc = parser.parse
235
+ node = doc.find_first('//metal')
236
+ if defined?(Encoding)
237
+ assert_equal(Encoding::ISO8859_1, node.content.encoding)
238
+ assert_equal("m\303\266tley_cr\303\274e".force_encoding(Encoding::ISO8859_1), node.content)
239
+ else
240
+ puts "TODO #{__FILE__} #{__LINE__}"
241
+ #assert_equal("m\303\266tley_cr\303\274e", node.content)
242
+ end
243
+ end
244
+
245
+ def test_fd_gc
246
+ # Test opening # of documents up to the file limit for the OS.
247
+ # Ideally it should run until libxml emits a warning,
248
+ # thereby knowing we've done a GC sweep. For the time being,
249
+ # re-open the same doc `limit descriptors` times.
250
+ # If we make it to the end, then we've succeeded,
251
+ # otherwise an exception will be thrown.
252
+ XML::Error.set_handler {|error|}
253
+
254
+ max_fd = if RUBY_PLATFORM.match(/mswin32|mingw/i)
255
+ 500
256
+ else
257
+ (`ulimit -n`.chomp.to_i) + 1
258
+ end
259
+
260
+ file = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
261
+ max_fd.times do
262
+ XML::Parser.file(file).parse
263
+ end
264
+ XML::Error.reset_handler {|error|}
265
+ end
266
+
267
+
268
+ # ----- Errors ------
269
+ def test_error
270
+ error = assert_raise(XML::Error) do
271
+ XML::Parser.string('<foo><bar/></foz>').parse
272
+ end
273
+
274
+ assert_not_nil(error)
275
+ assert_kind_of(XML::Error, error)
276
+ puts "TODO #{__FILE__} #{__LINE__}"
277
+ #assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message)
278
+ assert_equal(XML::Error::PARSER, error.domain)
279
+ assert_equal(XML::Error::TAG_NAME_MISMATCH, error.code)
280
+ assert_equal(XML::Error::FATAL, error.level)
281
+ assert_nil(error.file)
282
+ puts "TODO #{__FILE__} #{__LINE__}"
283
+ #assert_equal(1, error.line)
284
+ puts "TODO #{__FILE__} #{__LINE__}"
285
+ #assert_equal('foo', error.str1)
286
+ puts "TODO #{__FILE__} #{__LINE__}"
287
+ #assert_equal('foz', error.str2)
288
+ assert_nil(error.str3)
289
+ puts "TODO #{__FILE__} #{__LINE__}"
290
+ #assert_equal(1, error.int1)
291
+ puts "TODO #{__FILE__} #{__LINE__}"
292
+ #assert_equal(20, error.int2)
293
+ assert_nil(error.node)
294
+ end
295
+
296
+ def test_bad_xml
297
+ parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
298
+ error = assert_raise(XML::Error) do
299
+ assert_not_nil(parser.parse)
300
+ end
301
+
302
+ assert_not_nil(error)
303
+ assert_kind_of(XML::Error, error)
304
+ puts "TODO #{__FILE__} #{__LINE__}"
305
+ #assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
306
+ assert_equal(XML::Error::PARSER, error.domain)
307
+ assert_equal(XML::Error::DOCUMENT_END, error.code)
308
+ assert_equal(XML::Error::FATAL, error.level)
309
+ assert_nil(error.file)
310
+
311
+ puts "TODO #{__FILE__} #{__LINE__}"
312
+ #assert_equal(1, error.line)
313
+ assert_nil(error.str1)
314
+ assert_nil(error.str2)
315
+ assert_nil(error.str3)
316
+ puts "TODO #{__FILE__} #{__LINE__}"
317
+ #assert_equal(0, error.int1)
318
+ puts "TODO #{__FILE__} #{__LINE__}"
319
+ #assert_equal(20, error.int2)
320
+ assert_nil(error.node)
321
+ end
322
+
323
+ # Deprecated methods
324
+ def test_document_deprecated
325
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
326
+ parser = XML::Parser.file(file)
327
+ doc = parser.parse
328
+
329
+ parser = XML::Parser.new
330
+ parser.document = doc
331
+ doc = parser.parse
332
+
333
+ assert_instance_of(XML::Document, doc)
334
+ assert_instance_of(XML::Parser::Context, parser.context)
335
+ end
336
+
337
+ def test_file_deprecated
338
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
339
+
340
+ parser = XML::Parser.new
341
+ parser.file = file
342
+ puts "TODO #{__FILE__} #{__LINE__}"
343
+ #doc = parser.parse
344
+ #assert_instance_of(XML::Document, doc)
345
+ #assert_instance_of(XML::Parser::Context, parser.context)
346
+ end
347
+
348
+ def test_io_deprecated
349
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
350
+ parser = XML::Parser.new
351
+ assert_instance_of(XML::Parser, parser)
352
+ parser.io = io
353
+
354
+ doc = parser.parse
355
+ assert_instance_of(XML::Document, doc)
356
+ assert_instance_of(XML::Parser::Context, parser.context)
357
+ end
358
+ end
359
+
360
+ def test_string_deprecated
361
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
362
+
363
+ parser = XML::Parser.new
364
+ parser.string = str
365
+ assert_instance_of(XML::Parser, parser)
366
+
367
+ doc = parser.parse
368
+ assert_instance_of(XML::Document, doc)
369
+ assert_instance_of(XML::Parser::Context, parser.context)
370
+ end
371
+ end
@@ -0,0 +1,189 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+ class TestParserContext < Test::Unit::TestCase
8
+ def test_string
9
+ # UTF8
10
+ xml = <<-EOS
11
+ <bands>
12
+ <metal>m\303\266tley_cr\303\274e</metal>
13
+ </bands>
14
+ EOS
15
+
16
+ context = XML::Parser::Context.string(xml)
17
+ assert_instance_of(XML::Parser::Context, context)
18
+ assert_equal(XML::Encoding::NONE, context.encoding)
19
+ assert_nil(context.base_uri)
20
+ end
21
+
22
+ def test_encoding
23
+ # ISO_8859_1:
24
+ xml = <<-EOS
25
+ <bands>
26
+ <metal>m\366tley_cr\374e</metal>
27
+ </bands>
28
+ EOS
29
+
30
+ context = XML::Parser::Context.string(xml)
31
+ assert_equal(XML::Encoding::NONE, context.encoding)
32
+
33
+ context.encoding = XML::Encoding::ISO_8859_1
34
+ assert_equal(XML::Encoding::ISO_8859_1, context.encoding)
35
+ end
36
+
37
+ def test_base_uri
38
+ # UTF8
39
+ xml = <<-EOS
40
+ <bands>
41
+ <metal>m\303\266tley_cr\303\274e</metal>
42
+ </bands>
43
+ EOS
44
+
45
+ context = XML::Parser::Context.string(xml)
46
+ assert_nil(context.base_uri)
47
+
48
+ context.base_uri = 'http://libxml.rubyforge.org'
49
+ assert_equal('http://libxml.rubyforge.org', context.base_uri)
50
+ end
51
+
52
+ def test_string_empty
53
+ error = assert_raise(TypeError) do
54
+ parser = XML::Parser::Context.string(nil)
55
+ end
56
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
57
+
58
+ error = assert_raise(ArgumentError) do
59
+ XML::Parser::Context.string('')
60
+ end
61
+ assert_equal("Must specify a string with one or more characters", error.to_s)
62
+ end
63
+
64
+ def test_well_formed
65
+ parser = XML::Parser.string("<abc/>")
66
+ parser.parse
67
+ assert(parser.context.well_formed?)
68
+ end
69
+
70
+ def test_not_well_formed
71
+ parser = XML::Parser.string("<abc>")
72
+ assert_raise(XML::Error) do
73
+ parser.parse
74
+ end
75
+ assert(!parser.context.well_formed?)
76
+ end
77
+
78
+ def test_version_info
79
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
80
+ parser = XML::Parser.file(file)
81
+ assert_nil(parser.context.version)
82
+ parser.parse
83
+ assert_equal("1.0", parser.context.version)
84
+ end
85
+
86
+ def test_depth
87
+ context = XML::Parser::Context.new
88
+ assert_instance_of(Fixnum, context.depth)
89
+ end
90
+
91
+ def test_disable_sax
92
+ context = XML::Parser::Context.new
93
+ assert(!context.disable_sax?)
94
+ end
95
+
96
+ def test_docbook
97
+ context = XML::Parser::Context.new
98
+ assert(!context.docbook?)
99
+ end
100
+
101
+ def test_html
102
+ context = XML::Parser::Context.new
103
+ assert(!context.html?)
104
+ end
105
+
106
+ def test_keep_blanks
107
+ context = XML::Parser::Context.new
108
+ if context.keep_blanks?
109
+ assert_instance_of(TrueClass, context.keep_blanks?)
110
+ else
111
+ assert_instance_of(FalseClass, context.keep_blanks?)
112
+ end
113
+ end
114
+
115
+ if ENV['NOTWORKING']
116
+ def test_num_chars
117
+ assert_equal(17, context.num_chars)
118
+ end
119
+ end
120
+
121
+ def test_replace_entities
122
+ context = XML::Parser::Context.new
123
+ assert(!context.replace_entities?)
124
+
125
+ # context.options = 1
126
+ # assert(context.replace_entities?)
127
+
128
+ context.options = 0
129
+ assert(!context.replace_entities?)
130
+
131
+ context.replace_entities = true
132
+ assert(context.replace_entities?)
133
+ end
134
+
135
+ def test_space_depth
136
+ context = XML::Parser::Context.new
137
+ assert_equal(1, context.space_depth)
138
+ end
139
+
140
+ def test_subset_external
141
+ context = XML::Parser::Context.new
142
+ assert(!context.subset_external?)
143
+ end
144
+
145
+ def test_data_directory_get
146
+ context = XML::Parser::Context.new
147
+ assert_nil(context.data_directory)
148
+ end
149
+
150
+ def test_parse_error
151
+ xp = XML::Parser.string('<foo><bar/></foz>')
152
+
153
+ assert_raise(XML::Error) do
154
+ xp.parse
155
+ end
156
+
157
+ # Now check context
158
+ context = xp.context
159
+ assert_equal(nil, context.data_directory)
160
+ assert_equal(0, context.depth)
161
+ assert_equal(true, context.disable_sax?)
162
+ assert_equal(false, context.docbook?)
163
+ assert_equal(XML::Encoding::NONE, context.encoding)
164
+ assert_equal(76, context.errno)
165
+ assert_equal(false, context.html?)
166
+ assert_equal(5, context.io_max_num_streams)
167
+ assert_equal(1, context.io_num_streams)
168
+ assert_equal(true, context.keep_blanks?)
169
+ assert_equal(1, context.io_num_streams)
170
+ assert_equal(nil, context.name_node)
171
+ assert_equal(0, context.name_depth)
172
+ assert_equal(10, context.name_depth_max)
173
+ assert_equal(17, context.num_chars)
174
+ assert_equal(false, context.replace_entities?)
175
+ assert_equal(1, context.space_depth)
176
+ assert_equal(10, context.space_depth_max)
177
+ assert_equal(false, context.subset_external?)
178
+ assert_equal(nil, context.subset_external_system_id)
179
+ assert_equal(nil, context.subset_external_uri)
180
+ assert_equal(false, context.subset_internal?)
181
+ assert_equal(nil, context.subset_internal_name)
182
+ assert_equal(false, context.stats?)
183
+ assert_equal(true, context.standalone?)
184
+ assert_equal(false, context.valid)
185
+ assert_equal(false, context.validate?)
186
+ assert_equal('1.0', context.version)
187
+ assert_equal(false, context.well_formed?)
188
+ end
189
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+ # attributes is deprecated - use attributes instead.
8
+ # Tests for backwards compatibility
9
+
10
+ class Testattributes < Test::Unit::TestCase
11
+ def setup()
12
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
13
+ @doc = xp.parse
14
+ end
15
+
16
+ def teardown()
17
+ @doc = nil
18
+ end
19
+
20
+ def test_traversal
21
+ attributes = @doc.root.attributes
22
+
23
+ assert_instance_of(XML::Attributes, attributes)
24
+ f = attributes.first
25
+ l = f.next
26
+ assert( f.name.eql?( 'uga' ) || f.name.eql?( 'foo' ) )
27
+ assert( l.name.eql?( 'uga' ) || l.name.eql?( 'foo' ) )
28
+
29
+ n = f.next
30
+ assert_instance_of(XML::Attr, n)
31
+ assert( n.name.eql?( 'uga' ) || n.name.eql?( 'foo' ) )
32
+
33
+ end
34
+
35
+ def test_no_attributes
36
+ attributes = @doc.root.child.attributes
37
+ assert_instance_of(XML::Attributes, attributes)
38
+ assert_equal(0, attributes.length)
39
+ end
40
+ end