libxml-ruby 1.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/{CHANGES → HISTORY} +35 -0
  2. data/LICENSE +1 -0
  3. data/MANIFEST +165 -0
  4. data/{README → README.rdoc} +2 -2
  5. data/Rakefile +47 -147
  6. data/ext/libxml/libxml.c +17 -1
  7. data/ext/libxml/ruby_libxml.h +9 -1
  8. data/ext/libxml/ruby_xml_attr.c +3 -3
  9. data/ext/libxml/ruby_xml_attr_decl.c +32 -32
  10. data/ext/libxml/ruby_xml_attributes.c +1 -1
  11. data/ext/libxml/ruby_xml_cbg.c +1 -2
  12. data/ext/libxml/ruby_xml_document.c +26 -4
  13. data/ext/libxml/ruby_xml_dtd.c +3 -3
  14. data/ext/libxml/ruby_xml_encoding.c +92 -5
  15. data/ext/libxml/ruby_xml_encoding.h +4 -0
  16. data/ext/libxml/ruby_xml_namespace.c +2 -2
  17. data/ext/libxml/ruby_xml_node.c +14 -14
  18. data/ext/libxml/ruby_xml_parser_context.c +8 -8
  19. data/ext/libxml/ruby_xml_reader.c +98 -43
  20. data/ext/libxml/ruby_xml_sax2_handler.c +13 -1
  21. data/ext/libxml/ruby_xml_sax_parser.c +4 -5
  22. data/ext/libxml/ruby_xml_version.h +5 -5
  23. data/ext/libxml/ruby_xml_xpath_context.c +9 -6
  24. data/ext/libxml/ruby_xml_xpath_object.c +1 -1
  25. data/ext/vc/libxml_ruby.sln +4 -4
  26. data/lib/libxml.rb +29 -29
  27. data/lib/libxml/attr.rb +112 -110
  28. data/lib/libxml/attr_decl.rb +2 -0
  29. data/lib/libxml/attributes.rb +13 -11
  30. data/lib/libxml/document.rb +192 -190
  31. data/lib/libxml/error.rb +89 -87
  32. data/lib/libxml/hpricot.rb +77 -75
  33. data/lib/libxml/html_parser.rb +96 -94
  34. data/lib/libxml/namespace.rb +61 -59
  35. data/lib/libxml/namespaces.rb +37 -35
  36. data/lib/libxml/node.rb +398 -384
  37. data/lib/libxml/ns.rb +21 -19
  38. data/lib/libxml/parser.rb +366 -364
  39. data/lib/libxml/properties.rb +22 -20
  40. data/lib/libxml/reader.rb +2 -0
  41. data/lib/libxml/sax_callbacks.rb +179 -177
  42. data/lib/libxml/sax_parser.rb +57 -55
  43. data/lib/libxml/tree.rb +28 -26
  44. data/lib/libxml/xpath_object.rb +15 -13
  45. data/lib/xml.rb +16 -14
  46. data/lib/xml/libxml.rb +10 -8
  47. data/libxml-ruby.gemspec +50 -0
  48. data/script/benchmark/depixelate +634 -0
  49. data/script/benchmark/hamlet.xml +9055 -0
  50. data/script/benchmark/parsecount +170 -0
  51. data/script/benchmark/sock_entries.xml +507 -0
  52. data/script/benchmark/throughput +41 -0
  53. data/script/test +6 -0
  54. data/test/etc_doc_to_s.rb +21 -19
  55. data/test/ets_doc_file.rb +17 -15
  56. data/test/ets_doc_to_s.rb +23 -21
  57. data/test/ets_gpx.rb +28 -26
  58. data/test/ets_node_gc.rb +23 -21
  59. data/test/ets_tsr.rb +11 -9
  60. data/test/model/bands.iso-8859-1.xml +5 -0
  61. data/test/model/bands.utf-8.xml +5 -0
  62. data/test/rb-magic-comment.rb +33 -0
  63. data/test/tc_attr.rb +181 -170
  64. data/test/tc_attr_decl.rb +3 -1
  65. data/test/tc_attributes.rb +134 -132
  66. data/test/tc_deprecated_require.rb +13 -11
  67. data/test/tc_document.rb +119 -113
  68. data/test/tc_document_write.rb +186 -117
  69. data/test/tc_dtd.rb +125 -123
  70. data/test/tc_error.rb +3 -1
  71. data/test/tc_html_parser.rb +139 -137
  72. data/test/tc_namespace.rb +61 -58
  73. data/test/tc_namespaces.rb +176 -173
  74. data/test/tc_node.rb +257 -180
  75. data/test/tc_node_cdata.rb +51 -49
  76. data/test/tc_node_comment.rb +33 -30
  77. data/test/tc_node_copy.rb +42 -40
  78. data/test/tc_node_edit.rb +159 -157
  79. data/test/tc_node_text.rb +71 -69
  80. data/test/tc_node_write.rb +41 -16
  81. data/test/tc_node_xlink.rb +29 -26
  82. data/test/tc_parser.rb +335 -329
  83. data/test/tc_parser_context.rb +188 -185
  84. data/test/tc_properties.rb +39 -36
  85. data/test/tc_reader.rb +297 -283
  86. data/test/tc_relaxng.rb +54 -51
  87. data/test/tc_sax_parser.rb +275 -273
  88. data/test/tc_schema.rb +53 -51
  89. data/test/tc_traversal.rb +222 -220
  90. data/test/tc_xinclude.rb +21 -19
  91. data/test/tc_xml.rb +3 -1
  92. data/test/tc_xpath.rb +195 -193
  93. data/test/tc_xpath_context.rb +80 -78
  94. data/test/tc_xpath_expression.rb +38 -35
  95. data/test/tc_xpointer.rb +74 -72
  96. data/test/test_helper.rb +14 -0
  97. data/test/test_suite.rb +39 -33
  98. metadata +65 -105
  99. data/doc/css/normal.css +0 -182
  100. data/doc/img/raze-tiny.png +0 -0
  101. data/doc/img/red-cube.jpg +0 -0
  102. data/doc/img/xml-ruby.png +0 -0
  103. data/doc/index.xml +0 -43
  104. data/doc/install.xml +0 -77
  105. data/doc/layout.rhtml +0 -38
  106. data/doc/layout.xsl +0 -67
  107. data/doc/license.xml +0 -32
  108. data/doc/log/changelog.xml +0 -1324
  109. data/doc/log/changelog.xsl +0 -42
  110. data/ext/libxml/Makefile +0 -156
  111. data/ext/libxml/extconf.h +0 -5
  112. data/ext/libxml/libxml-ruby.so.a +0 -0
  113. data/ext/libxml/libxml.o +0 -0
  114. data/ext/libxml/libxml_ruby.so +0 -0
  115. data/ext/libxml/mkmf.log +0 -129
  116. data/ext/libxml/ruby_xml.o +0 -0
  117. data/ext/libxml/ruby_xml_attr.o +0 -0
  118. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  119. data/ext/libxml/ruby_xml_attributes.o +0 -0
  120. data/ext/libxml/ruby_xml_cbg.o +0 -0
  121. data/ext/libxml/ruby_xml_document.o +0 -0
  122. data/ext/libxml/ruby_xml_dtd.o +0 -0
  123. data/ext/libxml/ruby_xml_encoding.o +0 -0
  124. data/ext/libxml/ruby_xml_error.o +0 -0
  125. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  126. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  127. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  128. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  129. data/ext/libxml/ruby_xml_io.o +0 -0
  130. data/ext/libxml/ruby_xml_namespace.o +0 -0
  131. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  132. data/ext/libxml/ruby_xml_node.o +0 -0
  133. data/ext/libxml/ruby_xml_parser.o +0 -0
  134. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  135. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  136. data/ext/libxml/ruby_xml_reader.o +0 -0
  137. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  138. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  139. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  140. data/ext/libxml/ruby_xml_schema.o +0 -0
  141. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  142. data/ext/libxml/ruby_xml_xpath.o +0 -0
  143. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  144. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  145. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  146. data/ext/libxml/ruby_xml_xpointer.o +0 -0
