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,13 @@
1
+ require 'xml/libxml'
2
+ require 'test/unit'
3
+
4
+ class TestDeprecatedRequire < Test::Unit::TestCase
5
+ def test_basic
6
+ xp = XML::Parser.new
7
+ assert_instance_of(XML::Parser, xp)
8
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
9
+ assert_equal(str, xp.string = str)
10
+ @doc = xp.parse
11
+ assert_instance_of(XML::Document, @doc)
12
+ end
13
+ end
@@ -0,0 +1,97 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+
5
+ class TC_XML_Document < Test::Unit::TestCase
6
+ def setup
7
+ xp = XML::Parser.new
8
+ assert_instance_of(XML::Parser, xp)
9
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
10
+ assert_equal(str, xp.string = str)
11
+ @doc = xp.parse
12
+ assert_instance_of(XML::Document, @doc)
13
+ end
14
+
15
+ def teardown
16
+ @doc = nil
17
+ end
18
+
19
+ def test_libxml_document_find
20
+ set = @doc.find('/ruby_array/fixnum')
21
+ assert_instance_of(XML::XPath::Object, set)
22
+ assert_raise(NoMethodError) {
23
+ xpt = set.xpath
24
+ }
25
+ end
26
+
27
+ # FIXME XML::Parser::enabled_zlib? zlib support
28
+ # def test_ruby_xml_document_compression
29
+ # if XML::Parser::enabled_zlib?
30
+ # 0.upto(9) do |i|
31
+ # assert_equal(i, @doc.compression = i)
32
+ # assert_equal(i, @doc.compression)
33
+ # end
34
+ #
35
+ # 9.downto(0) do |i|
36
+ # assert_equal(i, @doc.compression = i)
37
+ # assert_equal(i, @doc.compression)
38
+ # end
39
+ #
40
+ # 10.upto(20) do |i|
41
+ # # assert_equal(9, @doc.compression = i)
42
+ # assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
43
+ # assert_equal(9, @doc.compression)
44
+ # end
45
+ #
46
+ # -1.downto(-10) do |i|
47
+ # # assert_equal(0, @doc.compression = i)
48
+ # assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
49
+ # assert_equal(0, @doc.compression)
50
+ # end
51
+ # end
52
+ # end
53
+
54
+ # FIXME Document#save
55
+ # def test_save
56
+ # filename = 'test_write'
57
+ # bytes = @doc.save(filename)
58
+ # assert_equal(110, bytes)
59
+ # contents = File.read(filename)
60
+ #
61
+ # expected =<<-EOS
62
+ # <?xml version="1.0"?>
63
+ # <ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>
64
+ # EOS
65
+ # assert_equal(expected, contents)
66
+ # ensure
67
+ # File.delete(filename)
68
+ # end
69
+
70
+ # FIXME Document#save
71
+ # def test_save_formatted
72
+ # filename = 'test_write'
73
+ # bytes = @doc.save(filename, true)
74
+ # assert_equal(117, bytes)
75
+ # contents = File.read(filename)
76
+ #
77
+ # expected =<<-EOS
78
+ # <?xml version="1.0"?>
79
+ # <ruby_array uga="booga" foo="bar">
80
+ # <fixnum>one</fixnum>
81
+ # <fixnum>two</fixnum>
82
+ # </ruby_array>
83
+ # EOS
84
+ # assert_equal(expected, contents)
85
+ # ensure
86
+ # File.delete(filename)
87
+ # end
88
+
89
+ # FIXME Document#save
90
+ # def test_save_formatted_invalid
91
+ # filename = 'test_write'
92
+ #
93
+ # assert_raise(ArgumentError) do
94
+ # @doc.save(filename, 1)
95
+ # end
96
+ # end
97
+ end
@@ -0,0 +1,139 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TC_XML_Document_Write < Test::Unit::TestCase
5
+ def setup
6
+ @doc = XML::Document.new('1.0')
7
+ end
8
+
9
+ def teardown
10
+ @doc = nil
11
+ end
12
+
13
+ def test_klass
14
+ assert_instance_of(XML::Document, @doc)
15
+ end
16
+
17
+ def test_version
18
+ assert_equal('1.0', @doc.version)
19
+
20
+ doc = XML::Document.new('6.9')
21
+ assert_equal('6.9', doc.version)
22
+ end
23
+
24
+ def test_write_root
25
+ @doc.root = XML::Node.new('rubynet')
26
+ assert_instance_of(XML::Node, @doc.root)
27
+ assert_instance_of(XML::Document, @doc.root.doc)
28
+ assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s)
29
+ end
30
+
31
+ def test_write_root
32
+ @doc.root = XML::Node.new('rubynet')
33
+ assert_instance_of(XML::Node, @doc.root)
34
+ assert_instance_of(XML::Document, @doc.root.doc)
35
+ assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s(false))
36
+ end
37
+
38
+ def test_encoding
39
+ @doc.root = XML::Node.new('rubynet')
40
+ @doc.encoding = 'UTF-8'
41
+ assert_instance_of(XML::Node, @doc.root)
42
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n", @doc.to_s)
43
+ end
44
+
45
+ def test_child()
46
+ xml = "<?xml version=\"1.0\"?>\n<rubynet>\n <pkg/>\n</rubynet>\n"
47
+ @doc.root = XML::Node.new('rubynet')
48
+ @doc.root.child = XML::Node.new('pkg')
49
+ assert_equal(xml, @doc.to_s)
50
+ end
51
+
52
+ def test_append
53
+ xml = "<?xml version=\"1.0\"?>\n"
54
+ xml << "<rubynet>\n"
55
+ xml << " <pkg>\n"
56
+ xml << " <meta>\n"
57
+ xml << " <pkgname>libxml</pkgname>\n"
58
+ xml << " </meta>\n"
59
+ xml << " </pkg>\n"
60
+ xml << "</rubynet>\n"
61
+
62
+ @doc.root = XML::Node.new('rubynet')
63
+ pkg = @doc.root.child = XML::Node.new('pkg')
64
+ meta = pkg.child = XML::Node.new('meta')
65
+ assert_equal(meta, meta << (pkgname = XML::Node.new('pkgname')))
66
+ pkgname << 'libxml'
67
+ assert_equal(xml, @doc.to_s)
68
+ end
69
+
70
+ def test_node_search_href
71
+ prefix = 'xlink'
72
+ uri = 'http://www.rubynet.org'
73
+ xml = "<?xml version=\"1.0\"?>\n"
74
+ xml << "<rubynet xmlns:#{prefix}=\"#{uri}\">\n"
75
+ xml << " <pkg/>\n"
76
+ xml << "</rubynet>\n"
77
+
78
+ @doc.root = XML::Node.new('rubynet')
79
+ @doc = XML::Parser.string(xml).parse
80
+ assert_equal(xml, @doc.to_s)
81
+ ns = @doc.root.search_href(uri)
82
+ assert_instance_of(XML::NS, ns)
83
+ assert_equal(uri, ns.href)
84
+ assert_equal(prefix, ns.prefix)
85
+ end
86
+
87
+ def test_sibling
88
+ xml = "<?xml version=\"1.0\"?>\n<rubynet>\n <pkg/>\n <pkg2/>\n</rubynet>\n"
89
+
90
+ @doc.root = XML::Node.new('rubynet')
91
+ child = @doc.root.child = XML::Node.new('pkg')
92
+ assert_instance_of(XML::Node, child)
93
+ child.sibling = XML::Node.new('pkg2')
94
+ assert_equal(xml, @doc.to_s)
95
+ end
96
+
97
+ def test_set_doc_property
98
+ xml = "<?xml version=\"1.0\"?>\n"
99
+ xml << "<rubynet xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
100
+ xml << " <pkg/>\n"
101
+ xml << "</rubynet>\n"
102
+
103
+ @doc.root = XML::Node.new('rubynet')
104
+ @doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"
105
+ pkg = @doc.root.child = XML::Node.new('pkg')
106
+ assert_equal(xml, @doc.to_s)
107
+ end
108
+
109
+ def test_set_node_base
110
+ xml = "<?xml version=\"1.0\"?>\n"
111
+ xml << "<rubynet>\n"
112
+ xml << " <pkg xml:base=\"http://www.rubynet.org/\"/>\n"
113
+ xml << "</rubynet>\n"
114
+
115
+ @doc.root = XML::Node.new('rubynet')
116
+ pkg = @doc.root.child = XML::Node.new('pkg')
117
+ pkg.base = 'http://www.rubynet.org/'
118
+ assert_equal(xml, @doc.to_s)
119
+ end
120
+
121
+ def test_set_node_property
122
+ xml = "<?xml version=\"1.0\"?>\n"
123
+ xml << "<rubynet xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
124
+ xml << " <pkg version=\"1.0\">\n"
125
+ xml << " <meta>\n"
126
+ xml << " <pkgname>libxml</pkgname>\n"
127
+ xml << " </meta>\n"
128
+ xml << " </pkg>\n"
129
+ xml << "</rubynet>\n"
130
+
131
+ @doc.root = XML::Node.new('rubynet')
132
+ @doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"
133
+ pkg = @doc.root.child = XML::Node.new('pkg')
134
+ pkg['version'] = '1.0'
135
+ meta = pkg.child = XML::Node.new('meta')
136
+ pkgname = meta.child = XML::Node.new('pkgname', 'libxml')
137
+ assert_equal(xml, @doc.to_s)
138
+ end
139
+ end
@@ -0,0 +1,70 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestDtd < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.string(<<-EOS)
7
+ <root>
8
+ <head a="ee" id="1">Colorado</head>
9
+ <descr>Lots of nice mountains</descr>
10
+ </root>
11
+ EOS
12
+ @doc = xp.parse
13
+ end
14
+
15
+ def teardown
16
+ @doc = nil
17
+ end
18
+
19
+ def dtd
20
+ XML::Dtd.new(<<-EOS)
21
+ <!ELEMENT root (head, descr)>
22
+ <!ELEMENT head (#PCDATA)>
23
+ <!ATTLIST head
24
+ id NMTOKEN #REQUIRED
25
+ a CDATA #IMPLIED
26
+ >
27
+ <!ELEMENT descr (#PCDATA)>
28
+ EOS
29
+ end
30
+
31
+ def test_valid
32
+ assert(@doc.validate(dtd))
33
+ end
34
+
35
+ def test_invalid
36
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
37
+ @doc.root.child_add(new_node)
38
+
39
+ messages = Hash.new
40
+ assert(!@doc.validate(dtd) do |message, error|
41
+ messages[message] = error
42
+ end)
43
+
44
+ expected = {"No declaration for element invalid\n" => true,
45
+ "Element root content does not follow the DTD, expecting (head , descr), got (head descr invalid)\n" => true}
46
+
47
+ assert_equal(expected, messages)
48
+ end
49
+
50
+ def test_external_dtd
51
+ xml = <<-EOS
52
+ <!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []>
53
+ <test>
54
+ <title>T1</title>
55
+ </test>
56
+ EOS
57
+
58
+ messages = Array.new
59
+ XML::Parser.register_error_handler(lambda { |msg| messages << msg })
60
+
61
+ XML::Parser.default_load_external_dtd = false
62
+ doc = XML::Parser.string(xml).parse
63
+ assert_equal(Array.new, messages)
64
+
65
+ XML::Parser.default_load_external_dtd = true
66
+ doc = XML::Parser.string(xml).parse
67
+ assert_equal('I/O warning : failed to load external entity "test.dtd" <!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []> ^',
68
+ messages.map{|msg| msg.strip}.join(' '))
69
+ end
70
+ end
@@ -0,0 +1,63 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TC_XML_HTMLParser < Test::Unit::TestCase
5
+ def setup()
6
+ @xp = XML::HTMLParser.new()
7
+ assert_not_nil(@xp)
8
+ str = '<html><head><meta name=keywords content=nasty></head><body>Hello<br>World</html>'
9
+ @xp.string = str
10
+ assert_equal(str, @xp.string)
11
+ end
12
+
13
+ def teardown()
14
+ @xp = nil
15
+ end
16
+
17
+ def test_libxml_html_parser_parse()
18
+ doc = @xp.parse
19
+
20
+ assert_instance_of XML::Document, doc
21
+
22
+ root = doc.root
23
+ assert_instance_of XML::Node, root
24
+ assert_equal 'html', root.name
25
+
26
+ head = root.child
27
+ assert_instance_of XML::Node, head
28
+ assert_equal 'head', head.name
29
+
30
+ meta = head.child
31
+ assert_instance_of XML::Node, meta
32
+ assert_equal 'meta', meta.name
33
+ assert_equal 'keywords', meta[:name]
34
+ assert_equal 'nasty', meta[:content]
35
+
36
+ body = head.next
37
+ assert_instance_of XML::Node, body
38
+ assert_equal 'body', body.name
39
+
40
+ hello = body.child
41
+ # It appears that some versions of libxml2 add a layer of <p>
42
+ # cant figure our why or how, so this skips it if there
43
+ hello = hello.child if hello.name == "p"
44
+
45
+ assert_instance_of XML::Node, hello
46
+ assert_equal 'Hello', hello.content
47
+
48
+ br = hello.next
49
+ assert_instance_of XML::Node, br
50
+ assert_equal 'br', br.name
51
+
52
+ world = br.next
53
+ assert_instance_of XML::Node, world
54
+ assert_equal 'World', world.content
55
+ end
56
+
57
+ def test_libxml_html_parser_context()
58
+ doc = @xp.parse
59
+ assert_instance_of(XML::Document, doc)
60
+ assert_instance_of(XML::Parser::Context, @xp.context)
61
+ assert @xp.context.html?
62
+ end
63
+ end # TC_XML_HTMLParser
@@ -0,0 +1,108 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestNode < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.new()
7
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
8
+ assert_equal(str, xp.string = str)
9
+ @doc = xp.parse
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def nodes
17
+ @doc.find('/ruby_array/fixnum')
18
+ end
19
+
20
+ def test_doc_class
21
+ assert_instance_of(XML::Document, @doc)
22
+ end
23
+
24
+ def test_root_class
25
+ assert_instance_of(XML::Node, @doc.root)
26
+ end
27
+
28
+ def test_node_class
29
+ for n in nodes
30
+ assert_instance_of(XML::Node, n)
31
+ end
32
+ end
33
+
34
+ def test_find_class
35
+ set = @doc.find('/ruby_array/fixnum')
36
+ assert_instance_of(XML::XPath::Object, set)
37
+ end
38
+
39
+ def test_node_child_get
40
+ assert_instance_of(TrueClass, @doc.root.child?)
41
+ assert_instance_of(XML::Node, @doc.root.child)
42
+ assert_equal('fixnum', @doc.root.child.name)
43
+ end
44
+
45
+ def test_node_doc
46
+ for n in nodes
47
+ assert_instance_of(XML::Document, n.doc) if n.document?
48
+ end
49
+ end
50
+
51
+ def test_node_type_name
52
+ assert_equal('element', nodes[0].node_type_name)
53
+ assert_equal('element', nodes[1].node_type_name)
54
+ end
55
+
56
+ def test_node_find
57
+ set = @doc.root.find('./fixnum').set
58
+ assert_instance_of(XML::Node::Set, set)
59
+ for node in set
60
+ assert_instance_of(XML::Node, node)
61
+ end
62
+ end
63
+
64
+ def test_equality
65
+ node_a = @doc.find('/ruby_array/fixnum').first
66
+ node_b = @doc.root.child
67
+ assert(node_a == node_b)
68
+ assert(node_a.eql?(node_b))
69
+ assert(node_a.equal?(node_b))
70
+
71
+ xp2 = XML::Parser.new()
72
+ xp2.string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
73
+ doc2 = xp2.parse
74
+
75
+ node_a2 = doc2.find('/ruby_array/fixnum').first
76
+
77
+ assert(node_a.to_s == node_a2.to_s)
78
+ assert(node_a == node_a2)
79
+ assert(node_a.eql?(node_a2))
80
+ assert(!node_a.equal?(node_a2))
81
+ end
82
+
83
+ def test_equality_nil
84
+ node = @doc.root
85
+ assert(node != nil)
86
+ end
87
+
88
+ def test_equality_wrong_type
89
+ node = @doc.root
90
+
91
+ assert_raises(TypeError) do
92
+ assert(node != 'abc')
93
+ end
94
+ end
95
+
96
+ def test_content()
97
+ assert_equal('onetwo', @doc.root.content)
98
+
99
+ first = @doc.root.child
100
+ assert_equal('one', first.content)
101
+ assert_equal('two', first.next.content)
102
+ end
103
+
104
+ def test_base
105
+ doc = XML::Parser.string('<person />').parse
106
+ assert_nil(doc.root.base)
107
+ end
108
+ end