libxml-ruby 0.9.7-x86-mswin32-60 → 0.9.8-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/CHANGES +53 -0
  2. data/Rakefile +1 -0
  3. data/ext/libxml/build.log +4 -0
  4. data/ext/libxml/cbg.c +86 -86
  5. data/ext/libxml/libxml.c +878 -876
  6. data/ext/libxml/ruby_libxml.h +8 -4
  7. data/ext/libxml/ruby_xml_attr.c +36 -168
  8. data/ext/libxml/ruby_xml_attr.h +2 -4
  9. data/ext/libxml/ruby_xml_attr_decl.c +177 -0
  10. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  11. data/ext/libxml/ruby_xml_attributes.c +29 -20
  12. data/ext/libxml/ruby_xml_document.c +895 -898
  13. data/ext/libxml/ruby_xml_dtd.c +18 -1
  14. data/ext/libxml/ruby_xml_dtd.h +1 -0
  15. data/ext/libxml/ruby_xml_encoding.c +116 -0
  16. data/ext/libxml/ruby_xml_encoding.h +12 -0
  17. data/ext/libxml/ruby_xml_error.c +8 -2
  18. data/ext/libxml/ruby_xml_html_parser.c +53 -74
  19. data/ext/libxml/ruby_xml_html_parser.h +2 -3
  20. data/ext/libxml/ruby_xml_html_parser_context.c +145 -0
  21. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  22. data/ext/libxml/ruby_xml_html_parser_options.c +48 -0
  23. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  24. data/ext/libxml/ruby_xml_input_cbg.c +1 -1
  25. data/ext/libxml/ruby_xml_io.c +30 -0
  26. data/ext/libxml/ruby_xml_io.h +9 -0
  27. data/ext/libxml/ruby_xml_namespace.c +34 -16
  28. data/ext/libxml/ruby_xml_namespace.h +2 -2
  29. data/ext/libxml/ruby_xml_namespaces.c +6 -6
  30. data/ext/libxml/ruby_xml_node.c +1367 -1324
  31. data/ext/libxml/ruby_xml_node.h +2 -2
  32. data/ext/libxml/ruby_xml_parser.c +26 -78
  33. data/ext/libxml/ruby_xml_parser.h +1 -1
  34. data/ext/libxml/ruby_xml_parser_context.c +284 -13
  35. data/ext/libxml/ruby_xml_parser_context.h +1 -2
  36. data/ext/libxml/ruby_xml_parser_options.c +75 -0
  37. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  38. data/ext/libxml/ruby_xml_reader.c +277 -183
  39. data/ext/libxml/ruby_xml_sax_parser.c +60 -57
  40. data/ext/libxml/ruby_xml_xpath_context.c +43 -8
  41. data/ext/libxml/ruby_xml_xpath_expression.c +6 -0
  42. data/ext/libxml/ruby_xml_xpath_object.c +107 -95
  43. data/ext/libxml/ruby_xml_xpath_object.h +9 -1
  44. data/ext/libxml/ruby_xml_xpointer.c +107 -107
  45. data/ext/libxml/version.h +2 -2
  46. data/ext/mingw/libxml_ruby.dll.a +0 -0
  47. data/ext/mingw/libxml_ruby.so +0 -0
  48. data/ext/vc/libxml_ruby.vcproj +43 -3
  49. data/lib/libxml.rb +2 -3
  50. data/lib/libxml/attr.rb +71 -2
  51. data/lib/libxml/attr_decl.rb +81 -0
  52. data/lib/libxml/document.rb +78 -14
  53. data/lib/libxml/html_parser.rb +75 -42
  54. data/lib/libxml/node.rb +11 -0
  55. data/lib/libxml/parser.rb +106 -62
  56. data/lib/libxml/reader.rb +12 -0
  57. data/lib/libxml/sax_parser.rb +42 -52
  58. data/lib/libxml/xpath_object.rb +15 -0
  59. data/test/model/atom.xml +12 -12
  60. data/test/model/bands.xml +4 -4
  61. data/test/model/books.xml +146 -147
  62. data/test/model/merge_bug_data.xml +1 -1
  63. data/test/model/rubynet.xml +1 -0
  64. data/test/model/shiporder.rng +1 -1
  65. data/test/model/shiporder.xml +22 -22
  66. data/test/model/shiporder.xsd +30 -30
  67. data/test/model/xinclude.xml +1 -1
  68. data/test/{tc_node_attr.rb → tc_attr.rb} +1 -1
  69. data/test/tc_attr_decl.rb +131 -0
  70. data/test/tc_deprecated_require.rb +1 -3
  71. data/test/tc_document.rb +13 -3
  72. data/test/tc_document_write.rb +5 -5
  73. data/test/tc_dtd.rb +13 -5
  74. data/test/tc_html_parser.rb +14 -26
  75. data/test/tc_node_cdata.rb +1 -3
  76. data/test/tc_node_comment.rb +2 -4
  77. data/test/tc_node_edit.rb +2 -3
  78. data/test/tc_node_text.rb +35 -1
  79. data/test/tc_node_write.rb +3 -3
  80. data/test/tc_node_xlink.rb +2 -4
  81. data/test/tc_parser.rb +163 -70
  82. data/test/tc_parser_context.rb +103 -42
  83. data/test/tc_reader.rb +173 -45
  84. data/test/tc_relaxng.rb +2 -2
  85. data/test/tc_sax_parser.rb +48 -52
  86. data/test/tc_schema.rb +2 -2
  87. data/test/tc_xpath.rb +37 -6
  88. data/test/tc_xpath_context.rb +7 -1
  89. data/test/tc_xpath_expression.rb +1 -3
  90. data/test/tc_xpointer.rb +1 -3
  91. data/test/test_suite.rb +2 -3
  92. metadata +20 -13
  93. data/ext/libxml/ruby_xml_input.c +0 -329
  94. data/ext/libxml/ruby_xml_input.h +0 -20
  95. data/lib/libxml/parser_context.rb +0 -17
  96. data/lib/libxml/parser_options.rb +0 -25
  97. data/test/model/simple.xml +0 -7
  98. data/test/tc_input.rb +0 -13
  99. data/test/tc_well_formed.rb +0 -11
