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,33 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ require 'test/unit'
6
+
7
+ class NodeCommentTest < Test::Unit::TestCase
8
+ def setup
9
+ xp = XML::Parser.string('<root></root>')
10
+ @doc = xp.parse
11
+ assert_instance_of(XML::Document, @doc)
12
+ @root = @doc.root
13
+ end
14
+
15
+ def test_libxml_node_add_comment_01
16
+ @root << XML::Node.new_comment('mycomment')
17
+ assert_equal '<root><!--mycomment--></root>',
18
+ @root.to_s.gsub(/\n\s*/,'')
19
+ end
20
+
21
+ def test_libxml_node_add_comment_02
22
+ @root << XML::Node.new_comment('mycomment')
23
+ assert_equal 'comment',
24
+ @root.child.node_type_name
25
+ end
26
+
27
+ def test_libxml_node_add_comment_03
28
+ @root << el = XML::Node.new_comment('mycomment')
29
+ el << "_this_is_added"
30
+ assert_equal '<root><!--mycomment_this_is_added--></root>',
31
+ @root.to_s.gsub(/\n\s*/,'')
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ # see mailing list archive
7
+ # [libxml-devel] Segmentation fault when add the cloned/copied node
8
+ # 2007/11/27 20:51
9
+
10
+ class TestNodeCopy < Test::Unit::TestCase
11
+ def setup
12
+ str = <<-STR
13
+ <html><body>
14
+ <div class="textarea" id="t1" style="STATIC">foo</div>
15
+ <div class="textarea" id="t2" style="STATIC">bar</div>
16
+ </body></html>
17
+ STR
18
+
19
+ doc = XML::Parser.string(str).parse
20
+
21
+ xpath = "//div"
22
+ @div1 = doc.find(xpath).to_a[0]
23
+ @div2 = doc.find(xpath).to_a[1]
24
+ end
25
+
26
+ def test_libxml_node_copy_not_segv
27
+ @div2.each do |child|
28
+ c = child.copy(false)
29
+ @div1 << c
30
+ end
31
+ assert @div1.to_s =~ /foo/
32
+ end
33
+
34
+ def test_libxml_node_clone_not_segv
35
+ @div2.each do |child|
36
+ c = child.clone
37
+ @div1 << c
38
+ end
39
+ assert @div1.to_s =~ /foo/
40
+ end
41
+
42
+ end # TC_XML_Node_Copy
@@ -0,0 +1,160 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class TestNodeEdit < Test::Unit::TestCase
7
+ def setup
8
+ xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
9
+ @doc = xp.parse
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def first_node
17
+ @doc.root.child
18
+ end
19
+
20
+ def second_node
21
+ first_node.next
22
+ end
23
+
24
+ def third_node
25
+ second_node.next
26
+ end
27
+
28
+ def test_add_next_01
29
+ first_node.next = XML::Node.new('num', 'one-and-a-half')
30
+ assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
31
+ @doc.root.to_s.gsub(/\n\s*/,''))
32
+ end
33
+
34
+ def test_add_next_02
35
+ second_node.next = XML::Node.new('num', 'two-and-a-half')
36
+ assert_equal('<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
37
+ @doc.root.to_s.gsub(/\n\s*/,''))
38
+ end
39
+
40
+ def test_add_next_03
41
+ third_node.next = XML::Node.new('num', 'four')
42
+ assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
43
+ @doc.root.to_s.gsub(/\n\s*/,'')
44
+ end
45
+
46
+ def test_add_prev_01
47
+ first_node.prev = XML::Node.new('num', 'half')
48
+ assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
49
+ @doc.root.to_s.gsub(/\n\s*/,'')
50
+ end
51
+
52
+ def test_add_prev_02
53
+ second_node.prev = XML::Node.new('num', 'one-and-a-half')
54
+ assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
55
+ @doc.root.to_s.gsub(/\n\s*/,'')
56
+ end
57
+
58
+ def test_add_prev_03
59
+ third_node.prev = XML::Node.new('num', 'two-and-a-half')
60
+ assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
61
+ @doc.root.to_s.gsub(/\n\s*/,'')
62
+ end
63
+
64
+ def test_remove_node
65
+ first_node.remove!
66
+ assert_equal('<test><num>two</num><num>three</num></test>',
67
+ @doc.root.to_s.gsub(/\n\s*/,''))
68
+ end
69
+
70
+ def test_remove_node_gc
71
+ xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
72
+ doc = xp.parse
73
+ node = doc.root.child.remove!
74
+ node = nil
75
+ GC.start
76
+ assert_not_nil(doc)
77
+ end
78
+
79
+ def test_remove_node_iteration
80
+ nodes = Array.new
81
+ @doc.root.each_element do |node|
82
+ if node.name == 'num'
83
+ nodes << node
84
+ node.remove!
85
+ end
86
+ end
87
+ assert_equal(3, nodes.length)
88
+ end
89
+
90
+ def test_reuse_removed_node
91
+ # Remove the node
92
+ node = @doc.root.first.remove!
93
+ assert_not_nil(node)
94
+
95
+ # Add it to the end of the documnet
96
+ @doc.root.last.next = node
97
+
98
+ assert_equal('<test><num>two</num><num>three</num><num>one</num></test>',
99
+ @doc.root.to_s.gsub(/\n\s*/,''))
100
+ end
101
+
102
+ def test_append_existing_node
103
+ doc = XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
104
+ node1 = doc.find_first('//two')
105
+
106
+ doc.root << node1
107
+ assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
108
+ doc.root.to_s)
109
+ end
110
+
111
+ def test_wrong_doc
112
+ doc1 = XML::Parser.string('<nums><one></one></nums>').parse
113
+ doc2 = XML::Parser.string('<nums><two></two></nums>').parse
114
+
115
+ node = doc1.root.child
116
+
117
+ error = assert_raise(XML::Error) do
118
+ doc2.root << node
119
+ end
120
+
121
+ assert_equal(' Nodes belong to different documents. You must first import the by calling XML::Document.import.',
122
+ error.to_s)
123
+ end
124
+
125
+
126
+ # This test is to verify that an earlier reported bug has been fixed
127
+ def test_merge
128
+ documents = []
129
+
130
+ # Read in 500 documents
131
+ 500.times do
132
+ documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
133
+ end
134
+
135
+ master_doc = documents.shift
136
+ documents.inject(master_doc) do |master_doc, child_doc|
137
+ master_body = master_doc.find("//body").first
138
+ child_body = child_doc.find("//body").first
139
+
140
+ child_element = child_body.detect do |node|
141
+ node.element?
142
+ end
143
+
144
+ master_body << child_element.copy(true)
145
+ master_doc
146
+ end
147
+ end
148
+
149
+ def test_append_chain
150
+ node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
151
+ assert_equal('<foo><bar/>bars contents</foo>',
152
+ node.to_s)
153
+ end
154
+
155
+ def test_set_base
156
+ @doc.root.base_uri = 'http://www.rubynet.org/'
157
+ assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
158
+ @doc.root.to_s)
159
+ end
160
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class TestTextNode < Test::Unit::TestCase
7
+ def test_content
8
+ node = XML::Node.new_text('testdata')
9
+ assert_instance_of(XML::Node, node)
10
+ assert_equal('testdata', node.content)
11
+ end
12
+
13
+ def test_invalid_content
14
+ error = assert_raise(TypeError) do
15
+ node = XML::Node.new_text(nil)
16
+ end
17
+ assert_equal('wrong argument type nil (expected String)', error.to_s)
18
+ end
19
+
20
+ # We use the same facility that libXSLT does here to disable output escaping.
21
+ # This lets you specify that the node's content should be rendered unaltered
22
+ # whenever it is being output. This is useful for things like <script> and
23
+ # <style> nodes in HTML documents if you don't want to be forced to wrap them
24
+ # in CDATA nodes. Or if you are sanitizing existing HTML documents and want
25
+ # to preserve the content of any of the text nodes.
26
+ #
27
+ def test_output_escaping
28
+ textnoenc = 'if (a < b || c > d) return "e";'
29
+ text = "if (a &lt; b || c &gt; d) return \"e\";"
30
+
31
+ node = XML::Node.new_text(textnoenc)
32
+ assert node.output_escaping?
33
+ assert_equal text, node.to_s
34
+
35
+ node.output_escaping = false
36
+ assert_equal textnoenc, node.to_s
37
+
38
+ node.output_escaping = true
39
+ assert_equal text, node.to_s
40
+
41
+ node.output_escaping = nil
42
+ assert_equal textnoenc, node.to_s
43
+
44
+ node.output_escaping = true
45
+ assert_equal text, node.to_s
46
+ end
47
+
48
+ # Just a sanity check for output escaping.
49
+ def test_output_escaping_sanity
50
+ node = XML::Node.new_text('testdata')
51
+ assert_equal 'text', node.name
52
+ assert node.output_escaping?
53
+
54
+ node.output_escaping = false
55
+ assert_equal 'textnoenc', node.name
56
+ assert ! node.output_escaping?
57
+
58
+ node.output_escaping = true
59
+ assert_equal 'text', node.name
60
+ assert node.output_escaping?
61
+
62
+ node.output_escaping = nil
63
+ assert_equal 'textnoenc', node.name
64
+ assert ! node.output_escaping?
65
+
66
+ node.output_escaping = true
67
+ assert_equal 'text', node.name
68
+ assert node.output_escaping?
69
+ end
70
+
71
+ end
@@ -0,0 +1,108 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class TestNodeWrite < 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 test_to_s_default
27
+ # Default to_s has indentation
28
+ node = @doc.root
29
+ assert_equal(Encoding::UTF_8, node.to_s.encoding) if defined?(Encoding)
30
+ assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
31
+ node.to_s)
32
+ end
33
+
34
+ def test_to_s_no_global_indentation
35
+ # No indentation due to global setting
36
+ node = @doc.root
37
+ XML.indent_tree_output = false
38
+ assert_equal("<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
39
+ node.to_s)
40
+ ensure
41
+ XML.indent_tree_output = true
42
+ end
43
+
44
+ def test_to_s_no_indentation
45
+ # No indentation due to local setting
46
+ node = @doc.root
47
+ assert_equal("<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>",
48
+ node.to_s(:indent => false))
49
+ end
50
+
51
+ def test_to_s_level
52
+ # No indentation due to local setting
53
+ node = @doc.root
54
+ assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n </bands>",
55
+ node.to_s(:level => 1))
56
+ end
57
+
58
+ def test_to_s_encoding
59
+ # Test encodings
60
+ node = @doc.root
61
+
62
+ # UTF8:
63
+ # ö - c3 b6 in hex, \303\266 in octal
64
+ # ü - c3 bc in hex, \303\274 in octal
65
+ value = node.to_s(:encoding => XML::Encoding::UTF_8)
66
+ assert_equal(Encoding::UTF_8, node.to_s.encoding) if defined?(Encoding)
67
+ assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
68
+ value)
69
+
70
+ # ISO_8859_1:
71
+ # ö - f6 in hex, \366 in octal
72
+ # ü - fc in hex, \374 in octal
73
+ value = node.to_s(:encoding => XML::Encoding::ISO_8859_1)
74
+ if defined?(Encoding)
75
+ assert_equal(Encoding::ISO8859_1, value.encoding)
76
+ assert_equal("<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>".force_encoding(Encoding::ISO8859_1),
77
+ value)
78
+ else
79
+ assert_equal("<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
80
+ value)
81
+ end
82
+
83
+ # Invalid encoding
84
+ error = assert_raise(ArgumentError) do
85
+ node.to_s(:encoding => -9999)
86
+ end
87
+ assert_equal('Unknown encoding value: -9999', error.to_s)
88
+ end
89
+
90
+ def test_inner_xml
91
+ # Default to_s has indentation
92
+ node = @doc.root
93
+
94
+ if defined?(Encoding)
95
+ assert_equal(Encoding::UTF_8, node.inner_xml.encoding)
96
+ assert_equal("<m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>",
97
+ node.inner_xml)
98
+ else
99
+ assert_equal("<m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>",
100
+ node.inner_xml)
101
+ end
102
+ end
103
+
104
+ # --- Debug ---
105
+ def test_debug
106
+ assert(@doc.root.debug)
107
+ end
108
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+
3
+ # $Id$
4
+ require './test_helper'
5
+
6
+ require 'test/unit'
7
+
8
+ class TC_XML_Node_XLink < Test::Unit::TestCase
9
+ def setup()
10
+ xp = XML::Parser.string('<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>')
11
+ doc = xp.parse
12
+ assert_instance_of(XML::Document, doc)
13
+ @root = doc.root
14
+ assert_instance_of(XML::Node, @root)
15
+ end
16
+
17
+ def teardown()
18
+ @root = nil
19
+ end
20
+
21
+ def test_xml_node_xlink()
22
+ for elem in @root.find('fixnum')
23
+ assert_instance_of(XML::Node, elem)
24
+ assert_instance_of(TrueClass, elem.xlink?)
25
+ assert_equal("simple", elem.xlink_type_name)
26
+ assert_equal(XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type)
27
+ end
28
+ end
29
+ end