libxml-jruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/History.txt +4 -0
  2. data/README.txt +50 -0
  3. data/Rakefile +19 -0
  4. data/VERSION +1 -0
  5. data/VERSION.yml +5 -0
  6. data/lib/libxml-jruby.rb +84 -0
  7. data/lib/libxml-jruby/xml.rb +1 -0
  8. data/lib/libxml-jruby/xml/attr.rb +46 -0
  9. data/lib/libxml-jruby/xml/attributes.rb +68 -0
  10. data/lib/libxml-jruby/xml/document.rb +52 -0
  11. data/lib/libxml-jruby/xml/dtd.rb +25 -0
  12. data/lib/libxml-jruby/xml/node.rb +285 -0
  13. data/lib/libxml-jruby/xml/ns.rb +19 -0
  14. data/lib/libxml-jruby/xml/parser.rb +121 -0
  15. data/lib/libxml-jruby/xml/xpath.rb +98 -0
  16. data/lib/libxml.rb +1 -0
  17. data/lib/xml.rb +13 -0
  18. data/lib/xml/libxml.rb +8 -0
  19. data/test/etc_doc_to_s.rb +19 -0
  20. data/test/ets_copy_bug.rb +21 -0
  21. data/test/ets_copy_bug3.rb +38 -0
  22. data/test/ets_doc_file.rb +15 -0
  23. data/test/ets_doc_to_s.rb +21 -0
  24. data/test/ets_gpx.rb +26 -0
  25. data/test/ets_node_gc.rb +21 -0
  26. data/test/ets_tsr.rb +9 -0
  27. data/test/model/default_validation_bug.rb +0 -0
  28. data/test/tc_attributes.rb +110 -0
  29. data/test/tc_deprecated_require.rb +13 -0
  30. data/test/tc_document.rb +97 -0
  31. data/test/tc_document_write.rb +139 -0
  32. data/test/tc_dtd.rb +70 -0
  33. data/test/tc_html_parser.rb +63 -0
  34. data/test/tc_node.rb +108 -0
  35. data/test/tc_node_attr.rb +176 -0
  36. data/test/tc_node_cdata.rb +51 -0
  37. data/test/tc_node_comment.rb +32 -0
  38. data/test/tc_node_copy.rb +40 -0
  39. data/test/tc_node_edit.rb +98 -0
  40. data/test/tc_node_set.rb +24 -0
  41. data/test/tc_node_set2.rb +37 -0
  42. data/test/tc_node_text.rb +17 -0
  43. data/test/tc_node_xlink.rb +28 -0
  44. data/test/tc_ns.rb +18 -0
  45. data/test/tc_parser.rb +308 -0
  46. data/test/tc_parser_context.rb +126 -0
  47. data/test/tc_properties.rb +37 -0
  48. data/test/tc_reader.rb +112 -0
  49. data/test/tc_relaxng.rb +39 -0
  50. data/test/tc_sax_parser.rb +113 -0
  51. data/test/tc_schema.rb +39 -0
  52. data/test/tc_traversal.rb +220 -0
  53. data/test/tc_well_formed.rb +11 -0
  54. data/test/tc_xinclude.rb +26 -0
  55. data/test/tc_xpath.rb +130 -0
  56. data/test/tc_xpath_context.rb +72 -0
  57. data/test/tc_xpointer.rb +78 -0
  58. data/test/test_libxml-jruby.rb +0 -0
  59. data/test/test_suite.rb +31 -0
  60. data/test/ts_working.rb +31 -0
  61. metadata +121 -0
File without changes
@@ -0,0 +1,110 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class AttributesTest < Test::Unit::TestCase
5
+ def setup()
6
+ xp = XML::Parser.string(<<-EOS)
7
+ <CityModel
8
+ xmlns="http://www.opengis.net/examples"
9
+ xmlns:city="http://www.opengis.net/examples"
10
+ xmlns:gml="http://www.opengis.net/gml"
11
+ xmlns:xlink="http://www.w3.org/1999/xlink"
12
+ xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
13
+ xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
14
+ <cityMember name="Cambridge"
15
+ xlink:type="simple"
16
+ xlink:title="Trinity Lane"
17
+ xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
18
+ gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
19
+ </CityModel>
20
+ EOS
21
+
22
+ @doc = xp.parse
23
+ end
24
+
25
+ def teardown()
26
+ @doc = nil
27
+ end
28
+
29
+ def city_member
30
+ @doc.find('/city:CityModel/city:cityMember').first
31
+ end
32
+
33
+ def test_attributes
34
+ attributes = city_member.attributes
35
+ assert_instance_of(XML::Attributes, attributes)
36
+ assert_equal(5, attributes.length)
37
+ end
38
+
39
+ def test_each
40
+ attributes = city_member.attributes
41
+ length = attributes.inject(0) do |result, attr|
42
+ assert_instance_of(XML::Attr, attr)
43
+ result + 1
44
+ end
45
+ assert_equal(5, length)
46
+ end
47
+
48
+ def test_get_attribute
49
+ attributes = city_member.attributes
50
+
51
+ attr = attributes.get_attribute('name')
52
+ assert_instance_of(XML::Attr, attr)
53
+
54
+ attr = attributes.get_attribute('does_not_exist')
55
+ assert_nil(attr)
56
+
57
+ attr = attributes.get_attribute('name')
58
+ assert_instance_of(XML::Attr, attr)
59
+
60
+ # FIXME Namespaced attribute, without namespace specified
61
+ # attr = attributes.get_attribute('href')
62
+ # assert_instance_of(XML::Attr, attr)
63
+ # assert_instance_of(XML::NS, attr.ns)
64
+ # assert_equal('xlink', attr.ns.prefix)
65
+ # assert_equal('http://www.w3.org/1999/xlink', attr.ns.href)
66
+
67
+ # FIXME this should be working, wtf happened
68
+ # attr = attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
69
+ # assert_instance_of(XML::Attr, attr)
70
+ #
71
+ # attr = attributes.get_attribute_ns('http://www.opengis.net/gml', 'remoteSchema')
72
+ # assert_instance_of(XML::Attr, attr)
73
+ #
74
+ # attr = attributes.get_attribute_ns('http://i.dont.exist', 'nor do i')
75
+ # assert_nil(attr)
76
+ end
77
+
78
+ def test_get_values
79
+ assert_equal('Cambridge', city_member[:name])
80
+ # FIXME Namespaced attribute, without namespace specified
81
+ # assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', city_member[:href])
82
+
83
+ attributes = city_member.attributes
84
+ assert_equal('Cambridge', attributes[:name])
85
+ # FIXME Namespaced attribute, without namespace specified
86
+ # assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attributes[:href])
87
+ end
88
+
89
+ def test_set_values
90
+ city_member[:name] = 'London'
91
+ assert_equal('London', city_member[:name])
92
+
93
+ city_member[:href] = 'foo'
94
+ assert_equal('foo', city_member[:href])
95
+
96
+ attributes = city_member.attributes
97
+
98
+ attributes[:name] = 'London'
99
+ assert_equal('London', attributes[:name])
100
+
101
+ attributes[:href] = 'foo'
102
+ assert_equal('foo', attributes[:href])
103
+ end
104
+
105
+ def test_str_sym()
106
+ attributes = city_member.attributes
107
+ assert_equal('Cambridge', attributes[:name])
108
+ assert_equal('Cambridge', attributes['name'])
109
+ end
110
+ end
@@ -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