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_node_text.rb CHANGED
@@ -1,69 +1,71 @@
1
- require 'xml'
2
- require 'test/unit'
3
-
4
- class TestTextNode < Test::Unit::TestCase
5
- def test_content
6
- node = XML::Node.new_text('testdata')
7
- assert_instance_of(XML::Node, node)
8
- assert_equal('testdata', node.content)
9
- end
10
-
11
- def test_invalid_content
12
- error = assert_raise(TypeError) do
13
- node = XML::Node.new_text(nil)
14
- end
15
- assert_equal('wrong argument type nil (expected String)', error.to_s)
16
- end
17
-
18
- # We use the same facility that libXSLT does here to disable output escaping.
19
- # This lets you specify that the node's content should be rendered unaltered
20
- # whenever it is being output. This is useful for things like <script> and
21
- # <style> nodes in HTML documents if you don't want to be forced to wrap them
22
- # in CDATA nodes. Or if you are sanitizing existing HTML documents and want
23
- # to preserve the content of any of the text nodes.
24
- #
25
- def test_output_escaping
26
- textnoenc = 'if (a < b || c > d) return "e";'
27
- text = "if (a &lt; b || c &gt; d) return \"e\";"
28
-
29
- node = XML::Node.new_text(textnoenc)
30
- assert node.output_escaping?
31
- assert_equal text, node.to_s
32
-
33
- node.output_escaping = false
34
- assert_equal textnoenc, node.to_s
35
-
36
- node.output_escaping = true
37
- assert_equal text, node.to_s
38
-
39
- node.output_escaping = nil
40
- assert_equal textnoenc, node.to_s
41
-
42
- node.output_escaping = true
43
- assert_equal text, node.to_s
44
- end
45
-
46
- # Just a sanity check for output escaping.
47
- def test_output_escaping_sanity
48
- node = XML::Node.new_text('testdata')
49
- assert_equal 'text', node.name
50
- assert node.output_escaping?
51
-
52
- node.output_escaping = false
53
- assert_equal 'textnoenc', node.name
54
- assert ! node.output_escaping?
55
-
56
- node.output_escaping = true
57
- assert_equal 'text', node.name
58
- assert node.output_escaping?
59
-
60
- node.output_escaping = nil
61
- assert_equal 'textnoenc', node.name
62
- assert ! node.output_escaping?
63
-
64
- node.output_escaping = true
65
- assert_equal 'text', node.name
66
- assert node.output_escaping?
67
- end
68
-
69
- end
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
@@ -1,12 +1,11 @@
1
- require 'xml'
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
2
4
  require 'test/unit'
3
5
 
4
6
  class TestNodeWrite < Test::Unit::TestCase
5
7
  def setup
6
- # Strip spaces to make testing easier
7
- XML.default_keep_blanks = false
8
- file = File.join(File.dirname(__FILE__), 'model/bands.xml')
9
- @doc = XML::Document.file(file)
8
+ load_encoding("utf-8")
10
9
  end
11
10
 
12
11
  def teardown
@@ -14,10 +13,21 @@ class TestNodeWrite < Test::Unit::TestCase
14
13
  @doc = nil
15
14
  end
16
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
+
17
26
  def test_to_s_default
18
27
  # Default to_s has indentation
19
28
  node = @doc.root
20
- assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
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>",
21
31
  node.to_s)
22
32
  end
23
33
 
@@ -25,7 +35,7 @@ class TestNodeWrite < Test::Unit::TestCase
25
35
  # No indentation due to global setting
26
36
  node = @doc.root
27
37
  XML.indent_tree_output = false
28
- assert_equal("<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
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>",
29
39
  node.to_s)
30
40
  ensure
31
41
  XML.indent_tree_output = true
@@ -34,14 +44,14 @@ class TestNodeWrite < Test::Unit::TestCase
34
44
  def test_to_s_no_indentation
35
45
  # No indentation due to local setting
36
46
  node = @doc.root
37
- assert_equal("<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>",
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>",
38
48
  node.to_s(:indent => false))
39
49
  end
40
50
 
41
51
  def test_to_s_level
42
52
  # No indentation due to local setting
43
53
  node = @doc.root
44
- assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n </bands>",
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>",
45
55
  node.to_s(:level => 1))
46
56
  end
47
57
 
@@ -52,15 +62,23 @@ class TestNodeWrite < Test::Unit::TestCase
52
62
  # UTF8:
53
63
  # ö - c3 b6 in hex, \303\266 in octal