@@ -3,9 +3,7 @@ require 'test/unit'
3
3
 
4
4
  class CDataCommentTest < Test::Unit::TestCase
5
5
  def setup
6
- xp = XML::Parser.new()
7
- str = '<root></root>'
8
- assert_equal(str, xp.string = str)
6
+ xp = XML::Parser.string('<root></root>')
9
7
  @doc = xp.parse
10
8
  assert_instance_of(XML::Document, @doc)
11
9
  @root = @doc.root
@@ -2,10 +2,8 @@ require "xml"
2
2
  require 'test/unit'
3
3
 
4
4
  class NodeCommentTest < Test::Unit::TestCase
5
- def setup()
6
- xp = XML::Parser.new()
7
- str = '<root></root>'
8
- assert_equal(str, xp.string = str)
5
+ def setup
6
+ xp = XML::Parser.string('<root></root>')
9
7
  @doc = xp.parse
10
8
  assert_instance_of(XML::Document, @doc)
11
9
  @root = @doc.root
@@ -3,8 +3,7 @@ require 'test/unit'
3
3
 
4
4
  class TestNodeEdit < Test::Unit::TestCase
5
5
  def setup
6
- xp = XML::Parser.new()
7
- xp.string = '<test><num>one</num><num>two</num><num>three</num></test>'
6
+ xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
8
7
  @doc = xp.parse
9
8
  end
10
9
 
@@ -108,7 +107,7 @@ class TestNodeEdit < Test::Unit::TestCase
108
107
  end
109
108
 
110
109
  def test_set_base
111
- @doc.root.base = 'http://www.rubynet.org/'
110
+ @doc.root.base_uri = 'http://www.rubynet.org/'
112
111
  assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
113
112
  @doc.root.to_s)
114
113
  end
@@ -14,4 +14,38 @@ class TestTextNode < Test::Unit::TestCase
14
14
  end
15
15
  assert_equal('wrong argument type nil (expected String)', error.to_s)
16
16
  end
