libxml-jruby-fixed 1.0.0-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +91 -0
  3. data/README.txt +50 -0
  4. data/Rakefile +40 -0
  5. data/lib/libxml-jruby.rb +84 -0
  6. data/lib/libxml-jruby/xml.rb +1 -0
  7. data/lib/libxml-jruby/xml/attr.rb +46 -0
  8. data/lib/libxml-jruby/xml/attributes.rb +68 -0
  9. data/lib/libxml-jruby/xml/document.rb +52 -0
  10. data/lib/libxml-jruby/xml/dtd.rb +25 -0
  11. data/lib/libxml-jruby/xml/node.rb +285 -0
  12. data/lib/libxml-jruby/xml/ns.rb +19 -0
  13. data/lib/libxml-jruby/xml/parser.rb +121 -0
  14. data/lib/libxml-jruby/xml/xpath.rb +98 -0
  15. data/lib/libxml.rb +1 -0
  16. data/lib/xml.rb +13 -0
  17. data/lib/xml/libxml.rb +8 -0
  18. data/script/benchmark/depixelate.rb +633 -0
  19. data/script/benchmark/hamlet.xml +9055 -0
  20. data/script/benchmark/sock_entries.xml +507 -0
  21. data/script/benchmark/throughput.rb +40 -0
  22. data/script/benchmark/xml_benchmarks.rb +228 -0
  23. data/script/test +6 -0
  24. data/tasks/ann.rake +81 -0
  25. data/tasks/bones.rake +21 -0
  26. data/tasks/gem.rake +126 -0
  27. data/tasks/git.rake +41 -0
  28. data/tasks/manifest.rake +49 -0
  29. data/tasks/notes.rake +28 -0
  30. data/tasks/post_load.rake +39 -0
  31. data/tasks/rdoc.rake +51 -0
  32. data/tasks/rubyforge.rake +57 -0
  33. data/tasks/setup.rb +268 -0
  34. data/tasks/spec.rake +55 -0
  35. data/tasks/svn.rake +48 -0
  36. data/tasks/test.rake +38 -0
  37. data/test/etc_doc_to_s.rb +19 -0
  38. data/test/ets_copy_bug.rb +21 -0
  39. data/test/ets_copy_bug3.rb +38 -0
  40. data/test/ets_doc_file.rb +15 -0
  41. data/test/ets_doc_to_s.rb +21 -0
  42. data/test/ets_gpx.rb +26 -0
  43. data/test/ets_node_gc.rb +21 -0
  44. data/test/ets_test.xml +2 -0
  45. data/test/ets_tsr.rb +9 -0
  46. data/test/model/books.xml +147 -0
  47. data/test/model/default_validation_bug.rb +0 -0
  48. data/test/model/merge_bug_data.xml +58 -0
  49. data/test/model/rubynet.xml +78 -0
  50. data/test/model/rubynet_project +1 -0
  51. data/test/model/saxtest.xml +5 -0
  52. data/test/model/shiporder.rnc +28 -0
  53. data/test/model/shiporder.rng +86 -0
  54. data/test/model/shiporder.xml +23 -0
  55. data/test/model/shiporder.xsd +31 -0
  56. data/test/model/simple.xml +7 -0
  57. data/test/model/soap.xml +27 -0
  58. data/test/model/xinclude.xml +5 -0
  59. data/test/tc_attributes.rb +110 -0
  60. data/test/tc_deprecated_require.rb +13 -0
  61. data/test/tc_document.rb +97 -0
  62. data/test/tc_document_write.rb +139 -0
  63. data/test/tc_dtd.rb +70 -0
  64. data/test/tc_html_parser.rb +63 -0
  65. data/test/tc_node.rb +108 -0
  66. data/test/tc_node_attr.rb +176 -0
  67. data/test/tc_node_cdata.rb +51 -0
  68. data/test/tc_node_comment.rb +32 -0
  69. data/test/tc_node_copy.rb +40 -0
  70. data/test/tc_node_edit.rb +98 -0
  71. data/test/tc_node_set.rb +24 -0
  72. data/test/tc_node_set2.rb +37 -0
  73. data/test/tc_node_text.rb +17 -0
  74. data/test/tc_node_xlink.rb +28 -0
  75. data/test/tc_ns.rb +18 -0
  76. data/test/tc_parser.rb +308 -0
  77. data/test/tc_parser_context.rb +126 -0
  78. data/test/tc_properties.rb +37 -0
  79. data/test/tc_reader.rb +112 -0
  80. data/test/tc_relaxng.rb +39 -0
  81. data/test/tc_sax_parser.rb +113 -0
  82. data/test/tc_schema.rb +39 -0
  83. data/test/tc_traversal.rb +220 -0
  84. data/test/tc_well_formed.rb +11 -0
  85. data/test/tc_xinclude.rb +26 -0
  86. data/test/tc_xpath.rb +130 -0
  87. data/test/tc_xpath_context.rb +72 -0
  88. data/test/tc_xpointer.rb +78 -0
  89. data/test/test_libxml-jruby.rb +0 -0
  90. data/test/test_suite.rb +31 -0
  91. data/test/ts_working.rb +31 -0
  92. metadata +146 -0
