libxml-ruby 2.0.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/HISTORY +516 -0
  2. data/LICENSE +23 -0
  3. data/MANIFEST +165 -0
  4. data/README.rdoc +161 -0
  5. data/Rakefile +82 -0
  6. data/ext/libxml/extconf.rb +122 -0
  7. data/ext/libxml/libxml.c +93 -0
  8. data/ext/libxml/ruby_libxml.h +101 -0
  9. data/ext/libxml/ruby_xml.c +893 -0
  10. data/ext/libxml/ruby_xml.h +10 -0
  11. data/ext/libxml/ruby_xml_attr.c +352 -0
  12. data/ext/libxml/ruby_xml_attr.h +14 -0
  13. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  14. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  15. data/ext/libxml/ruby_xml_attributes.c +277 -0
  16. data/ext/libxml/ruby_xml_attributes.h +17 -0
  17. data/ext/libxml/ruby_xml_cbg.c +85 -0
  18. data/ext/libxml/ruby_xml_document.c +958 -0
  19. data/ext/libxml/ruby_xml_document.h +17 -0
  20. data/ext/libxml/ruby_xml_dtd.c +257 -0
  21. data/ext/libxml/ruby_xml_dtd.h +9 -0
  22. data/ext/libxml/ruby_xml_encoding.c +221 -0
  23. data/ext/libxml/ruby_xml_encoding.h +16 -0
  24. data/ext/libxml/ruby_xml_error.c +1004 -0
  25. data/ext/libxml/ruby_xml_error.h +14 -0
  26. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  27. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  29. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  30. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  31. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  32. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  33. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  34. data/ext/libxml/ruby_xml_io.c +30 -0
  35. data/ext/libxml/ruby_xml_io.h +9 -0
  36. data/ext/libxml/ruby_xml_namespace.c +170 -0
  37. data/ext/libxml/ruby_xml_namespace.h +12 -0
  38. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  39. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  40. data/ext/libxml/ruby_xml_node.c +1386 -0
  41. data/ext/libxml/ruby_xml_node.h +13 -0
  42. data/ext/libxml/ruby_xml_parser.c +94 -0
  43. data/ext/libxml/ruby_xml_parser.h +14 -0
  44. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  45. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  46. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  47. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  48. data/ext/libxml/ruby_xml_reader.c +1057 -0
  49. data/ext/libxml/ruby_xml_reader.h +14 -0
  50. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  51. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  52. data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
  53. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  54. data/ext/libxml/ruby_xml_sax_parser.c +136 -0
  55. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  56. data/ext/libxml/ruby_xml_schema.c +159 -0
  57. data/ext/libxml/ruby_xml_schema.h +11 -0
  58. data/ext/libxml/ruby_xml_version.h +9 -0
  59. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  60. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  61. data/ext/libxml/ruby_xml_xpath.c +107 -0
  62. data/ext/libxml/ruby_xml_xpath.h +12 -0
  63. data/ext/libxml/ruby_xml_xpath_context.c +390 -0
  64. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  65. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  66. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  67. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  68. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  69. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  70. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  71. data/ext/mingw/Rakefile +34 -0
  72. data/ext/mingw/build.rake +41 -0
  73. data/ext/vc/libxml_ruby.sln +26 -0
  74. data/lib/1.8/libxml_ruby.so +0 -0
  75. data/lib/1.9/libxml_ruby.so +0 -0
  76. data/lib/libxml.rb +30 -0
  77. data/lib/libxml/attr.rb +113 -0
  78. data/lib/libxml/attr_decl.rb +80 -0
  79. data/lib/libxml/attributes.rb +14 -0
  80. data/lib/libxml/document.rb +192 -0
  81. data/lib/libxml/error.rb +90 -0
  82. data/lib/libxml/hpricot.rb +78 -0
  83. data/lib/libxml/html_parser.rb +96 -0
  84. data/lib/libxml/namespace.rb +62 -0
  85. data/lib/libxml/namespaces.rb +38 -0
  86. data/lib/libxml/node.rb +399 -0
  87. data/lib/libxml/ns.rb +22 -0
  88. data/lib/libxml/parser.rb +367 -0
  89. data/lib/libxml/properties.rb +23 -0
  90. data/lib/libxml/reader.rb +29 -0
  91. data/lib/libxml/sax_callbacks.rb +180 -0
  92. data/lib/libxml/sax_parser.rb +58 -0
  93. data/lib/libxml/tree.rb +29 -0
  94. data/lib/libxml/xpath_object.rb +16 -0
  95. data/lib/xml.rb +16 -0
  96. data/lib/xml/libxml.rb +10 -0
  97. data/libxml-ruby.gemspec +50 -0
  98. data/script/benchmark/depixelate +634 -0
  99. data/script/benchmark/hamlet.xml +9055 -0
  100. data/script/benchmark/parsecount +170 -0
  101. data/script/benchmark/sock_entries.xml +507 -0
  102. data/script/benchmark/throughput +41 -0
  103. data/script/test +6 -0
  104. data/setup.rb +1585 -0
  105. data/test/etc_doc_to_s.rb +21 -0
  106. data/test/ets_doc_file.rb +17 -0
  107. data/test/ets_doc_to_s.rb +23 -0
  108. data/test/ets_gpx.rb +28 -0
  109. data/test/ets_node_gc.rb +23 -0
  110. data/test/ets_test.xml +2 -0
  111. data/test/ets_tsr.rb +11 -0
  112. data/test/model/atom.xml +13 -0
  113. data/test/model/bands.iso-8859-1.xml +5 -0
  114. data/test/model/bands.utf-8.xml +5 -0
  115. data/test/model/bands.xml +5 -0
  116. data/test/model/books.xml +146 -0
  117. data/test/model/merge_bug_data.xml +58 -0
  118. data/test/model/ruby-lang.html +238 -0
  119. data/test/model/rubynet.xml +79 -0
  120. data/test/model/rubynet_project +1 -0
  121. data/test/model/shiporder.rnc +28 -0
  122. data/test/model/shiporder.rng +86 -0
  123. data/test/model/shiporder.xml +23 -0
  124. data/test/model/shiporder.xsd +31 -0
  125. data/test/model/soap.xml +27 -0
  126. data/test/model/xinclude.xml +5 -0
  127. data/test/rb-magic-comment.rb +33 -0
  128. data/test/tc_attr.rb +181 -0
  129. data/test/tc_attr_decl.rb +133 -0
  130. data/test/tc_attributes.rb +135 -0
  131. data/test/tc_deprecated_require.rb +13 -0
  132. data/test/tc_document.rb +119 -0
  133. data/test/tc_document_write.rb +187 -0
  134. data/test/tc_dtd.rb +125 -0
  135. data/test/tc_error.rb +138 -0
  136. data/test/tc_html_parser.rb +140 -0
  137. data/test/tc_namespace.rb +62 -0
  138. data/test/tc_namespaces.rb +177 -0
  139. data/test/tc_node.rb +258 -0
  140. data/test/tc_node_cdata.rb +51 -0
  141. data/test/tc_node_comment.rb +33 -0
  142. data/test/tc_node_copy.rb +42 -0
  143. data/test/tc_node_edit.rb +160 -0
  144. data/test/tc_node_text.rb +71 -0
  145. data/test/tc_node_write.rb +108 -0
  146. data/test/tc_node_xlink.rb +29 -0
  147. data/test/tc_parser.rb +336 -0
  148. data/test/tc_parser_context.rb +189 -0
  149. data/test/tc_properties.rb +39 -0
  150. data/test/tc_reader.rb +298 -0
  151. data/test/tc_relaxng.rb +54 -0
  152. data/test/tc_sax_parser.rb +276 -0
  153. data/test/tc_schema.rb +53 -0
  154. data/test/tc_traversal.rb +222 -0
  155. data/test/tc_xinclude.rb +21 -0
  156. data/test/tc_xml.rb +226 -0
  157. data/test/tc_xpath.rb +195 -0
  158. data/test/tc_xpath_context.rb +80 -0
  159. data/test/tc_xpath_expression.rb +38 -0
  160. data/test/tc_xpointer.rb +74 -0
  161. data/test/test_helper.rb +14 -0
  162. data/test/test_suite.rb +39 -0
  163. metadata +254 -0