data/test/tc_attr_decl.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'xml'
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
2
4
  require 'test/unit'
3
5
 
4
6
  class AttrDeclTest < Test::Unit::TestCase
@@ -1,133 +1,135 @@
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
- attr = attributes.get_attribute('href')
61
- assert_instance_of(XML::Attr, attr)
62
- assert_instance_of(XML::Namespace, attr.ns)
63
- assert_equal('xlink', attr.ns.prefix)
64
- assert_equal('http://www.w3.org/1999/xlink', attr.ns.href)
65
-
66
- attr = attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
67
- assert_instance_of(XML::Attr, attr)
68
-
69
- attr = attributes.get_attribute_ns('http://www.opengis.net/gml', 'remoteSchema')
70
- assert_instance_of(XML::Attr, attr)
71
-
72
- attr = attributes.get_attribute_ns('http://i.dont.exist', 'nor do i')
73
- assert_nil(attr)
74
- end
75
-
76
- def test_property
77
- attr = city_member.property('name')
78
- assert_instance_of(String, attr)
79
- assert_equal('Cambridge', attr)
80
- end
81
-
82
- def test_get_values
83
- assert_equal('Cambridge', city_member[:name])
84
- assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', city_member[:href])
85
-
86
- attributes = city_member.attributes
87
- assert_equal('Cambridge', attributes[:name])
88
- assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attributes[:href])
89
- end
90
-
91
- def test_set_values
92
- city_member[:name] = 'London'
93
- assert_equal('London', city_member[:name])
94
-
95
- city_member[:href] = 'foo'
96
- assert_equal('foo', city_member[:href])
97
-
98
- attributes = city_member.attributes
99
-
100
- attributes[:name] = 'London'
101
- assert_equal('London', attributes[:name])
102
-
103
- attributes[:href] = 'foo'
104
- assert_equal('foo', attributes[:href])
105
- end
106
-
107
- def test_str_sym()
108
- attributes = city_member.attributes
109
- assert_equal('Cambridge', attributes[:name])
110
- assert_equal('Cambridge', attributes['name'])
111
- end
112
-
113
- def test_remove_first
114
- attributes = @doc.find_first('/city:CityModel/city:cityMember').attributes
115
- assert_equal(5, attributes.length)
116
- attr = attributes.first
117
- attr.remove!
118
- assert_equal(4, attributes.length)
119
- end
120
-
121
- def test_remove_all
122
- node = @doc.find_first('/city:CityModel/city:cityMember')
123
- assert_equal(5, node.attributes.length)
124
-
125
- attrs = Array.new
126
- node.attributes.each do |attr|
127
- attrs << attr
128
- attr.remove!
129
- end
130
- assert_equal(5, attrs.length)
131
- assert_equal(0, node.attributes.length)
132
- end
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class AttributesTest < Test::Unit::TestCase
7
+ def setup
8
+ xp = XML::Parser.string(<<-EOS)
9
+ <CityModel
10
+ xmlns="http://www.opengis.net/examples"
11
+ xmlns:city="http://www.opengis.net/examples"
12
+ xmlns:gml="http://www.opengis.net/gml"
13
+ xmlns:xlink="http://www.w3.org/1999/xlink"
14
+ xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
15
+ xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
16
+ <cityMember name="Cambridge"
17
+ xlink:type="simple"
18
+ xlink:title="Trinity Lane"
19
+ xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
20
+ gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
21
+ </CityModel>
22
+ EOS
23
+
24
+ @doc = xp.parse
25
+ end
26
+
27
+ def teardown
28
+ @doc = nil
29
+ end
30
+
31
+ def city_member
32
+ @doc.find('/city:CityModel/city:cityMember').first
33
+ end
34
+
35
+ def test_attributes
36
+ attributes = city_member.attributes
37
+ assert_instance_of(XML::Attributes, attributes)
38
+ assert_equal(5, attributes.length)
39
+ end
40
+
41
+ def test_each
42
+ attributes = city_member.attributes
43
+ length = attributes.inject(0) do |result, attr|
44
+ assert_instance_of(XML::Attr, attr)
45
+ result + 1
46
+ end
47
+ assert_equal(5, length)
48
+ end
49
+
50
+ def test_get_attribute
51
+ attributes = city_member.attributes
52
+
53
+ attr = attributes.get_attribute('name')
54
+ assert_instance_of(XML::Attr, attr)
55
+
56
+ attr = attributes.get_attribute('does_not_exist')
57
+ assert_nil(attr)
58
+
59
+ attr = attributes.get_attribute('name')
60
+ assert_instance_of(XML::Attr, attr)
61
+
62
+ attr = attributes.get_attribute('href')
63
+ assert_instance_of(XML::Attr, attr)
64
+ assert_instance_of(XML::Namespace, attr.ns)
65
+ assert_equal('xlink', attr.ns.prefix)
66
+ assert_equal('http://www.w3.org/1999/xlink', attr.ns.href)
67
+
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_property
79
+ attr = city_member.property('name')
80
+ assert_instance_of(String, attr)
81
+ assert_equal('Cambridge', attr)
82
+ end
83
+
84
+ def test_get_values
85
+ assert_equal('Cambridge', city_member[:name])
86
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', city_member[:href])
87
+
88
+ attributes = city_member.attributes
89
+ assert_equal('Cambridge', attributes[:name])
90
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attributes[:href])
91
+ end
92
+
93
+ def test_set_values
94
+ city_member[:name] = 'London'
95
+ assert_equal('London', city_member[:name])
96
+
97
+ city_member[:href] = 'foo'
98
+ assert_equal('foo', city_member[:href])
99
+
100
+ attributes = city_member.attributes
101
+
102
+ attributes[:name] = 'London'
103
+ assert_equal('London', attributes[:name])
104
+
105
+ attributes[:href] = 'foo'
106
+ assert_equal('foo', attributes[:href])
107
+ end
108
+
109
+ def test_str_sym()
110
+ attributes = city_member.attributes
111
+ assert_equal('Cambridge', attributes[:name])
112
+ assert_equal('Cambridge', attributes['name'])
113
+ end
114
+
115
+ def test_remove_first
116
+ attributes = @doc.find_first('/city:CityModel/city:cityMember').attributes
117
+ assert_equal(5, attributes.length)
118
+ attr = attributes.first
119
+ attr.remove!
120
+ assert_equal(4, attributes.length)
121
+ end
122
+
123
+ def test_remove_all
124
+ node = @doc.find_first('/city:CityModel/city:cityMember')
125
+ assert_equal(5, node.attributes.length)
126
+
127
+ attrs = Array.new
128
+ node.attributes.each do |attr|
129
+ attrs << attr
130
+ attr.remove!
131
+ end
132
+ assert_equal(5, attrs.length)
133
+ assert_equal(0, node.attributes.length)
134
+ end
133
135
  end