@@ -0,0 +1,17 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TC_XML_Node_text < Test::Unit::TestCase
5
+ def setup
6
+ @t=XML::Node.new_text("testdata")
7
+ assert_instance_of(XML::Node,@t)
8
+ end
9
+
10
+ def test_content
11
+ assert_equal("testdata",@t.content)
12
+ end
13
+
14
+ def test_type
15
+ assert_equal(true,@t.text?)
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # $Id$
2
+ require "xml"
3
+ require 'test/unit'
4
+
5
+ class TC_XML_Node_XLink < Test::Unit::TestCase
6
+ def setup()
7
+ xp = XML::Parser.new()
8
+ str = '<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>'
9
+ assert_equal(str, xp.string = str)
10
+ doc = xp.parse
11
+ assert_instance_of(XML::Document, doc)
12
+ @root = doc.root
13
+ assert_instance_of(XML::Node, @root)
14
+ end
15
+
16
+ def teardown()
17
+ @root = nil
18
+ end
19
+
20
+ def test_xml_node_xlink()
21
+ for elem in @root.find('fixnum')
22
+ assert_instance_of(XML::Node, elem)
23
+ assert_instance_of(TrueClass, elem.xlink?)
24
+ assert_equal("simple", elem.xlink_type_name)
25
+ assert_equal(XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestNS < Test::Unit::TestCase
5
+ def test_ns
6
+ node = XML::Node.new('foo')
7
+ ns = XML::NS.new(node, 'http://www.mynamespace.com', 'my_namepace')
8
+ assert_equal(ns.prefix, 'my_namepace')
9
+ assert_equal(ns.href, 'http://www.mynamespace.com')
10
+ end
11
+
12
+ def test_default_ns
13
+ node = XML::Node.new('foo')
14
+ ns = XML::NS.new(node, 'http://www.mynamespace.com', nil)
15
+ assert_equal(ns.prefix, nil)
16
+ assert_equal(ns.href, 'http://www.mynamespace.com')
17
+ end
18
+ end
@@ -0,0 +1,308 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+ require 'test_helper'
4
+
5
+ class TestParser < Test::Unit::TestCase
6
+ def setup
7
+ XML::Parser.register_error_handler(nil)
8
+ @xp = XML::Parser.new
9
+ end
10
+
11
+ def teardown
12
+ @xp = nil
13
+ XML::Parser.register_error_handler(nil)
14
+ # Clear out all the files we opened up in
15
+ # the test_fd_gc test
16
+ GC.start
17
+ end
18
+
19
+ # ----- Constants ------
20
+ def test_lib_versions
21
+ assert(XML::Parser::check_lib_versions)
22
+ end
23
+
24
+ def test_debug_entities
25
+ XML::Parser::debug_entities = false
26
+ assert(!XML::Parser::debug_entities)
27
+
28
+ XML::Parser::debug_entities = true
29
+ assert(XML::Parser::debug_entities)
30
+
31
+ XML::Parser::debug_entities = false
32
+ assert(!XML::Parser::debug_entities)
33
+ end
34
+
35
+ def test_default_compression
36
+ return unless XML::Parser::default_compression
37
+
38
+ 0.upto(9) do |i|
39
+ XML::Parser::default_compression = i
40
+ assert_equal(i, XML::Parser::default_compression)
41
+ end
42
+
43
+ 9.downto(0) do |i|
44
+ assert_equal(i, XML::Parser::default_compression = i)
45
+ assert_equal(i, XML::Parser::default_compression)
46
+ end
47
+
48
+ 0.downto(-10) do |i|
49
+ assert_equal(i, XML::Parser::default_compression = i)
50
+ assert_equal(0, XML::Parser::default_compression)
51
+ end
52
+
53
+ 10.upto(20) do |i|
54
+ assert_equal(i, XML::Parser::default_compression = i)
55
+ assert_equal(9, XML::Parser::default_compression)
56
+ end
57
+ end
58
+
59
+ def test_default_keep_blanks
60
+ XML::Parser::default_keep_blanks = false
61
+ assert(!XML::Parser::default_keep_blanks)
62
+
63
+ XML::Parser::default_keep_blanks = true
64
+ assert(XML::Parser::default_keep_blanks)
65
+
66
+ XML::Parser::default_keep_blanks = false
67
+ assert(!XML::Parser::default_keep_blanks)
68
+
69
+ # other tests depend on keeping blanks by default,
70
+ # which is the default default behaviour anyway.
71
+ XML::Parser::default_keep_blanks = true
72
+ end
73
+
74
+ def test_default_line_numbers
75
+ XML::Parser::default_line_numbers = false
76
+ assert(!XML::Parser::default_line_numbers)
77
+
78
+ XML::Parser::default_line_numbers = true
79
+ assert(XML::Parser::default_line_numbers)
80
+
81
+ XML::Parser::default_line_numbers = false
82
+ assert(!XML::Parser::default_line_numbers)
83
+ end
84
+
85
+ def test_default_substitute_entities
86
+ XML::Parser::default_substitute_entities = false
87
+ assert(!XML::Parser::default_substitute_entities)
88
+
89
+ XML::Parser::default_substitute_entities = true
90
+ assert(XML::Parser::default_substitute_entities)
91
+
92
+ XML::Parser::default_substitute_entities = false
93
+ assert(!XML::Parser::default_substitute_entities)
94
+ end
95
+
96
+ def test_default_tree_indent_string
97
+ s = XML::Parser::default_tree_indent_string
98
+ assert_instance_of(String, s)
99
+ assert_equal(' ', s)
100
+ XML::Parser::default_tree_indent_string = 'uga'
101
+ s = XML::Parser::default_tree_indent_string
102
+ assert_instance_of(String, s)
103
+ assert_equal('uga', s)
104
+ XML::Parser::default_tree_indent_string = ' '
105
+ s = XML::Parser::default_tree_indent_string
106
+ assert_instance_of(String, s)
107
+ assert_equal(' ', s)
108
+ end
109
+
110
+ def test_default_validity_checking
111
+ XML::Parser::default_validity_checking = false
112
+ assert(!XML::Parser::default_validity_checking)
113
+
114
+ XML::Parser::default_validity_checking = true
115
+ assert(XML::Parser::default_validity_checking)
116
+
117
+ XML::Parser::default_validity_checking = false
118
+ assert(!XML::Parser::default_validity_checking)
119
+ end
120
+
121
+ def test_default_warnings
122
+ XML::Parser::default_warnings = false
123
+ assert(!XML::Parser::default_warnings)
124
+
125
+ XML::Parser::default_warnings = true
126
+ assert(XML::Parser::default_warnings)
127
+
128
+ XML::Parser::default_warnings = false
129
+ assert(!XML::Parser::default_warnings)
130
+ end
131
+
132
+ def test_intent_tree_output
133
+ assert(TrueClass, XML::Parser::indent_tree_output)
134
+
135
+ XML::Parser::indent_tree_output = false
136
+ assert(FalseClass, XML::Parser::indent_tree_output)
137
+
138
+ XML::Parser::indent_tree_output = true
139
+ assert(TrueClass, XML::Parser::indent_tree_output)
140
+ end
141
+
142
+ def test_version
143
+ assert_instance_of(String, XML::Parser::VERSION)
144
+ end
145
+
146
+ def test_vernum
147
+ assert_instance_of(Fixnum, XML::Parser::VERNUM)
148
+ end
149
+
150
+ # ----- IO ------
151
+ def test_string
152
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
153
+ assert_equal(str, @xp.string = str)
154
+ assert_instance_of(XML::Document, @xp.parse)
155
+ end
156
+
157
+ def test_context
158
+ @xp = XML::Parser.string('<rubynet><testing>uga</testing><uga>foo</uga></rubynet>')
159
+ doc = @xp.parse
160
+ assert_instance_of(XML::Document, doc)
161
+ # FIXME Parser#context is not implemented
162
+ # assert_instance_of(XML::Parser::Context, @xp.context)
163
+ end
164
+
165
+ def test_file
166
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
167
+
168
+ @xp.filename = file
169
+ assert_equal(file, @xp.filename)
170
+
171
+ doc = @xp.parse
172
+ assert_instance_of(XML::Document, doc)
173
+ end
174
+
175
+ def test_io
176
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |f|
177
+ assert_kind_of(IO, f)
178
+ assert_kind_of(IO, @xp.io = f)
179
+ assert_instance_of(XML::Document, @xp.parse)
180
+ end
181
+ end
182
+
183
+ def test_string_io
184
+ data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
185
+ string_io = StringIO.new(data)
186
+ assert_raises(TypeError) do
187
+ assert_kind_of(StringIO, @xp.io = string_io)
188
+ end
189
+ end
190
+
191
+ def test_fd_gc
192
+ # Test opening # of documents up to the file limit for the OS.
193
+ # Ideally it should run until libxml emits a warning,
194
+ # thereby knowing we've done a GC sweep. For the time being,
195
+ # re-open the same doc `limit descriptors` times.
196
+ # If we make it to the end, then we've succeeded,
197
+ # otherwise an exception will be thrown.
198
+
199
+ # FIXME removed test, extremely slow...
200
+ # XML::Parser.register_error_handler(lambda {|msg| nil })
201
+ #
202
+ # max_fd = if RUBY_PLATFORM.match(/mswin32/i)
203
+ # 500
204
+ # else
205
+ # (`ulimit -n`.chomp.to_i) + 1
206
+ # end
207
+ #
208
+ # filename = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
209
+ # max_fd.times do
210
+ # XML::Document.file(filename)
211
+ # end
212
+ end
213
+
214
+ def test_libxml_parser_features
215
+ assert_instance_of(Array, XML::Parser::features)
216
+ end
217
+
218
+ # ----- Errors ------
219
+ def test_error_handler
220
+ assert_raise(XML::Parser::ParseError) do
221
+ XML::Parser.string('<foo><bar/></foz>').parse
222
+ end
223
+
224
+ ary = []
225
+ XML::Parser.register_error_handler do |msg|
226
+ ary << msg
227
+ end
228
+
229
+ # this will use our error handler
230
+ assert_raise(XML::Parser::ParseError) do
231
+ XML::Parser.string('<foo><bar/></foz>').parse
232
+ end
233
+
234
+ # FIXME Errors are not the same across platforms
235
+ # assert_equal(["Entity: line 1: ",
236
+ # "parser ",
237
+ # "error : ",
238
+ # "Opening and ending tag mismatch: foo line 1 and foz\n",
239
+ # "<foo><bar/></foz>\n",
240
+ # " ^\n"], ary)
241
+
242
+ # assert_instance_of(Proc, XML::Parser.register_error_handler(nil))
243
+
244
+ # this will go to stderr again
245
+ assert_raise(XML::Parser::ParseError) do
246
+ d = XML::Parser.string('<foo><bar/></foz>').parse
247
+ end
248
+ end
249
+
250
+ def test_error_handler_lambda
251
+ XML::Parser.register_error_handler(nil)
252
+ assert_raise(XML::Parser::ParseError) do
253
+ XML::Parser.string('<foo><bar/></foz>').parse
254
+ end
255
+
256
+ ary = []
257
+ assert_nil XML::Parser.register_error_handler(lambda { |msg| ary << msg })
258
+
259
+ # this will use our error handler
260
+ assert_raise(XML::Parser::ParseError) do
261
+ XML::Parser.string('<foo><bar/></foz>').parse
262
+ end
263
+
264
+ # FIXME Errors are not the same across platforms
265
+ # assert_equal(["Entity: line 1: ",
266
+ # "parser ",
267
+ # "error : ",
268
+ # "Opening and ending tag mismatch: foo line 1 and foz\n",
269
+ # "<foo><bar/></foz>\n",
270
+ # " ^\n"], ary)
271
+
272
+ # assert_instance_of(Proc, XML::Parser.register_error_handler(nil))
273
+
274
+ # this will go to stderr again
275
+ assert_raise(XML::Parser::ParseError) do
276
+ d = XML::Parser.string('<foo><bar/></foz>').parse
277
+ end
278
+ end
279
+
280
+ def test_bad_xml
281
+ @xp.string = '<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
282
+ XML::Parser.register_error_handler(lambda {|msg| nil })
283
+ assert_raise(XML::Parser::ParseError) do
284
+ assert_not_nil(@xp.parse)
285
+ end
286
+ end
287
+
288
+ def test_double_parse
289
+ XML::Parser.register_error_handler(lambda {|msg| nil })
290
+ parser = XML::Parser.string("<test>something</test>")
291
+ doc = parser.parse
292
+
293
+ assert_raise(XML::Parser::ParseError) do
294
+ parser.parse
295
+ end
296
+ end
297
+
298
+ def test_libxml_parser_empty_string
299
+ assert_raise(XML::Parser::ParseError) do
300
+ @xp.string = ''
301
+ @xp.parse
302
+ end
303
+
304
+ assert_raise(TypeError) do
305
+ @xp.string = nil
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,126 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestParserContext < Test::Unit::TestCase
5
+ def setup
6
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
7
+ xp = XML::Parser.string(str)
8
+ assert_equal(str, xp.string = str)
9
+ doc = xp.parse
10
+ assert_instance_of(XML::Document, doc)
11
+ @ctxt = xp.context
12
+ assert_instance_of(XML::Parser::Context, @ctxt)
13
+ end
14
+
15
+ def teardown
16
+ @ctxt = nil
17
+ end
18
+
19
+ def test_well_formed
20
+ if @ctxt.well_formed?
21
+ assert_instance_of(TrueClass, @ctxt.well_formed?)
22
+ else
23
+ assert_instance_of(FalseClass, @ctxt.well_formed?)
24
+ end
25
+ end
26
+
27
+ def test_version_info
28
+ assert_instance_of(String, @ctxt.version)
29
+ end
30
+
31
+ def test_depth
32
+ assert_instance_of(Fixnum, @ctxt.depth)
33
+ end
34
+
35
+ def test_disable_sax
36
+ assert(!@ctxt.disable_sax?)
37
+ end
38
+
39
+ def test_docbook
40
+ assert(!@ctxt.docbook?)
41
+ end
42
+
43
+ def test_encoding
44
+ assert(!@ctxt.encoding)
45
+ end
46
+
47
+ def test_html
48
+ assert(!@ctxt.html?)
49
+ end
50
+
51
+ def test_keep_blanks
52
+ if @ctxt.keep_blanks?
53
+ assert_instance_of(TrueClass, @ctxt.keep_blanks?)
54
+ else
55
+ assert_instance_of(FalseClass, @ctxt.keep_blanks?)
56
+ end
57
+ end
58
+
59
+ if ENV['NOTWORKING']
60
+ def test_num_chars
61
+ assert_equal(17, @ctxt.num_chars)
62
+ end
63
+ end
64
+
65
+ def test_replace_entities
66
+ if @ctxt.replace_entities?
67
+ assert_instance_of(TrueClass, @ctxt.replace_entities?)
68
+ else
69
+ assert_instance_of(FalseClass, @ctxt.replace_entities?)
70
+ end
71
+ end
72
+
73
+ def test_space_depth
74
+ assert_equal(1, @ctxt.space_depth)
75
+ end
76
+
77
+ def test_subset_external
78
+ assert(!@ctxt.subset_external?)
79
+ end
80
+
81
+ def test_data_directory_get
82
+ assert_nil(@ctxt.data_directory)
83
+ end
84
+
85
+ def test_parse_error
86
+ xp = XML::Parser.new
87
+ xp.string = '<foo><bar/></foz>'
88
+
89
+ assert_raise(XML::Parser::ParseError) do
90
+ xp.parse
91
+ end
92
+
93
+ # Now check context
94
+ context = xp.context
95
+ assert_equal(nil, context.data_directory)
96
+ assert_equal(0, context.depth)
97
+ assert_equal(true, context.disable_sax?)
98
+ assert_equal(false, context.docbook?)
99
+ assert_equal(nil, context.encoding)
100
+ assert_equal(76, context.errno)
101
+ assert_equal(false, context.html?)
102
+ assert_equal(5, context.io_max_num_streams)
103
+ assert_equal(1, context.io_num_streams)
104
+ assert_equal(true, context.keep_blanks?)
105
+ assert_equal(1, context.io_num_streams)
106
+ assert_equal(nil, context.name_node)
107
+ assert_equal(0, context.name_depth)
108
+ assert_equal(10, context.name_depth_max)
109
+ assert_equal(17, context.num_chars)
110
+ assert_equal(0, context.options)
111
+ assert_equal(true, context.replace_entities?)
112
+ assert_equal(1, context.space_depth)
113
+ assert_equal(10, context.space_depth_max)
114
+ assert_equal(false, context.subset_external?)
115
+ assert_equal(nil, context.subset_external_system_id)
116
+ assert_equal(nil, context.subset_external_uri)
117
+ assert_equal(false, context.subset_internal?)
118
+ assert_equal(nil, context.subset_internal_name)
119
+ assert_equal(false, context.stats?)
120
+ assert_equal(true, context.standalone?)
121
+ assert_equal(false, context.valid)
122
+ assert_equal(false, context.validate?)
123
+ assert_equal('1.0', context.version)
124
+ assert_equal(false, context.well_formed?)
125
+ end
126
+ end