@@ -0,0 +1,177 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+ class TestNamespaces < Test::Unit::TestCase
8
+ def setup
9
+ file = File.join(File.dirname(__FILE__), 'model/soap.xml')
10
+ @doc = XML::Document.file(file)
11
+ end
12
+
13
+ def teardown
14
+ @doc = nil
15
+ end
16
+
17
+ def test_namespace
18
+ node = @doc.root
19
+ ns = node.namespaces.namespace
20
+ assert_equal('soap', ns.prefix)
21
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
22
+ end
23
+
24
+ def test_set_namespace
25
+ node = XML::Node.new('Envelope')
26
+ assert_equal('<Envelope/>', node.to_s)
27
+
28
+ ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
29
+ assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
30
+ assert_nil(node.namespaces.namespace)
31
+
32
+ # Now put the node in the soap namespace
33
+ node.namespaces.namespace = ns
34
+ assert_not_nil(node.namespaces.namespace)
35
+ assert_equal("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
36
+ end
37
+
38
+ def test_define_namespace
39
+ node = XML::Node.new('Envelope')
40
+ assert_equal('<Envelope/>', node.to_s)
41
+
42
+ XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
43
+ assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
44
+ assert_nil(node.namespaces.namespace)
45
+ end
46
+
47
+ def test_define_default_namespace
48
+ node = XML::Node.new('Envelope')
49
+ assert_equal('<Envelope/>', node.to_s)
50
+
51
+ XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
52
+ assert_equal("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
53
+ # This seems wrong, but appears to be the way libxml works
54
+ assert_nil(node.namespaces.namespace)
55
+ end
56
+
57
+ def test_namespaces
58
+ node = @doc.find_first('//ns1:IdAndName',
59
+ :ns1 => 'http://domain.somewhere.com')
60
+
61
+ namespaces = node.namespaces.sort
62
+ assert_equal(5, namespaces.length)
63
+
64
+ namespace = namespaces[0]
65
+ assert_instance_of(XML::Namespace, namespace)
66
+ assert_equal(nil, namespace.prefix)
67
+ assert_equal('http://services.somewhere.com', namespace.href)
68
+
69
+ namespace = namespaces[1]
70
+ assert_instance_of(XML::Namespace, namespace)
71
+ assert_equal('ns1', namespace.prefix)
72
+ assert_equal('http://domain.somewhere.com', namespace.href)
73
+
74
+ namespace = namespaces[2]
75
+ assert_instance_of(XML::Namespace, namespace)
76
+ assert_equal('soap', namespace.prefix)
77
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
78
+
79
+ namespace = namespaces[3]
80
+ assert_instance_of(XML::Namespace, namespace)
81
+ assert_equal('xsd', namespace.prefix)
82
+ assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
83
+
84
+ namespace = namespaces[4]
85
+ assert_instance_of(XML::Namespace, namespace)
86
+ assert_equal('xsi', namespace.prefix)
87
+ assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
88
+ end
89
+
90
+ def test_namespaces
91
+ node = @doc.find_first('//ns1:IdAndName',
92
+ :ns1 => 'http://domain.somewhere.com')
93
+
94
+ namespaces = node.namespaces.each do |namespace|
95
+ assert_instance_of(XML::Namespace, namespace)
96
+ end
97
+ end
98
+
99
+ def test_namespace_definitions
100
+ ns_defs = @doc.root.namespaces.definitions
101
+ assert_equal(3, ns_defs.size)
102
+
103
+ namespace = ns_defs[0]
104
+ assert_instance_of(XML::Namespace, namespace)
105
+ assert_equal('soap', namespace.prefix)
106
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
107
+
108
+ namespace = ns_defs[1]
109
+ assert_instance_of(XML::Namespace, namespace)
110
+ assert_equal('xsd', namespace.prefix)
111
+ assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
112
+
113
+ namespace = ns_defs[2]
114
+ assert_instance_of(XML::Namespace, namespace)
115
+ assert_equal('xsi', namespace.prefix)
116
+ assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
117
+
118
+ node = @doc.root.find_first('//ns:getManufacturerNamesResponse',
119
+ :ns => 'http://services.somewhere.com')
120
+ ns_defs = node.namespaces.definitions
121
+ assert_equal(1, ns_defs.size)
122
+
123
+ namespace = ns_defs[0]
124
+ assert_instance_of(XML::Namespace, namespace)
125
+ assert_equal(nil, namespace.prefix)
126
+ assert_equal('http://services.somewhere.com', namespace.href)
127
+ end
128
+
129
+ def test_find_by_prefix
130
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
131
+ :ns1 => 'http://services.somewhere.com')
132
+
133
+ namespace = @doc.root.namespaces.find_by_prefix('soap')
134
+
135
+ assert_instance_of(XML::Namespace, namespace)
136
+ assert_equal('soap', namespace.prefix)
137
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
138
+ end
139
+
140
+ def test_find_default_ns
141
+ namespace = @doc.root.namespaces.find_by_prefix(nil)
142
+ assert_nil(namespace)
143
+
144
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
145
+ :ns1 => 'http://services.somewhere.com')
146
+ namespace = node.namespaces.find_by_prefix(nil)
147
+
148
+ assert_instance_of(XML::Namespace, namespace)
149
+ assert_equal(nil, namespace.prefix)
150
+ assert_equal('http://services.somewhere.com', namespace.href)
151
+ end
152
+
153
+ def test_find_ns_by_href
154
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
155
+ :ns1 => 'http://services.somewhere.com')
156
+
157
+ namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
158
+
159
+ assert_instance_of(XML::Namespace, namespace)
160
+ assert_equal('soap', namespace.prefix)
161
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
162
+ end
163
+
164
+ def test_default_namespace
165
+ doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
166
+ ns = doc.root.namespaces.default
167
+ assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
168
+ end
169
+
170
+ def test_default_prefix
171
+ doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
172
+ doc.root.namespaces.default_prefix = 'soap'
173
+
174
+ node = doc.root.find_first('/soap:Envelope')
175
+ assert_not_nil(node)
176
+ end
177
+ end
@@ -0,0 +1,258 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class TestNode < Test::Unit::TestCase
7
+ def setup
8
+ load_encoding("utf-8")
9
+ end
10
+
11
+ def teardown
12
+ XML.default_keep_blanks = true
13
+ @doc = nil
14
+ end
15
+
16
+ def load_encoding(name)
17
+ @encoding = Encoding.find(name) if defined?(Encoding)
18
+ @file_name = "model/bands.#{name.downcase}.xml"
19
+
20
+ # Strip spaces to make testing easier
21
+ XML.default_keep_blanks = false
22
+ file = File.join(File.dirname(__FILE__), @file_name)
23
+ @doc = XML::Document.file(file)
24
+ end
25
+
26
+ def nodes
27
+ # Find all nodes with a country attributes
28
+ @doc.find('*[@country]')
29
+ end
30
+
31
+ def test_doc_class
32
+ assert_instance_of(XML::Document, @doc)
33
+ end
34
+
35
+ def test_doc_node_type
36
+ assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type
37
+ end
38
+
39
+ def test_root_class
40
+ assert_instance_of(XML::Node, @doc.root)
41
+ end
42
+
43
+ def test_root_node_type
44
+ assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type
45
+ end
46
+
47
+ def test_node_class
48
+ for n in nodes
49
+ assert_instance_of(XML::Node, n)
50
+ end
51
+ end
52
+
53
+ def test_context
54
+ node = @doc.root
55
+ context = node.context
56
+ assert_instance_of(XML::XPath::Context, context)
57
+ end
58
+
59
+ def test_find
60
+ assert_instance_of(XML::XPath::Object, self.nodes)
61
+ end
62
+
63
+ def test_node_child_get
64
+ assert_instance_of(TrueClass, @doc.root.child?)
65
+ assert_instance_of(XML::Node, @doc.root.child)
66
+
67
+ if defined?(Encoding)
68
+ assert_equal(@encoding, @doc.root.child.name.encoding)
69
+ assert_equal("m\u00F6tley_cr\u00FCe", @doc.root.child.name)
70
+ else
71
+ assert_equal("m\303\266tley_cr\303\274e", @doc.root.child.name)
72
+ end
73
+ end
74
+
75
+ def test_node_doc
76
+ for n in nodes
77
+ assert_instance_of(XML::Document, n.doc) if n.document?
78
+ end
79
+ end
80
+
81
+ def test_name
82
+ if defined?(Encoding)
83
+ assert_equal(@encoding, nodes[0].name.encoding)
84
+ assert_equal("m\u00F6tley_cr\u00FCe", nodes[0].name)
85
+ else
86
+ assert_equal("m\303\266tley_cr\303\274e", nodes[0].name)
87
+ end
88
+ assert_equal("iron_maiden", nodes[1].name)
89
+ end
90
+
91
+ def test_name_iso_8859_1
92
+ load_encoding("iso-8859-1")
93
+
94
+ if defined?(Encoding)
95
+ assert_equal(@encoding, nodes[0].name.encoding)
96
+ assert_equal("m\303\266tley_cr\303\274e".force_encoding(@encoding), nodes[0].name)
97
+ else
98
+ assert_equal("m\303\266tley_cr\303\274e", nodes[0].name)
99
+ end
100
+ assert_equal("iron_maiden", nodes[1].name)
101
+ end
102
+
103
+ def test_node_find
104
+ nodes = @doc.root.find('./fixnum')
105
+ for node in nodes
106
+ assert_instance_of(XML::Node, node)
107
+ end
108
+ end
109
+
110
+ def test_equality
111
+ node_a = @doc.find_first('*[@country]')
112
+ node_b = @doc.root.child
113
+
114
+ assert(node_a == node_b)
115
+ assert(node_a.eql?(node_b))
116
+ assert(node_a.equal?(node_b))
117
+
118
+ file = File.join(File.dirname(__FILE__), @file_name)
119
+ doc2 = XML::Document.file(file)
120
+
121
+ node_a2 = doc2.find_first('*[@country]')
122
+
123
+ assert_equal(node_a.to_s, node_a2.to_s)
124
+ assert_equal(node_a, node_a2)
125
+ assert(node_a.eql?(node_a2))
126
+ assert(!node_a.equal?(node_a2))
127
+ end
128
+
129
+ def test_equality_nil
130
+ node = @doc.root
131
+ assert(node != nil)
132
+ end
133
+
134
+ def test_equality_wrong_type
135
+ node = @doc.root
136
+
137
+ assert_raise(TypeError) do
138
+ assert(node != 'abc')
139
+ end
140
+ end
141
+
142
+ def test_content
143
+ if defined?(Encoding)
144
+ assert_equal(@encoding, @doc.root.content.encoding)
145
+ assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.",
146
+ @doc.root.content)
147
+
148
+ first = @doc.root.child
149
+ assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.",
150
+ first.content)
151
+ assert_equal("Iron Maiden is a British heavy metal band formed in 1975.", first.next.content)
152
+ else
153
+ assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.",
154
+ @doc.root.content)
155
+
156
+ first = @doc.root.child
157
+ assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.",
158
+ first.content)
159
+ assert_equal("Iron Maiden is a British heavy metal band formed in 1975.",
160
+ first.next.content)
161
+ end
162
+ end
163
+
164
+ def test_content_iso_8859_1
165
+ load_encoding("iso-8859-1")
166
+ if defined?(Encoding)
167
+ assert_equal(@encoding, @doc.root.content.encoding)
168
+ assert_equal("M\xC3\xB6tley Cr\xC3\xBCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.".force_encoding(@encoding),
169
+ @doc.root.content)
170
+
171
+ first = @doc.root.child
172
+ assert_equal("M\xC3\xB6tley Cr\xC3\xBCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(@encoding),
173
+ first.content)
174
+ assert_equal("Iron Maiden is a British heavy metal band formed in 1975.", first.next.content)
175
+ else
176
+ assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.",
177
+ @doc.root.content)
178
+
179
+ first = @doc.root.child
180
+ assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.",
181
+ first.content)
182
+ assert_equal("Iron Maiden is a British heavy metal band formed in 1975.", first.next.content)
183
+ end
184
+ end
185
+
186
+ def test_base
187
+ doc = XML::Parser.string('<person />').parse
188
+ assert_nil(doc.root.base_uri)
189
+ end
190
+
191
+ # We use the same facility that libXSLT does here to disable output escaping.
192
+ # This lets you specify that the node's content should be rendered unaltered
193
+ # whenever it is being output. This is useful for things like <script> and
194
+ # <style> nodes in HTML documents if you don't want to be forced to wrap them
195
+ # in CDATA nodes. Or if you are sanitizing existing HTML documents and want
196
+ # to preserve the content of any of the text nodes.
197
+ #
198
+ def test_output_escaping
199
+ text = '<bad-script>if (a &lt; b || b &gt; c) { return "text"; }<stop/>return "&gt;&gt;&gt;snip&lt;&lt;&lt;";</bad-script>'
200
+ node = XML::Parser.string(text).parse.root
201
+ assert_equal text, node.to_s
202
+
203
+ text_noenc = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
204
+ node.output_escaping = false
205
+ assert_equal text_noenc, node.to_s
206
+
207
+ node.output_escaping = true
208
+ assert_equal text, node.to_s
209
+
210
+ node.output_escaping = nil
211
+ assert_equal text_noenc, node.to_s
212
+
213
+ node.output_escaping = true
214
+ assert_equal text, node.to_s
215
+ end
216
+
217
+ # Just a sanity check for output escaping.
218
+ def test_output_escaping_sanity
219
+ text = '<bad-script>if (a &lt; b || b &gt; c) { return "text"; }<stop/>return "&gt;&gt;&gt;snip&lt;&lt;&lt;";</bad-script>'
220
+ node = XML::Parser.string(text).parse.root
221
+ affected = node.find('//text()')
222
+
223
+ check_escaping = lambda do |flag|
224
+ assert_equal('bad-script', node.name)
225
+ assert_equal(flag, node.output_escaping?)
226
+ affected.each do |x|
227
+ assert_equal(flag ? 'text' : 'textnoenc', x.name)
228
+ assert_equal(flag, x.output_escaping?)
229
+ end
230
+ end
231
+
232
+ node.output_escaping = false
233
+ check_escaping[false]
234
+
235
+ node.output_escaping = true
236
+ check_escaping[true]
237
+
238
+ node.output_escaping = nil
239
+ check_escaping[false]
240
+
241
+ node.output_escaping = true
242
+ check_escaping[true]
243
+
244
+ affected.first.output_escaping = true
245
+ affected.last.output_escaping = false
246
+ assert node.output_escaping?.nil?
247
+ end
248
+
249
+ def test_space_preserve
250
+ node = @doc.root
251
+
252
+ node.space_preserve = false
253
+ assert_equal XML::Node::SPACE_DEFAULT, node.space_preserve
254
+
255
+ node.space_preserve = true
256
+ assert_equal XML::Node::SPACE_PRESERVE, node.space_preserve
257
+ end
258
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class CDataCommentTest < Test::Unit::TestCase
7
+ def setup
8
+ xp = XML::Parser.string('<root></root>')
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