libxml-jruby-modified 1.0.1-jruby

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 (95) hide show
  1. checksums.yaml +7 -0
  2. data/History.txt +4 -0
  3. data/Manifest.txt +91 -0
  4. data/README.txt +50 -0
  5. data/Rakefile +20 -0
  6. data/lib/libxml-jruby/xml/attr.rb +46 -0
  7. data/lib/libxml-jruby/xml/attributes.rb +68 -0
  8. data/lib/libxml-jruby/xml/document.rb +48 -0
  9. data/lib/libxml-jruby/xml/dtd.rb +25 -0
  10. data/lib/libxml-jruby/xml/node.rb +285 -0
  11. data/lib/libxml-jruby/xml/ns.rb +19 -0
  12. data/lib/libxml-jruby/xml/parser.rb +121 -0
  13. data/lib/libxml-jruby/xml/xpath.rb +98 -0
  14. data/lib/libxml-jruby/xml.rb +1 -0
  15. data/lib/libxml-jruby.rb +82 -0
  16. data/lib/libxml.rb +1 -0
  17. data/lib/xml/libxml.rb +8 -0
  18. data/lib/xml.rb +13 -0
  19. data/libxml-jruby-1.0.1-java.gem +0 -0
  20. data/libxml-jruby.gemspec +15 -0
  21. data/script/benchmark/depixelate.rb +633 -0
  22. data/script/benchmark/hamlet.xml +9055 -0
  23. data/script/benchmark/sock_entries.xml +507 -0
  24. data/script/benchmark/throughput.rb +40 -0
  25. data/script/benchmark/xml_benchmarks.rb +228 -0
  26. data/script/test +6 -0
  27. data/tasks/ann.rake +81 -0
  28. data/tasks/bones.rake +21 -0
  29. data/tasks/gem.rake +126 -0
  30. data/tasks/git.rake +41 -0
  31. data/tasks/manifest.rake +49 -0
  32. data/tasks/notes.rake +28 -0
  33. data/tasks/post_load.rake +39 -0
  34. data/tasks/rdoc.rake +51 -0
  35. data/tasks/rubyforge.rake +57 -0
  36. data/tasks/setup.rb +268 -0
  37. data/tasks/spec.rake +55 -0
  38. data/tasks/svn.rake +48 -0
  39. data/tasks/test.rake +38 -0
  40. data/test/etc_doc_to_s.rb +19 -0
  41. data/test/ets_copy_bug.rb +21 -0
  42. data/test/ets_copy_bug3.rb +38 -0
  43. data/test/ets_doc_file.rb +15 -0
  44. data/test/ets_doc_to_s.rb +21 -0
  45. data/test/ets_gpx.rb +26 -0
  46. data/test/ets_node_gc.rb +21 -0
  47. data/test/ets_test.xml +2 -0
  48. data/test/ets_tsr.rb +9 -0
  49. data/test/model/books.xml +147 -0
  50. data/test/model/default_validation_bug.rb +0 -0
  51. data/test/model/merge_bug_data.xml +58 -0
  52. data/test/model/rubynet.xml +78 -0
  53. data/test/model/rubynet_project +1 -0
  54. data/test/model/saxtest.xml +5 -0
  55. data/test/model/shiporder.rnc +28 -0
  56. data/test/model/shiporder.rng +86 -0
  57. data/test/model/shiporder.xml +23 -0
  58. data/test/model/shiporder.xsd +31 -0
  59. data/test/model/simple.xml +7 -0
  60. data/test/model/soap.xml +27 -0
  61. data/test/model/xinclude.xml +5 -0
  62. data/test/tc_attributes.rb +110 -0
  63. data/test/tc_deprecated_require.rb +13 -0
  64. data/test/tc_document.rb +97 -0
  65. data/test/tc_document_write.rb +139 -0
  66. data/test/tc_dtd.rb +70 -0
  67. data/test/tc_html_parser.rb +63 -0
  68. data/test/tc_node.rb +108 -0
  69. data/test/tc_node_attr.rb +176 -0
  70. data/test/tc_node_cdata.rb +51 -0
  71. data/test/tc_node_comment.rb +32 -0
  72. data/test/tc_node_copy.rb +40 -0
  73. data/test/tc_node_edit.rb +98 -0
  74. data/test/tc_node_set.rb +24 -0
  75. data/test/tc_node_set2.rb +37 -0
  76. data/test/tc_node_text.rb +17 -0
  77. data/test/tc_node_xlink.rb +28 -0
  78. data/test/tc_ns.rb +18 -0
  79. data/test/tc_parser.rb +308 -0
  80. data/test/tc_parser_context.rb +126 -0
  81. data/test/tc_properties.rb +37 -0
  82. data/test/tc_reader.rb +112 -0
  83. data/test/tc_relaxng.rb +39 -0
  84. data/test/tc_sax_parser.rb +113 -0
  85. data/test/tc_schema.rb +39 -0
  86. data/test/tc_traversal.rb +220 -0
  87. data/test/tc_well_formed.rb +11 -0
  88. data/test/tc_xinclude.rb +26 -0
  89. data/test/tc_xpath.rb +130 -0
  90. data/test/tc_xpath_context.rb +72 -0
  91. data/test/tc_xpointer.rb +78 -0
  92. data/test/test_libxml-jruby.rb +0 -0
  93. data/test/test_suite.rb +31 -0
  94. data/test/ts_working.rb +31 -0
  95. metadata +135 -0