@@ -1,11 +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.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
7
- assert_instance_of(XML::Parser, xp)
8
- @doc = xp.parse
9
- assert_instance_of(XML::Document, @doc)
10
- end
11
- end
1
+ # encoding: UTF-8
2
+
3
+ require 'xml/libxml'
4
+ require 'test/unit'
5
+
6
+ class TestDeprecatedRequire < Test::Unit::TestCase
7
+ def test_basic
8
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
9
+ assert_instance_of(XML::Parser, xp)
10
+ @doc = xp.parse
11
+ assert_instance_of(XML::Document, @doc)
12
+ end
13
+ end
data/test/tc_document.rb CHANGED
@@ -1,113 +1,119 @@
1
- require "xml"
2
- require 'test/unit'
3
-
4
-
5
- class TestDocument < Test::Unit::TestCase
6
- def setup
7
- xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
8
- assert_instance_of(XML::Parser, xp)
9
- @doc = xp.parse
10
- assert_instance_of(XML::Document, @doc)
11
- end
12
-
13
- def teardown
14
- @doc = nil
15
- end
16
-
17
- def test_klass
18
- assert_instance_of(XML::Document, @doc)
19
- end
20
-
21
- def test_context
22
- context = @doc.context
23
- assert_instance_of(XML::XPath::Context, context)
24
- end
25
-
26
- def test_find
27
- set = @doc.find('/ruby_array/fixnum')
28
- assert_instance_of(XML::XPath::Object, set)
29
- assert_raise(NoMethodError) {
30
- xpt = set.xpath
31
- }
32
- end
33
-
34
- def test_compression
35
- if XML.enabled_zlib?
36
- 0.upto(9) do |i|
37
- assert_equal(i, @doc.compression = i)
38
- assert_equal(i, @doc.compression)
39
- end
40
-
41
- 9.downto(0) do |i|
42
- assert_equal(i, @doc.compression = i)
43
- assert_equal(i, @doc.compression)
44
- end
45
-
46
- 10.upto(20) do |i|
47
- # assert_equal(9, @doc.compression = i)
48
- assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
49
- assert_equal(9, @doc.compression)
50
- end
51
-
52
- -1.downto(-10) do |i|
53
- # assert_equal(0, @doc.compression = i)
54
- assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
55
- assert_equal(0, @doc.compression)
56
- end
57
- end
58
- end
59
-
60
- def test_version
61
- assert_equal('1.0', @doc.version)
62
-
63
- doc = XML::Document.new('6.9')
64
- assert_equal('6.9', doc.version)
65
- end
66
-
67
- def test_write_root
68
- @doc.root = XML::Node.new('rubynet')
69
- assert_instance_of(XML::Node, @doc.root)
70
- assert_instance_of(XML::Document, @doc.root.doc)
71
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
72
- @doc.to_s(:indent => false))
73
- end
74
-
75
- def test_encoding
76
- doc = XML::Document.new
77
- assert_equal(XML::Encoding::NONE, doc.encoding)
78
-
79
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
80
- doc = XML::Document.file(file)
81
- assert_equal(XML::Encoding::UTF_8, doc.encoding)
82
-
83
- doc.encoding = XML::Encoding::ISO_8859_1
84
- assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
85
- end
86
-
87
- def test_doc_node_type
88
- assert_equal XML::Node::DOCUMENT_NODE, XML::Document.new.node_type
89
- end
90
-
91
- def test_doc_node_type_name
92
- assert_equal 'document_xml', XML::Document.new.node_type_name
93
- end
94
-
95
- def test_xhtml
96
- doc = XML::Document.new
97
- assert ! doc.xhtml?
98
- xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
99
- assert doc.xhtml?
100
- end
101
-
102
- def test_import_node
103
- doc1 = XML::Parser.string('<nums><one></one></nums>').parse
104
- doc2 = XML::Parser.string('<nums><two></two></nums>').parse
105
-
106
- node = doc1.root.child
107
-
108
- doc2.root << doc2.import(node)
109
-
110
- assert_equal("<nums>\n <two/>\n <one/>\n</nums>",
111
- doc2.root.to_s)
112
- end
113
- end
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+
8
+ class TestDocument < Test::Unit::TestCase
9
+ def setup
10
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
11
+ assert_instance_of(XML::Parser, xp)
12
+ @doc = xp.parse
13
+ assert_instance_of(XML::Document, @doc)
14
+ end
15
+
16
+ def teardown
17
+ @doc = nil
18
+ end
19
+
20
+ def test_klass
21
+ assert_instance_of(XML::Document, @doc)
22
+ end
23
+
24
+ def test_context
25
+ context = @doc.context
26
+ assert_instance_of(XML::XPath::Context, context)
27
+ end
28
+
29
+ def test_find
30
+ set = @doc.find('/ruby_array/fixnum')
31
+ assert_instance_of(XML::XPath::Object, set)
32
+ assert_raise(NoMethodError) {
33
+ xpt = set.xpath
34
+ }
35
+ end
36
+
37
+ def test_compression
38
+ if XML.enabled_zlib?
39
+ 0.upto(9) do |i|
40
+ assert_equal(i, @doc.compression = i)
41
+ assert_equal(i, @doc.compression)
42
+ end
43
+
44
+ 9.downto(0) do |i|
45
+ assert_equal(i, @doc.compression = i)
46
+ assert_equal(i, @doc.compression)
47
+ end
48
+
49
+ 10.upto(20) do |i|
50
+ # assert_equal(9, @doc.compression = i)
51
+ assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
52
+ assert_equal(9, @doc.compression)
53
+ end
54
+
55
+ -1.downto(-10) do |i|
56
+ # assert_equal(0, @doc.compression = i)
57
+ assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
58
+ assert_equal(0, @doc.compression)
59
+ end
60
+ end
61
+ end
62
+
63
+ def test_version
64
+ assert_equal('1.0', @doc.version)
65
+
66
+ doc = XML::Document.new('6.9')
67
+ assert_equal('6.9', doc.version)
68
+ end
69
+
70
+ def test_write_root
71
+ @doc.root = XML::Node.new('rubynet')
72
+ assert_instance_of(XML::Node, @doc.root)
73
+ assert_instance_of(XML::Document, @doc.root.doc)
74
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
75
+ @doc.to_s(:indent => false))
76
+ end
77
+
78
+ def test_encoding
79
+ doc = XML::Document.new
80
+ assert_equal(XML::Encoding::NONE, doc.encoding)
81
+ assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) if defined?(Encoding)
82
+
83
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
84
+ doc = XML::Document.file(file)
85
+ assert_equal(XML::Encoding::UTF_8, doc.encoding)
86
+ assert_equal(Encoding::UTF_8, doc.rb_encoding) if defined?(Encoding)
87
+
88
+ doc.encoding = XML::Encoding::ISO_8859_1
89
+ assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
90
+ assert_equal(Encoding::ISO8859_1, doc.rb_encoding) if defined?(Encoding)
91
+ end
92
+
93
+ def test_doc_node_type
94
+ assert_equal(XML::Node::DOCUMENT_NODE, XML::Document.new.node_type)
95
+ end
96
+
97
+ def test_doc_node_type_name
98
+ assert_equal('document_xml', XML::Document.new.node_type_name)
99
+ end
100
+
101
+ def test_xhtml
102
+ doc = XML::Document.new
103
+ assert(!doc.xhtml?)
104
+ XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
105
+ assert(doc.xhtml?)
106
+ end
107
+
108
+ def test_import_node
109
+ doc1 = XML::Parser.string('<nums><one></one></nums>').parse
110
+ doc2 = XML::Parser.string('<nums><two></two></nums>').parse
111
+
112
+ node = doc1.root.child
113
+
114
+ doc2.root << doc2.import(node)
115
+
116
+ assert_equal("<nums>\n <two/>\n <one/>\n</nums>",
117
+ doc2.root.to_s)
118
+ end
119
+ end