17
- end
17
+
18
+ # Disabling output escaping can't work without this test passing.
19
+ def test_text_node_name_sanity
20
+ node = XML::Node.new_text('testdata')
21
+ assert_equal XML::Node::XML_STRING_TEXT.object_id, node.name.object_id
22
+ node.name = 'ignore-me'
23
+ assert_equal XML::Node::XML_STRING_TEXT.object_id, node.name.object_id
24
+ node.name = XML::Node::XML_STRING_TEXT_NOENC
25
+ assert_equal XML::Node::XML_STRING_TEXT_NOENC.object_id, node.name.object_id
26
+ node.name = 'ignore-me'
27
+ assert_equal XML::Node::XML_STRING_TEXT_NOENC.object_id, node.name.object_id
28
+ end
29
+
30
+ def test_text_node_name_singletons_frozen
31
+ assert XML::Node::XML_STRING_TEXT.frozen?
32
+ assert XML::Node::XML_STRING_TEXT_NOENC.frozen?
33
+ end
34
+
35
+ # We use the same facility that libXSLT does here to disable output escaping.
36
+ # This lets you specify that the node's content should be rendered unaltered
37
+ # whenever it is being output. This is useful for things like <script> and
38
+ # <style> nodes in HTML documents if you don't want to be forced to wrap them
39
+ # in CDATA nodes. Or if you are sanitizing existing HTML documents and want
40
+ # to preserve the content of any of the text nodes.
41
+ #
42
+ def test_output_escaping
43
+ node = XML::Node.new_text('<my> "entity"')
44
+ assert_equal '&lt;my&gt; "entity"', node.to_s
45
+ node.name = XML::Node::XML_STRING_TEXT_NOENC
46
+ assert_equal '<my> "entity"', node.to_s
47
+ node.name = XML::Node::XML_STRING_TEXT
48
+ assert_equal '&lt;my&gt; "entity"', node.to_s
49
+ end
50
+
51
+ end
@@ -53,20 +53,20 @@ class TestNodeWrite < Test::Unit::TestCase
53
53
  # ö - c3 b6 in hex, \303\266 in octal
54
54
  # ü - c3 bc in hex, \303\274 in octal
55
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::Input::UTF_8))
56
+ node.to_s(:encoding => XML::Encoding::UTF_8))
57
57
 
58
58
  # ISO_8859_1:
59
59
  # ö - f6 in hex, \366 in octal
60
60
  # ü - fc in hex, \374 in octal
61
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::Input::ISO_8859_1))
62
+ node.to_s(:encoding => XML::Encoding::ISO_8859_1))
63
63
 
64
64
 
65
65
  # Invalid encoding
66
66
  error = assert_raise(ArgumentError) do
67
67
  node.to_s(:encoding => -9999)
68
68
  end
69
- assert_equal('Unknown encoding.', error.to_s)
69
+ assert_equal('Unknown encoding value: -9999', error.to_s)
70
70
  end
71
71
 
72
72
  # --- Debug ---
@@ -1,12 +1,10 @@
1
- # $Id: tc_node_xlink.rb 481 2008-07-19 08:59:39Z cfis $
1
+ # $Id: tc_node_xlink.rb 710 2009-01-20 05:30:51Z cfis $
2
2
  require "xml"
3
3
  require 'test/unit'
4
4
 
5
5
  class TC_XML_Node_XLink < Test::Unit::TestCase
6
6
  def setup()
7
- xp = XML::Parser.new()
8
- str = '<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>'
9
- assert_equal(str, xp.string = str)
7
+ xp = XML::Parser.string('<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>')
10
8
  doc = xp.parse
11
9
  assert_instance_of(XML::Document, doc)
12
10
  @root = doc.root
@@ -5,110 +5,164 @@ require 'stringio'
5
5
  class TestParser < Test::Unit::TestCase
6
6
  def setup
7
7
  XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
8
- @xp = XML::Parser.new
9
8
  end
10
9
 
11
10
  def teardown
12
- @xp = nil
13
11
  GC.start
14
12
  GC.start
15
13
  GC.start
16
14
  end
17
15
 
18
16
  # ----- Sources ------
19
- def test_file
20
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
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
21
 
22
- @xp.file = file
23
- assert_equal(file, @xp.file)
24
- assert_equal(file, @xp.input.file)
22
+ parser = XML::Parser.document(doc)
25
23
 