@@ -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
data/test/tc_dtd.rb ADDED
@@ -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
data/test/tc_node.rb ADDED
@@ -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
@@ -0,0 +1,176 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class AttrNodeTest < 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
+ <type>City</type>
15
+ <cityMember name="Cambridge"
16
+ xlink:type="simple"
17
+ xlink:title="Trinity Lane"
18
+ xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
19
+ gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
20
+ </CityModel>
21
+ EOS
22
+
23
+ @doc = xp.parse
24
+ end
25
+
26
+ def teardown()
27
+ @doc = nil
28
+ end
29
+
30
+ def city_member
31
+ @doc.find('/city:CityModel/city:cityMember').first
32
+ end
33
+
34
+ def test_types
35
+ attribute = city_member.attributes.get_attribute('name')
36
+ assert_instance_of(XML::Attr, attribute)
37
+ assert_equal('attribute', attribute.node_type_name)
38
+ end
39
+
40
+ def test_name
41
+ attribute = city_member.attributes.get_attribute('name')
42
+ assert_equal('name', attribute.name)
43
+
44
+ # FIXME Namespaced attribute, without namespace specified
45
+ # attribute = city_member.attributes.get_attribute('href')
46
+ # assert_equal('href', attribute.name)
47
+ # assert_equal('xlink', attribute.ns.prefix)
48
+ # assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
49
+
50
+ # FIXME This should be working, review ASAP
51
+ # attribute = city_member.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
52
+ # assert_equal('href', attribute.name)
53
+ # assert_equal('xlink', attribute.ns.prefix)
54
+ # assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
55
+ end
56
+
57
+ def test_value
58
+ attribute = city_member.attributes.get_attribute('name')
59
+ assert_equal('Cambridge', attribute.value)
60
+
61
+ # FIXME Namespaced attribute, without namespace specified
62
+ # attribute = city_member.attributes.get_attribute('href')
63
+ # assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
64
+ end
65
+
66
+ def test_set_value
67
+ attribute = city_member.attributes.get_attribute('name')
68
+ attribute.value = 'London'
69
+ assert_equal('London', attribute.value)
70
+
71
+ # FIXME Namespaced attribute, without namespace specified
72
+ # attribute = city_member.attributes.get_attribute('href')
73
+ # attribute.value = 'http://i.have.changed'
74
+ # assert_equal('http://i.have.changed', attribute.value)
75
+ end
76
+
77
+ def test_set_nil
78
+ attribute = city_member.attributes.get_attribute('name')
79
+ assert_raise(TypeError) do
80
+ attribute.value = nil
81
+ end
82
+ end
83
+
84
+ def test_create
85
+ attributes = city_member.attributes
86
+ assert_equal(5, attributes.length)
87
+
88
+ attr = XML::Attr.new(city_member, 'size', '50,000')
89
+ assert_instance_of(XML::Attr, attr)
90
+
91
+ attributes = city_member.attributes
92
+ assert_equal(6, attributes.length)
93
+
94
+ assert_equal(attributes['size'], '50,000')
95
+ end
96
+
97
+ def test_create_on_node
98
+ attributes = city_member.attributes
99
+ assert_equal(5, attributes.length)
100
+
101
+ attributes['country'] = 'England'
102
+
103
+ attributes = city_member.attributes
104
+ assert_equal(6, attributes.length)
105
+
106
+ assert_equal(attributes['country'], 'England')
107
+ end
108
+
109
+ def test_create_ns
110
+ assert_equal(5, city_member.attributes.length)
111
+
112
+ ns = XML::NS.new(city_member, 'my_namepace', 'http://www.mynamespace.com')
113
+ attr = XML::Attr.new(city_member, 'rating', 'rocks', ns)
114
+ assert_instance_of(XML::Attr, attr)
115
+ # FIXME I'm not sure what is going on here, look at Attr#initialize
116
+ # assert_equal('rating', attr.name)
117
+ # assert_equal('rocks', attr.value)
118
+
119
+ attributes = city_member.attributes
120
+ assert_equal(6, attributes.length)
121
+
122
+ assert_equal('rocks', city_member['rating'])
123
+ end
124
+
125
+ def test_remove
126
+ attributes = city_member.attributes
127
+ assert_equal(5, attributes.length)
128
+
129
+ attribute = attributes.get_attribute('name')
130
+ assert_not_nil(attribute.parent)
131
+ assert(attribute.parent?)
132
+
133
+ attribute.remove!
134
+ assert_equal(4, attributes.length)
135
+ assert_nil(attribute.parent)
136
+ assert(!attribute.parent?)
137
+ end
138
+
139
+ # FIXME Ordering of Attributes is not implemented yet
140
+ # def test_first
141
+ # attribute = city_member.attributes.first
142
+ # assert_instance_of(XML::Attr, attribute)
143
+ # assert_equal('name', attribute.name)
144
+ # assert_equal('Cambridge', attribute.value)
145
+ #
146
+ # attribute = attribute.next
147
+ # assert_instance_of(XML::Attr, attribute)
148
+ # assert_equal('type', attribute.name)
149
+ # assert_equal('simple', attribute.value)
150
+ #
151
+ # attribute = attribute.next
152
+ # assert_instance_of(XML::Attr, attribute)
153
+ # assert_equal('title', attribute.name)
154
+ # assert_equal('Trinity Lane', attribute.value)
155
+ #
156
+ # attribute = attribute.next
157
+ # assert_instance_of(XML::Attr, attribute)
158
+ # assert_equal('href', attribute.name)
159
+ # assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
160
+ #
161
+ # attribute = attribute.next
162
+ # assert_instance_of(XML::Attr, attribute)
163
+ # assert_equal('remoteSchema', attribute.name)
164
+ # assert_equal("city.xsd#xpointer(//complexType[@name='RoadType'])", attribute.value)
165
+ #
166
+ # attribute = attribute.next
167
+ # assert_nil(attribute)
168
+ # end
169
+
170
+ def test_no_attributes
171
+ element = @doc.find('/city:CityModel/city:type').first
172
+
173
+ assert_not_nil(element.attributes)
174
+ assert_equal(0, element.attributes.length)
175
+ end
176
+ end
@@ -0,0 +1,51 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class CDataCommentTest < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.new()
7
+ str = '<root></root>'
8
+ assert_equal(str, xp.string = str)
9
+ @doc = xp.parse
10
+ assert_instance_of(XML::Document, @doc)
11
+ @root = @doc.root
12
+ end
13
+
14
+ def test_node_type
15
+ cnode = XML::Node.new_cdata('test cdata')
16
+ assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type)
17
+ end
18
+
19
+ def test_add_cdata
20
+ @root << XML::Node.new_cdata('mycdata')
21
+ assert_equal '<root><![CDATA[mycdata]]></root>',
22
+ @root.to_s.gsub(/\n\s*/,'')
23
+ end
24
+
25
+ def test_add_cdata_2
26
+ @root << XML::Node.new_cdata('mycdata')
27
+ assert_equal 'cdata',
28
+ @root.child.node_type_name
29
+ end
30
+
31
+ def test_add_cdata_3
32
+ @root << el = XML::Node.new_cdata('mycdata')
33
+ el << "_this_is_added"
34
+ assert_equal '<root><![CDATA[mycdata_this_is_added]]></root>',
35
+ @root.to_s.gsub(/\n\s*/,'')
36
+ end
37
+
38
+ def test_attributes
39
+ cnode = XML::Node.new_cdata('test cdata')
40
+ assert_equal(0, cnode.attributes.length)
41
+ end
42
+
43
+ def test_set_cdata_attribute
44
+ cnode = XML::Node.new_cdata('test cdata')
45
+
46
+ # Can't create attributes on non-element nodes
47
+ assert_raise(ArgumentError) do
48
+ cnode['attr'] = '123'
49
+ end
50
+ end
51
+ end