54
64
  # ü - c3 bc in hex, \303\274 in octal
55
- assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
56
- node.to_s(:encoding => XML::Encoding::UTF_8))
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)
57
69
 
58
70
  # ISO_8859_1:
59
71
  # ö - f6 in hex, \366 in octal
60
72
  # ü - fc in hex, \374 in octal
61
- assert_equal("<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
62
- node.to_s(:encoding => XML::Encoding::ISO_8859_1))
63
-
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
64
82
 
65
83
  # Invalid encoding
66
84
  error = assert_raise(ArgumentError) do
@@ -72,8 +90,15 @@ class TestNodeWrite < Test::Unit::TestCase
72
90
  def test_inner_xml
73
91
  # Default to_s has indentation
74
92
  node = @doc.root
75
- assert_equal("<m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>",
76
- node.inner_xml)
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
77
102
  end
78
103
 
79
104
  # --- Debug ---
@@ -1,26 +1,29 @@
1
- # $Id$
2
- require "xml"
3
- require 'test/unit'
4
-
5
- class TC_XML_Node_XLink < Test::Unit::TestCase
6
- def setup()
7
- xp = XML::Parser.string('<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>')
8
- doc = xp.parse
9
- assert_instance_of(XML::Document, doc)
10
- @root = doc.root
11
- assert_instance_of(XML::Node, @root)
12
- end
13
-
14
- def teardown()
15
- @root = nil
16
- end
17
-
18
- def test_xml_node_xlink()
19
- for elem in @root.find('fixnum')
20
- assert_instance_of(XML::Node, elem)
21
- assert_instance_of(TrueClass, elem.xlink?)
22
- assert_equal("simple", elem.xlink_type_name)
23
- assert_equal(XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type)
24
- end
25
- end
26
- end
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
data/test/tc_parser.rb CHANGED
@@ -1,330 +1,336 @@
1
- require 'xml'
2
- require 'test/unit'
3
- require 'stringio'
4
-
5
- class TestParser < Test::Unit::TestCase
6
- def setup
7
- XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
8
- end
9
-
10
- def teardown
11
- GC.start
12
- GC.start
13
- GC.start
14
- end
15
-
16
- # ----- Sources ------
17
- def test_document
18
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
19
- parser = XML::Parser.file(file)
20
- doc = parser.parse
21
-
22
- parser = XML::Parser.document(doc)
23
-
24
- doc = parser.parse
25
-
26
- assert_instance_of(XML::Document, doc)
27
- assert_instance_of(XML::Parser::Context, parser.context)
28
- end
29
-
30
- def test_nil_document
31
- error = assert_raise(TypeError) do
32
- XML::Parser.document(nil)
33
- end
34
-
35
- assert_equal("Must pass an XML::Document object", error.to_s)
36
- end
37
-
38
- def test_file
39
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
40
-
41
- parser = XML::Parser.file(file)
42
- doc = parser.parse
43
- assert_instance_of(XML::Document, doc)
44
- assert_instance_of(XML::Parser::Context, parser.context)
45
- end
46
-
47
- def test_noexistent_file
48
- error = assert_raise(XML::Error) do
49
- XML::Parser.file('i_dont_exist.xml')
50
- end
51
-
52
- assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
53
- end
54
-
55
- def test_nil_file
56
- error = assert_raise(TypeError) do
57
- XML::Parser.file(nil)
58
- end
59
-
60
- assert_equal("can't convert nil into String", error.to_s)
61
- end
62
-
63
- def test_file_encoding
64
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
65
- parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
66
-
67
- error = assert_raise(XML::Error) do
68
- doc = parser.parse
69
- end
70
-
71
- assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
72
-
73
- parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
74
- doc = parser.parse
75
- assert_not_nil(doc)
76
- end
77
-
78
- def test_file_base_uri
79
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
80
-
81
- parser = XML::Parser.file(file)
82
- doc = parser.parse
83
- assert(doc.child.base.match(/test\/model\/bands.xml/))
84
-
85
- parser = XML::Parser.file(file, :base_uri => "http://libxml.org")
86
- doc = parser.parse
87
- assert(doc.child.base.match(/test\/model\/bands.xml/))
88
- end
89
-
90
- def test_io
91
- File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
92
- parser = XML::Parser.io(io)
93
- assert_instance_of(XML::Parser, parser)
94
-
95
- doc = parser.parse
96
- assert_instance_of(XML::Document, doc)
97
- assert_instance_of(XML::Parser::Context, parser.context)
98
- end
99
- end
100
-
101
- def test_io_gc
102
- # Test that the reader keeps a reference
103
- # to the io object
104
- file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
105
- parser = XML::Parser.io(file)
106
- file = nil
107
- GC.start
108
- assert(parser.parse)
109
- end
110
-
111
- def test_nil_io
112
- error = assert_raise(TypeError) do
113
- XML::Parser.io(nil)
114
- end
115
-
116
- assert_equal("Must pass in an IO object", error.to_s)
117
- end
118
-
119
- def test_string_io
120
- data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
121
- string_io = StringIO.new(data)
122
- parser = XML::Parser.io(string_io)
123
-
124
- doc = parser.parse
125
- assert_instance_of(XML::Document, doc)
126
- assert_instance_of(XML::Parser::Context, parser.context)
127
- end
128
-
129
- def test_string
130
- str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
131
-
132
- parser = XML::Parser.string(str)
133
- assert_instance_of(XML::Parser, parser)
134
-
135
- doc = parser.parse
136
- assert_instance_of(XML::Document, doc)
137
- assert_instance_of(XML::Parser::Context, parser.context)
138
- end
139
-
140
- def test_nil_string
141
- error = assert_raise(TypeError) do
142
- XML::Parser.string(nil)
143
- end
144
-
145
- assert_equal("wrong argument type nil (expected String)", error.to_s)
146
- end
147
-
148
- def test_string_options
149
- xml = <<-EOS
150
- <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
151
- <test>
152
- <cdata><![CDATA[something]]></cdata>
153
- <entity>&foo;</entity>
154
- </test>
155
- EOS
156
-
157
- XML::default_substitute_entities = false
158
-
159
- # Parse normally
160
- parser = XML::Parser.string(xml)
161
- doc = parser.parse
162
- assert_nil(doc.child.base)
163
-
164
- # Cdata section should be cdata nodes
165
- node = doc.find_first('/test/cdata').child
166
- assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type)
167
-
168
- # Entities should not be subtituted
169
- node = doc.find_first('/test/entity')
170
- assert_equal('&foo;', node.child.to_s)
171
-
172
- # Parse with options
173
- parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
174
- :options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT)
175
- doc = parser.parse
176
- assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org')
177
-
178
- # Cdata section should be text nodes
179
- node = doc.find_first('/test/cdata').child
180
- assert_equal(XML::Node::TEXT_NODE, node.node_type)
181
-
182
- # Entities should be subtituted
183
- node = doc.find_first('/test/entity')
184
- assert_equal('bar', node.child.to_s)
185
- end
186
-
187
- def test_string_encoding
188
- # ISO_8859_1:
189
- # ö - f6 in hex, \366 in octal
190
- # ü - fc in hex, \374 in octal
191
-
192
- xml = <<-EOS
193
- <bands>
194
- <metal>m\366tley_cr\374e</metal>
195
- </bands>
196
- EOS
197
-
198
- # Parse as UTF_8
199
- parser = XML::Parser.string(xml)
200
-
201
- error = assert_raise(XML::Error) do
202
- doc = parser.parse
203
- end
204
-
205
- assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
206
- error.to_s)
207
-
208
- # Parse as ISO_8859_1:
209
- parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1)
210
- doc = parser.parse
211
- node = doc.find_first('//metal')
212
- assert_equal("m\303\266tley_cr\303\274e", node.content)
213
- end
214
-
215
-
216
- def test_fd_gc
217
- # Test opening # of documents up to the file limit for the OS.
218
- # Ideally it should run until libxml emits a warning,
219
- # thereby knowing we've done a GC sweep. For the time being,
220
- # re-open the same doc `limit descriptors` times.
221
- # If we make it to the end, then we've succeeded,
222
- # otherwise an exception will be thrown.
223
- XML::Error.set_handler {|error|}
224
-
225
- max_fd = if RUBY_PLATFORM.match(/mswin32/i)
226
- 500
227
- else
228
- (`ulimit -n`.chomp.to_i) + 1
229
- end
230
-
231
- file = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
232
- max_fd.times do
233
- XML::Parser.file(file).parse
234
- end
235
- XML::Error.reset_handler {|error|}
236
- end
237
-
238
-
239
- # ----- Errors ------
240
- def test_error
241
- error = assert_raise(XML::Error) do
242
- XML::Parser.string('<foo><bar/></foz>').parse
243
- end
244
-
245
- assert_not_nil(error)
246
- assert_kind_of(XML::Error, error)
247
- assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message)
248
- assert_equal(XML::Error::PARSER, error.domain)
249
- assert_equal(XML::Error::TAG_NAME_MISMATCH, error.code)
250
- assert_equal(XML::Error::FATAL, error.level)
251
- assert_nil(error.file)
252
- assert_equal(1, error.line)
253
- assert_equal('foo', error.str1)
254
- assert_equal('foz', error.str2)
255
- assert_nil(error.str3)
256
- assert_equal(1, error.int1)
257
- assert_equal(20, error.int2)
258
- assert_nil(error.node)
259
- end
260
-
261
- def test_bad_xml
262
- parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
263
- error = assert_raise(XML::Error) do
264
- assert_not_nil(parser.parse)
265
- end
266
-
267
- assert_not_nil(error)
268
- assert_kind_of(XML::Error, error)
269
- assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
270
- assert_equal(XML::Error::PARSER, error.domain)
271
- assert_equal(XML::Error::DOCUMENT_END, error.code)
272
- assert_equal(XML::Error::FATAL, error.level)
273
- assert_nil(error.file)
274
- assert_equal(1, error.line)
275
- assert_nil(error.str1)
276
- assert_nil(error.str2)
277
- assert_nil(error.str3)
278
- assert_equal(0, error.int1)
279
- assert_equal(20, error.int2)
280
- assert_nil(error.node)
281
- end
282
-
283
- # Deprecated methods
284
- def test_document_deprecated
285
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
286
- parser = XML::Parser.file(file)
287
- doc = parser.parse
288
-
289
- parser = XML::Parser.new
290
- parser.document = doc
291
- doc = parser.parse
292
-
293
- assert_instance_of(XML::Document, doc)
294
- assert_instance_of(XML::Parser::Context, parser.context)
295
- end
296
-
297
- def test_file_deprecated
298
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
299
-
300
- parser = XML::Parser.new
301
- parser.file = file
302
- doc = parser.parse
303
- assert_instance_of(XML::Document, doc)
304
- assert_instance_of(XML::Parser::Context, parser.context)
305
- end
306
-
307
- def test_io_deprecated
308
- File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
309
- parser = XML::Parser.new
310
- assert_instance_of(XML::Parser, parser)
311
- parser.io = io
312
-
313
- doc = parser.parse
314
- assert_instance_of(XML::Document, doc)
315
- assert_instance_of(XML::Parser::Context, parser.context)
316
- end
317
- end
318
-
319
- def test_string_deprecated
320
- str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
321
-
322
- parser = XML::Parser.new
323
- parser.string = str
324
- assert_instance_of(XML::Parser, parser)
325
-
326
- doc = parser.parse
327
- assert_instance_of(XML::Document, doc)
328
- assert_instance_of(XML::Parser::Context, parser.context)
329
- end
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+ require 'stringio'
6
+
7
+ class TestParser < Test::Unit::TestCase
8
+ def setup
9
+ XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
10
+ end
11
+
12
+ def teardown
13
+ GC.start
14
+ GC.start
15
+ GC.start
16
+ end
17
+
18
+ # ----- Sources -------8
19
+ def test_document
20
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
21
+ parser = XML::Parser.file(file)
22
+ doc = parser.parse
23
+
24
+ parser = XML::Parser.document(doc)
25
+
26
+ doc = parser.parse
27
+
28
+ assert_instance_of(XML::Document, doc)
29
+ assert_instance_of(XML::Parser::Context, parser.context)
30
+ end
31
+
32
+ def test_nil_document
33
+ error = assert_raise(TypeError) do
34
+ XML::Parser.document(nil)
35
+ end
36
+
37
+ assert_equal("Must pass an XML::Document object", error.to_s)
38
+ end
39
+
40
+ def test_file
41
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
42
+
43
+ parser = XML::Parser.file(file)
44
+ doc = parser.parse
45
+ assert_instance_of(XML::Document, doc)
46
+ assert_instance_of(XML::Parser::Context, parser.context)
47
+ end
48
+
49
+ def test_noexistent_file
50
+ error = assert_raise(XML::Error) do
51
+ XML::Parser.file('i_dont_exist.xml')
52
+ end
53
+
54
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
55
+ end
56
+
57
+ def test_nil_file
58
+ error = assert_raise(TypeError) do
59
+ XML::Parser.file(nil)
60
+ end
61
+
62
+ assert_equal("can't convert nil into String", error.to_s)
63
+ end
64
+
65
+ def test_file_encoding
66
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
67
+ parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
68
+
69
+ error = assert_raise(XML::Error) do
70
+ doc = parser.parse
71
+ end
72
+
73
+ assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
74
+
75
+ parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
76
+ doc = parser.parse
77
+ assert_not_nil(doc)
78
+ end
79
+
80
+ def test_file_base_uri
81
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
82
+
83
+ parser = XML::Parser.file(file)
84
+ doc = parser.parse
85
+ assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/))
86
+
87
+ parser = XML::Parser.file(file, :base_uri => "http://libxml.org")
88
+ doc = parser.parse
89
+ assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/))
90
+ end
91
+
92
+ def test_io
93
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
94
+ parser = XML::Parser.io(io)
95
+ assert_instance_of(XML::Parser, parser)
96
+
97
+ doc = parser.parse
98
+ assert_instance_of(XML::Document, doc)
99
+ assert_instance_of(XML::Parser::Context, parser.context)
100
+ end
101
+ end
102
+
103
+ def test_io_gc
104
+ # Test that the reader keeps a reference
105
+ # to the io object
106
+ file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
107
+ parser = XML::Parser.io(file)
108
+ file = nil
109
+ GC.start
110
+ assert(parser.parse)
111
+ end
112
+
113
+ def test_nil_io
114
+ error = assert_raise(TypeError) do
115
+ XML::Parser.io(nil)
116
+ end
117
+
118
+ assert_equal("Must pass in an IO object", error.to_s)
119
+ end
120
+
121
+ def test_string_io
122
+ data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
123
+ string_io = StringIO.new(data)
124
+ parser = XML::Parser.io(string_io)
125
+
126
+ doc = parser.parse
127
+ assert_instance_of(XML::Document, doc)
128
+ assert_instance_of(XML::Parser::Context, parser.context)
129
+ end
130
+
131
+ def test_string
132
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
133
+
134
+ parser = XML::Parser.string(str)
135
+ assert_instance_of(XML::Parser, parser)
136
+
137
+ doc = parser.parse
138
+ assert_instance_of(XML::Document, doc)
139
+ assert_instance_of(XML::Parser::Context, parser.context)
140
+ end
141
+
142
+ def test_nil_string
143
+ error = assert_raise(TypeError) do
144
+ XML::Parser.string(nil)
145
+ end
146
+
147
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
148
+ end
149
+
150
+ def test_string_options
151
+ xml = <<-EOS
152
+ <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
153
+ <test>
154
+ <cdata><![CDATA[something]]></cdata>
155
+ <entity>&foo;</entity>
156
+ </test>
157
+ EOS
158
+
159
+ XML::default_substitute_entities = false
160
+
161
+ # Parse normally
162
+ parser = XML::Parser.string(xml)
163
+ doc = parser.parse
164
+ assert_nil(doc.child.base_uri)
165
+
166
+ # Cdata section should be cdata nodes
167
+ node = doc.find_first('/test/cdata').child
168
+ assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type)
169
+
170
+ # Entities should not be subtituted
171
+ node = doc.find_first('/test/entity')
172
+ assert_equal('&foo;', node.child.to_s)
173
+
174
+ # Parse with options
175
+ parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
176
+ :options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT)
177
+ doc = parser.parse
178
+ assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org')
179
+
180
+ # Cdata section should be text nodes
181
+ node = doc.find_first('/test/cdata').child
182
+ assert_equal(XML::Node::TEXT_NODE, node.node_type)
183
+
184
+ # Entities should be subtituted
185
+ node = doc.find_first('/test/entity')
186
+ assert_equal('bar', node.child.to_s)
187
+ end
188
+
189
+ def test_string_encoding
190
+ # ISO_8859_1:
191
+ # ö - f6 in hex, \366 in octal
192
+ # ü - fc in hex, \374 in octal
193
+
194
+ xml = <<-EOS
195
+ <bands>
196
+ <metal>m\366tley_cr\374e</metal>
197
+ </bands>
198
+ EOS
199
+
200
+ # Parse as UTF_8
201
+ parser = XML::Parser.string(xml, :encoding => XML::Encoding::UTF_8)
202
+
203
+ error = assert_raise(XML::Error) do
204
+ doc = parser.parse
205
+ end
206
+
207
+ assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
208
+ error.to_s)
209
+
210
+ # Parse as ISO_8859_1:
211
+ parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1)
212
+ doc = parser.parse
213
+ node = doc.find_first('//metal')
214
+ if defined?(Encoding)
215
+ assert_equal(Encoding::ISO8859_1, node.content.encoding)
216
+ assert_equal("m\303\266tley_cr\303\274e".force_encoding(Encoding::ISO8859_1), node.content)
217
+ else
218
+ assert_equal("m\303\266tley_cr\303\274e", node.content)
219
+ end
220
+ end
221
+
222
+ def test_fd_gc
223
+ # Test opening # of documents up to the file limit for the OS.
224
+ # Ideally it should run until libxml emits a warning,
225
+ # thereby knowing we've done a GC sweep. For the time being,
226
+ # re-open the same doc `limit descriptors` times.
227
+ # If we make it to the end, then we've succeeded,
228
+ # otherwise an exception will be thrown.
229
+ XML::Error.set_handler {|error|}
230
+
231
+ max_fd = if RUBY_PLATFORM.match(/mswin32|mingw/i)
232
+ 500
233
+ else
234
+ (`ulimit -n`.chomp.to_i) + 1
235
+ end
236
+
237
+ file = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
238
+ max_fd.times do
239
+ XML::Parser.file(file).parse
240
+ end
241
+ XML::Error.reset_handler {|error|}
242
+ end
243
+
244
+
245
+ # ----- Errors ------
246
+ def test_error
247
+ error = assert_raise(XML::Error) do
248
+ XML::Parser.string('<foo><bar/></foz>').parse
249
+ end
250
+
251
+ assert_not_nil(error)
252
+ assert_kind_of(XML::Error, error)
253
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message)
254
+ assert_equal(XML::Error::PARSER, error.domain)
255
+ assert_equal(XML::Error::TAG_NAME_MISMATCH, error.code)
256
+ assert_equal(XML::Error::FATAL, error.level)
257
+ assert_nil(error.file)
258
+ assert_equal(1, error.line)
259
+ assert_equal('foo', error.str1)
260
+ assert_equal('foz', error.str2)
261
+ assert_nil(error.str3)
262
+ assert_equal(1, error.int1)
263
+ assert_equal(20, error.int2)
264
+ assert_nil(error.node)
265
+ end
266
+
267
+ def test_bad_xml
268
+ parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
269
+ error = assert_raise(XML::Error) do
270
+ assert_not_nil(parser.parse)
271
+ end
272
+
273
+ assert_not_nil(error)
274
+ assert_kind_of(XML::Error, error)
275
+ assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
276
+ assert_equal(XML::Error::PARSER, error.domain)
277
+ assert_equal(XML::Error::DOCUMENT_END, error.code)
278
+ assert_equal(XML::Error::FATAL, error.level)
279
+ assert_nil(error.file)
280
+ assert_equal(1, error.line)
281
+ assert_nil(error.str1)
282
+ assert_nil(error.str2)
283
+ assert_nil(error.str3)
284
+ assert_equal(0, error.int1)
285
+ assert_equal(20, error.int2)
286
+ assert_nil(error.node)
287
+ end
288
+
289
+ # Deprecated methods
290
+ def test_document_deprecated
291
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
292
+ parser = XML::Parser.file(file)
293
+ doc = parser.parse
294
+
295
+ parser = XML::Parser.new
296
+ parser.document = doc
297
+ doc = parser.parse
298
+
299
+ assert_instance_of(XML::Document, doc)
300
+ assert_instance_of(XML::Parser::Context, parser.context)
301
+ end
302
+
303
+ def test_file_deprecated
304
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
305
+
306
+ parser = XML::Parser.new
307
+ parser.file = file
308
+ doc = parser.parse
309
+ assert_instance_of(XML::Document, doc)
310
+ assert_instance_of(XML::Parser::Context, parser.context)
311
+ end
312
+
313
+ def test_io_deprecated
314
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
315
+ parser = XML::Parser.new
316
+ assert_instance_of(XML::Parser, parser)
317
+ parser.io = io
318
+
319
+ doc = parser.parse
320
+ assert_instance_of(XML::Document, doc)
321
+ assert_instance_of(XML::Parser::Context, parser.context)
322
+ end
323
+ end
324
+
325
+ def test_string_deprecated
326
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
327
+
328
+ parser = XML::Parser.new
329
+ parser.string = str
330
+ assert_instance_of(XML::Parser, parser)
331
+
332
+ doc = parser.parse
333
+ assert_instance_of(XML::Document, doc)
334
+ assert_instance_of(XML::Parser::Context, parser.context)
335
+ end
330
336
  end