26
- doc = @xp.parse
27
- assert_instance_of(XML::Document, doc)
28
- assert_instance_of(XML::Parser::Context, @xp.context)
29
- GC.start
30
- GC.start
31
- GC.start
32
- end
33
-
34
- def test_file_class
35
- file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
24
+ doc = parser.parse
36
25
 
37
- xp = XML::Parser.file(file)
38
- assert_instance_of(XML::Parser, xp)
39
- assert_equal(file, xp.file)
40
- assert_equal(file, xp.input.file)
26
+ assert_instance_of(XML::Document, doc)
27
+ assert_instance_of(XML::Parser::Context, parser.context)
41
28
  end
42
29
 
43
- def test_string
44
- str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
45
-
46
- @xp.string = str
47
- assert_equal(str, @xp.string)
48
- assert_equal(str, @xp.input.string)
30
+ def test_file
31
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
49
32
 
50
- doc = @xp.parse
33
+ parser = XML::Parser.file(file)
34
+ doc = parser.parse
51
35
  assert_instance_of(XML::Document, doc)
52
- assert_instance_of(XML::Parser::Context, @xp.context)
36
+ assert_instance_of(XML::Parser::Context, parser.context)
53
37
  end
54
38
 
55
- def test_string_empty
56
- assert_raise(XML::Error) do
57
- @xp.string = ''
58
- @xp.parse
59
- end
39
+ def test_file_encoding
40
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
41
+ parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
60
42
 
61
- assert_raise(TypeError) do
62
- @xp.string = nil
43
+ error = assert_raise(XML::Error) do
44
+ doc = parser.parse
63
45
  end
64
- end
65
46
 
66
- def test_string_class
67
- str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
47
+ assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
68
48
 
69
- xp = XML::Parser.string(str)
70
- assert_instance_of(XML::Parser, xp)
71
- assert_equal(str, xp.string)
72
- assert_equal(str, xp.input.string)
49
+ parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
50
+ doc = parser.parse
51
+ assert_not_nil(doc)
73
52
  end
74
53
 
75
- def test_io
76
- File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
77
- @xp.io = io
78
- assert_equal(io, @xp.io)
79
- assert_equal(io, @xp.input.io)
54
+ def test_file_base_uri
55
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
80
56
 
81
- doc = @xp.parse
82
- assert_instance_of(XML::Document, doc)
83
- assert_instance_of(XML::Parser::Context, @xp.context)
84
- end
57
+ parser = XML::Parser.file(file)
58
+ doc = parser.parse
59
+ assert(doc.child.base.match(/test\/model\/bands.xml/))
60
+
61
+ parser = XML::Parser.file(file, :base_uri => "http://libxml.org")
62
+ doc = parser.parse
63
+ assert(doc.child.base.match(/test\/model\/bands.xml/))
85
64
  end
86
65
 
87
- def test_io_class
66
+ def test_io
88
67
  File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
89
- xp = XML::Parser.io(io)
90
- assert_instance_of(XML::Parser, xp)
91
- assert_equal(io, xp.io)
92
- assert_equal(io, xp.input.io)
68
+ parser = XML::Parser.io(io)
69
+ assert_instance_of(XML::Parser, parser)
93
70
 
94
- doc = xp.parse
71
+ doc = parser.parse
95
72
  assert_instance_of(XML::Document, doc)
96
- assert_instance_of(XML::Parser::Context, xp.context)
73
+ assert_instance_of(XML::Parser::Context, parser.context)
97
74
  end
98
75
  end
99
76
 
100
77
  def test_string_io
101
78
  data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
102
79
  string_io = StringIO.new(data)
103
- @xp.io = string_io
104
- assert_equal(string_io, @xp.io)
105
- assert_equal(string_io, @xp.input.io)
80
+ parser = XML::Parser.io(string_io)
81
+
82
+ doc = parser.parse
83
+ assert_instance_of(XML::Document, doc)
84
+ assert_instance_of(XML::Parser::Context, parser.context)
85
+ end
86
+
87
+ def test_string
88
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
89
+
90
+ parser = XML::Parser.string(str)
91
+ assert_instance_of(XML::Parser, parser)
106
92
 
107
- doc = @xp.parse
93
+ doc = parser.parse
108
94
  assert_instance_of(XML::Document, doc)
109
- assert_instance_of(XML::Parser::Context, @xp.context)
95
+ assert_instance_of(XML::Parser::Context, parser.context)
96
+ end
97
+
98
+ def test_string_options
99
+ xml = <<-EOS
100
+ <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
101
+ <test>
102
+ <cdata><![CDATA[something]]></cdata>
103
+ <entity>&foo;</entity>
104
+ </test>
105
+ EOS
106
+
107
+ XML::default_substitute_entities = false
108
+
109
+ # Parse normally
110
+ parser = XML::Parser.string(xml)
111
+ doc = parser.parse
112
+ assert_nil(doc.child.base)
113
+
114
+ # Cdata section should be cdata nodes
115
+ node = doc.find_first('/test/cdata').child
116
+ assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type)
117
+
118
+ # Entities should not be subtituted
119
+ node = doc.find_first('/test/entity')
120
+ assert_equal('&foo;', node.child.to_s)
121
+
122
+ # Parse with options
123
+ parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
124
+ :options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT)
125
+ doc = parser.parse
126
+ assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org')
127
+
128
+ # Cdata section should be text nodes
129
+ node = doc.find_first('/test/cdata').child
130
+ assert_equal(XML::Node::TEXT_NODE, node.node_type)
131
+
132
+ # Entities should be subtituted
133
+ node = doc.find_first('/test/entity')
134
+ assert_equal('bar', node.child.to_s)
110
135
  end
111
136
 
137
+ def test_string_encoding
138
+ # ISO_8859_1:
139
+ # ö - f6 in hex, \366 in octal
140
+ # ü - fc in hex, \374 in octal
141
+
142
+ xml = <<-EOS
143
+ <bands>
144
+ <metal>m\366tley_cr\374e</metal>
145
+ </bands>
146
+ EOS
147
+
148
+ # Parse as UTF_8
149
+ parser = XML::Parser.string(xml)
150
+
151
+ error = assert_raise(XML::Error) do
152
+ doc = parser.parse
153
+ end
154
+
155
+ assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
156
+ error.to_s)
157
+
158
+ # Parse as ISO_8859_1:
159
+ parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1)
160
+ doc = parser.parse
161
+ node = doc.find_first('//metal')
162
+ assert_equal("m\303\266tley_cr\303\274e", node.content)
163
+ end
164
+
165
+
112
166
  def test_fd_gc
113
167
  # Test opening # of documents up to the file limit for the OS.
114
168
  # Ideally it should run until libxml emits a warning,
@@ -155,9 +209,9 @@ class TestParser < Test::Unit::TestCase
155
209
  end
156
210
 
157
211
  def test_bad_xml
158
- @xp.string = '<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
212
+ parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
159
213
  error = assert_raise(XML::Error) do
160
- assert_not_nil(@xp.parse)
214
+ assert_not_nil(parser.parse)
161
215
  end
162
216
 
163
217
  assert_not_nil(error)
@@ -176,12 +230,51 @@ class TestParser < Test::Unit::TestCase
176
230
  assert_nil(error.node)
177
231
  end
178
232
 
179
- def test_double_parse
180
- parser = XML::Parser.string("<test>something</test>")
233
+ # Deprecated methods
234
+ def test_document_deprecated
235
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
236
+ parser = XML::Parser.file(file)
181
237
  doc = parser.parse
182
238
 
183
- assert_raise(RuntimeError) do
184
- parser.parse
239
+ parser = XML::Parser.new
240
+ parser.document = doc
241
+ doc = parser.parse
242
+
243
+ assert_instance_of(XML::Document, doc)
244
+ assert_instance_of(XML::Parser::Context, parser.context)
245
+ end
246
+
247
+ def test_file_deprecated
248
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
249
+
250
+ parser = XML::Parser.new
251
+ parser.file = file
252
+ doc = parser.parse
253
+ assert_instance_of(XML::Document, doc)
254
+ assert_instance_of(XML::Parser::Context, parser.context)
255
+ end
256
+
257
+ def test_io_deprecated
258
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
259
+ parser = XML::Parser.new
260
+ assert_instance_of(XML::Parser, parser)
261
+ parser.io = io
262
+
263
+ doc = parser.parse
264
+ assert_instance_of(XML::Document, doc)
265
+ assert_instance_of(XML::Parser::Context, parser.context)
185
266
  end
186
267
  end
268
+
269
+ def test_string_deprecated
270
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
271
+
272
+ parser = XML::Parser.new
273
+ parser.string = str
274
+ assert_instance_of(XML::Parser, parser)
275
+
276
+ doc = parser.parse
277
+ assert_instance_of(XML::Document, doc)
278
+ assert_instance_of(XML::Parser::Context, parser.context)
279
+ end
187
280
  end
@@ -2,101 +2,162 @@ require "xml"
2
2
  require 'test/unit'
3
3
 
4
4
  class TestParserContext < Test::Unit::TestCase
5
- def setup
6
- str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
7
- xp = XML::Parser.string(str)
8
- assert_equal(str, xp.string = str)
9
- doc = xp.parse
10
- assert_instance_of(XML::Document, doc)
11
- @ctxt = xp.context
12
- assert_instance_of(XML::Parser::Context, @ctxt)
5
+ def test_string
6
+ # UTF8
7
+ xml = <<-EOS
8
+ <bands>
9
+ <metal>m\303\266tley_cr\303\274e</metal>
10
+ </bands>
11
+ EOS
12
+
13
+ context = XML::Parser::Context.string(xml)
14
+ assert_instance_of(XML::Parser::Context, context)
15
+ assert_equal(XML::Encoding::NONE, context.encoding)
16
+ assert_nil(context.base_uri)
17
+ end
18
+
19
+ def test_encoding
20
+ # ISO_8859_1:
21
+ xml = <<-EOS
22
+ <bands>
23
+ <metal>m\366tley_cr\374e</metal>
24
+ </bands>
25
+ EOS
26
+
27
+ context = XML::Parser::Context.string(xml)
28
+ assert_equal(XML::Encoding::NONE, context.encoding)
29
+
30
+ context.encoding = XML::Encoding::ISO_8859_1
31
+ assert_equal(XML::Encoding::ISO_8859_1, context.encoding)
32
+ end
33
+
34
+ def test_base_uri
35
+ # UTF8
36
+ xml = <<-EOS
37
+ <bands>
38
+ <metal>m\303\266tley_cr\303\274e</metal>
39
+ </bands>
40
+ EOS
41
+
42
+ context = XML::Parser::Context.string(xml)
43
+ assert_nil(context.base_uri)
44
+
45
+ context.base_uri = 'http://libxml.rubyforge.org'
46
+ assert_equal('http://libxml.rubyforge.org', context.base_uri)
13
47
  end
14
48
 
15
- def teardown
16
- @ctxt = nil
49
+ def test_string_empty
50
+ error = assert_raise(TypeError) do
51
+ parser = XML::Parser::Context.string(nil)
52
+ end
53
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
54
+
55
+ error = assert_raise(ArgumentError) do
56
+ XML::Parser::Context.string('')
57
+ end
58
+ assert_equal("Must specify a string with one or more characters", error.to_s)
17
59
  end
18
60
 
19
61
  def test_well_formed
20
- if @ctxt.well_formed?
21
- assert_instance_of(TrueClass, @ctxt.well_formed?)
22
- else
23
- assert_instance_of(FalseClass, @ctxt.well_formed?)
62
+ parser = XML::Parser.string("<abc/>")
63
+ parser.parse
64
+ assert(parser.context.well_formed?)
65
+ end
66
+
67
+ def test_not_well_formed
68
+ parser = XML::Parser.string("<abc>")
69
+ assert_raise(XML::Error) do
70
+ parser.parse
24
71
  end
72
+ assert(!parser.context.well_formed?)
25
73
  end
26
74
 
27
75
  def test_version_info
28
- assert_instance_of(String, @ctxt.version)
76
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
77
+ parser = XML::Parser.file(file)
78
+ assert_nil(parser.context.version)
79
+ parser.parse
80
+ assert_equal("1.0", parser.context.version)
29
81
  end
30
82
 
31
83
  def test_depth
32
- assert_instance_of(Fixnum, @ctxt.depth)
84
+ context = XML::Parser::Context.new
85
+ assert_instance_of(Fixnum, context.depth)
33
86
  end
34
87
 
35
88
  def test_disable_sax
36
- assert(!@ctxt.disable_sax?)
89
+ context = XML::Parser::Context.new
90
+ assert(!context.disable_sax?)
37
91
  end
38
92
 
39
93
  def test_docbook
40
- assert(!@ctxt.docbook?)
41
- end
42
-
43
- def test_encoding
44
- assert(!@ctxt.encoding)
94
+ context = XML::Parser::Context.new
95
+ assert(!context.docbook?)
45
96
  end
46
97
 
47
98
  def test_html
48
- assert(!@ctxt.html?)
99
+ context = XML::Parser::Context.new
100
+ assert(!context.html?)
49
101
  end
50
102
 
51
103
  def test_keep_blanks
52
- if @ctxt.keep_blanks?
53
- assert_instance_of(TrueClass, @ctxt.keep_blanks?)
104
+ context = XML::Parser::Context.new
105
+ if context.keep_blanks?
106
+ assert_instance_of(TrueClass, context.keep_blanks?)
54
107
  else
55
- assert_instance_of(FalseClass, @ctxt.keep_blanks?)
108
+ assert_instance_of(FalseClass, context.keep_blanks?)
56
109
  end
57
110
  end
58
111
 
59
112
  if ENV['NOTWORKING']
60
113
  def test_num_chars
61
- assert_equal(17, @ctxt.num_chars)
114
+ assert_equal(17, context.num_chars)
62
115
  end
63
116
  end
64
117
 
65
118
  def test_replace_entities
66
- if @ctxt.replace_entities?
67
- assert_instance_of(TrueClass, @ctxt.replace_entities?)
68
- else
69
- assert_instance_of(FalseClass, @ctxt.replace_entities?)
70
- end
119
+ context = XML::Parser::Context.new
120
+ assert(!context.replace_entities?)
121
+
122
+ # context.options = 1
123
+ # assert(context.replace_entities?)
124
+
125
+ context.options = 0
126
+ assert(!context.replace_entities?)
127
+
128
+ context.replace_entities = true
129
+ assert(context.replace_entities?)
71
130
  end
72
131
 
73
132
  def test_space_depth
74
- assert_equal(1, @ctxt.space_depth)
133
+ context = XML::Parser::Context.new
134
+ assert_equal(1, context.space_depth)
75
135
  end
76
136
 
77
137
  def test_subset_external
78
- assert(!@ctxt.subset_external?)
138
+ context = XML::Parser::Context.new
139
+ assert(!context.subset_external?)
79
140
  end
80
141
 
81
142
  def test_data_directory_get
82
- assert_nil(@ctxt.data_directory)
143
+ context = XML::Parser::Context.new
144
+ assert_nil(context.data_directory)
83
145
  end
84
146
 
85
147
  def test_parse_error
86
- xp = XML::Parser.new
87
- xp.string = '<foo><bar/></foz>'
88
-
148
+ xp = XML::Parser.string('<foo><bar/></foz>')
149
+
89
150
  assert_raise(XML::Error) do
90
151
  xp.parse
91
152
  end
92
-
153
+
93
154
  # Now check context
94
155
  context = xp.context
95
156
  assert_equal(nil, context.data_directory)
96
157
  assert_equal(0, context.depth)
97
158
  assert_equal(true, context.disable_sax?)
98
159
  assert_equal(false, context.docbook?)
99
- assert_equal(nil, context.encoding)
160
+ assert_equal(XML::Encoding::NONE, context.encoding)
100
161
  assert_equal(76, context.errno)
101
162
  assert_equal(false, context.html?)
102
163
  assert_equal(5, context.io_max_num_streams)
@@ -107,7 +168,7 @@ class TestParserContext < Test::Unit::TestCase
107
168
  assert_equal(0, context.name_depth)
108
169
  assert_equal(10, context.name_depth_max)
109
170
  assert_equal(17, context.num_chars)
110
- assert_equal(true, context.replace_entities?)
171
+ assert_equal(false, context.replace_entities?)
111
172
  assert_equal(1, context.space_depth)
112
173
  assert_equal(10, context.space_depth_max)
113
174
  assert_equal(false, context.subset_external?)
@@ -122,4 +183,4 @@ class TestParserContext < Test::Unit::TestCase
122
183
  assert_equal('1.0', context.version)
123
184
  assert_equal(false, context.well_formed?)
124
185
  end
125
- end
186
+ end