libxml-ruby 1.1.3-x86-mswin32-60 → 1.1.4-x86-mswin32-60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/CHANGES +1 -1
  2. data/LICENSE +22 -22
  3. data/README +160 -160
  4. data/Rakefile +0 -9
  5. data/ext/libxml/Makefile +156 -0
  6. data/ext/libxml/extconf.h +5 -0
  7. data/ext/libxml/extconf.rb +4 -160
  8. data/ext/libxml/libxml-ruby.so.a +0 -0
  9. data/ext/libxml/libxml.o +0 -0
  10. data/ext/libxml/libxml_ruby.so +0 -0
  11. data/ext/libxml/mkmf.log +129 -0
  12. data/ext/libxml/ruby_xml.o +0 -0
  13. data/ext/libxml/ruby_xml_attr.c +1 -1
  14. data/ext/libxml/ruby_xml_attr.h +1 -1
  15. data/ext/libxml/ruby_xml_attr.o +0 -0
  16. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  17. data/ext/libxml/ruby_xml_attributes.o +0 -0
  18. data/ext/libxml/ruby_xml_cbg.o +0 -0
  19. data/ext/libxml/ruby_xml_document.c +936 -936
  20. data/ext/libxml/ruby_xml_document.h +1 -1
  21. data/ext/libxml/ruby_xml_document.o +0 -0
  22. data/ext/libxml/ruby_xml_dtd.o +0 -0
  23. data/ext/libxml/ruby_xml_encoding.o +0 -0
  24. data/ext/libxml/ruby_xml_error.o +0 -0
  25. data/ext/libxml/ruby_xml_html_parser.c +1 -1
  26. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  29. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  30. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  31. data/ext/libxml/ruby_xml_io.o +0 -0
  32. data/ext/libxml/ruby_xml_namespace.c +1 -1
  33. data/ext/libxml/ruby_xml_namespace.h +1 -1
  34. data/ext/libxml/ruby_xml_namespace.o +0 -0
  35. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  36. data/ext/libxml/ruby_xml_node.c +1386 -1386
  37. data/ext/libxml/ruby_xml_node.h +1 -1
  38. data/ext/libxml/ruby_xml_node.o +0 -0
  39. data/ext/libxml/ruby_xml_parser.c +1 -1
  40. data/ext/libxml/ruby_xml_parser.h +1 -1
  41. data/ext/libxml/ruby_xml_parser.o +0 -0
  42. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  43. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  44. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  45. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  46. data/ext/libxml/ruby_xml_reader.o +0 -0
  47. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  48. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  49. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  50. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  51. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  52. data/ext/libxml/ruby_xml_schema.o +0 -0
  53. data/ext/libxml/ruby_xml_version.h +3 -3
  54. data/ext/libxml/ruby_xml_xinclude.c +1 -1
  55. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  56. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  57. data/ext/libxml/ruby_xml_xpath.c +1 -1
  58. data/ext/libxml/ruby_xml_xpath.h +1 -1
  59. data/ext/libxml/ruby_xml_xpath.o +0 -0
  60. data/ext/libxml/ruby_xml_xpath_context.c +1 -1
  61. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  62. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  63. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  64. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  65. data/ext/libxml/ruby_xml_xpointer.c +1 -1
  66. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  67. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  68. data/ext/mingw/build.rake +3 -3
  69. data/ext/mingw/libiconv-2.dll +0 -0
  70. data/ext/mingw/libxml2-2.dll +0 -0
  71. data/ext/mingw/libxml_ruby.dll.a +0 -0
  72. data/ext/mingw/libxml_ruby.so +0 -0
  73. data/lib/libxml.rb +29 -29
  74. data/test/model/merge_bug_data.xml +58 -58
  75. data/test/model/rubynet.xml +79 -79
  76. data/test/model/xinclude.xml +4 -4
  77. data/test/tc_attr.rb +170 -170
  78. data/test/tc_document.rb +113 -113
  79. data/test/tc_document_write.rb +117 -117
  80. data/test/tc_dtd.rb +123 -123
  81. data/test/tc_html_parser.rb +137 -137
  82. data/test/tc_node.rb +180 -180
  83. data/test/tc_node_cdata.rb +49 -49
  84. data/test/tc_node_comment.rb +30 -30
  85. data/test/tc_node_edit.rb +157 -157
  86. data/test/tc_node_xlink.rb +26 -26
  87. data/test/tc_parser.rb +329 -329
  88. data/test/tc_parser_context.rb +185 -185
  89. data/test/tc_reader.rb +283 -283
  90. data/test/tc_sax_parser.rb +273 -273
  91. data/test/tc_schema.rb +51 -51
  92. data/test/tc_xinclude.rb +19 -19
  93. data/test/tc_xpath.rb +193 -193
  94. data/test/tc_xpointer.rb +72 -72
  95. metadata +55 -14
  96. data/ext/libxml/build.log +0 -4
@@ -1,186 +1,186 @@
1
- require "xml"
2
- require 'test/unit'
3
-
4
- class TestParserContext < Test::Unit::TestCase
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)
47
- end
48
-
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)
59
- end
60
-
61
- def test_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
71
- end
72
- assert(!parser.context.well_formed?)
73
- end
74
-
75
- def test_version_info
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)
81
- end
82
-
83
- def test_depth
84
- context = XML::Parser::Context.new
85
- assert_instance_of(Fixnum, context.depth)
86
- end
87
-
88
- def test_disable_sax
89
- context = XML::Parser::Context.new
90
- assert(!context.disable_sax?)
91
- end
92
-
93
- def test_docbook
94
- context = XML::Parser::Context.new
95
- assert(!context.docbook?)
96
- end
97
-
98
- def test_html
99
- context = XML::Parser::Context.new
100
- assert(!context.html?)
101
- end
102
-
103
- def test_keep_blanks
104
- context = XML::Parser::Context.new
105
- if context.keep_blanks?
106
- assert_instance_of(TrueClass, context.keep_blanks?)
107
- else
108
- assert_instance_of(FalseClass, context.keep_blanks?)
109
- end
110
- end
111
-
112
- if ENV['NOTWORKING']
113
- def test_num_chars
114
- assert_equal(17, context.num_chars)
115
- end
116
- end
117
-
118
- def test_replace_entities
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?)
130
- end
131
-
132
- def test_space_depth
133
- context = XML::Parser::Context.new
134
- assert_equal(1, context.space_depth)
135
- end
136
-
137
- def test_subset_external
138
- context = XML::Parser::Context.new
139
- assert(!context.subset_external?)
140
- end
141
-
142
- def test_data_directory_get
143
- context = XML::Parser::Context.new
144
- assert_nil(context.data_directory)
145
- end
146
-
147
- def test_parse_error
148
- xp = XML::Parser.string('<foo><bar/></foz>')
149
-
150
- assert_raise(XML::Error) do
151
- xp.parse
152
- end
153
-
154
- # Now check context
155
- context = xp.context
156
- assert_equal(nil, context.data_directory)
157
- assert_equal(0, context.depth)
158
- assert_equal(true, context.disable_sax?)
159
- assert_equal(false, context.docbook?)
160
- assert_equal(XML::Encoding::NONE, context.encoding)
161
- assert_equal(76, context.errno)
162
- assert_equal(false, context.html?)
163
- assert_equal(5, context.io_max_num_streams)
164
- assert_equal(1, context.io_num_streams)
165
- assert_equal(true, context.keep_blanks?)
166
- assert_equal(1, context.io_num_streams)
167
- assert_equal(nil, context.name_node)
168
- assert_equal(0, context.name_depth)
169
- assert_equal(10, context.name_depth_max)
170
- assert_equal(17, context.num_chars)
171
- assert_equal(false, context.replace_entities?)
172
- assert_equal(1, context.space_depth)
173
- assert_equal(10, context.space_depth_max)
174
- assert_equal(false, context.subset_external?)
175
- assert_equal(nil, context.subset_external_system_id)
176
- assert_equal(nil, context.subset_external_uri)
177
- assert_equal(false, context.subset_internal?)
178
- assert_equal(nil, context.subset_internal_name)
179
- assert_equal(false, context.stats?)
180
- assert_equal(true, context.standalone?)
181
- assert_equal(false, context.valid)
182
- assert_equal(false, context.validate?)
183
- assert_equal('1.0', context.version)
184
- assert_equal(false, context.well_formed?)
185
- end
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestParserContext < Test::Unit::TestCase
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)
47
+ end
48
+
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)
59
+ end
60
+
61
+ def test_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
71
+ end
72
+ assert(!parser.context.well_formed?)
73
+ end
74
+
75
+ def test_version_info
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)
81
+ end
82
+
83
+ def test_depth
84
+ context = XML::Parser::Context.new
85
+ assert_instance_of(Fixnum, context.depth)
86
+ end
87
+
88
+ def test_disable_sax
89
+ context = XML::Parser::Context.new
90
+ assert(!context.disable_sax?)
91
+ end
92
+
93
+ def test_docbook
94
+ context = XML::Parser::Context.new
95
+ assert(!context.docbook?)
96
+ end
97
+
98
+ def test_html
99
+ context = XML::Parser::Context.new
100
+ assert(!context.html?)
101
+ end
102
+
103
+ def test_keep_blanks
104
+ context = XML::Parser::Context.new
105
+ if context.keep_blanks?
106
+ assert_instance_of(TrueClass, context.keep_blanks?)
107
+ else
108
+ assert_instance_of(FalseClass, context.keep_blanks?)
109
+ end
110
+ end
111
+
112
+ if ENV['NOTWORKING']
113
+ def test_num_chars
114
+ assert_equal(17, context.num_chars)
115
+ end
116
+ end
117
+
118
+ def test_replace_entities
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?)
130
+ end
131
+
132
+ def test_space_depth
133
+ context = XML::Parser::Context.new
134
+ assert_equal(1, context.space_depth)
135
+ end
136
+
137
+ def test_subset_external
138
+ context = XML::Parser::Context.new
139
+ assert(!context.subset_external?)
140
+ end
141
+
142
+ def test_data_directory_get
143
+ context = XML::Parser::Context.new
144
+ assert_nil(context.data_directory)
145
+ end
146
+
147
+ def test_parse_error
148
+ xp = XML::Parser.string('<foo><bar/></foz>')
149
+
150
+ assert_raise(XML::Error) do
151
+ xp.parse
152
+ end
153
+
154
+ # Now check context
155
+ context = xp.context
156
+ assert_equal(nil, context.data_directory)
157
+ assert_equal(0, context.depth)
158
+ assert_equal(true, context.disable_sax?)
159
+ assert_equal(false, context.docbook?)
160
+ assert_equal(XML::Encoding::NONE, context.encoding)
161
+ assert_equal(76, context.errno)
162
+ assert_equal(false, context.html?)
163
+ assert_equal(5, context.io_max_num_streams)
164
+ assert_equal(1, context.io_num_streams)
165
+ assert_equal(true, context.keep_blanks?)
166
+ assert_equal(1, context.io_num_streams)
167
+ assert_equal(nil, context.name_node)
168
+ assert_equal(0, context.name_depth)
169
+ assert_equal(10, context.name_depth_max)
170
+ assert_equal(17, context.num_chars)
171
+ assert_equal(false, context.replace_entities?)
172
+ assert_equal(1, context.space_depth)
173
+ assert_equal(10, context.space_depth_max)
174
+ assert_equal(false, context.subset_external?)
175
+ assert_equal(nil, context.subset_external_system_id)
176
+ assert_equal(nil, context.subset_external_uri)
177
+ assert_equal(false, context.subset_internal?)
178
+ assert_equal(nil, context.subset_internal_name)
179
+ assert_equal(false, context.stats?)
180
+ assert_equal(true, context.standalone?)
181
+ assert_equal(false, context.valid)
182
+ assert_equal(false, context.validate?)
183
+ assert_equal('1.0', context.version)
184
+ assert_equal(false, context.well_formed?)
185
+ end
186
186
  end
data/test/tc_reader.rb CHANGED
@@ -1,284 +1,284 @@
1
- require 'xml'
2
- require 'stringio'
3
- require 'test/unit'
4
-
5
- class TestReader < Test::Unit::TestCase
6
- XML_FILE = File.join(File.dirname(__FILE__), 'model/atom.xml')
7
-
8
- def verify_simple(reader)
9
- node_types = []
10
-
11
- # Read each node
12
- 26.times do
13
- assert(reader.read)
14
- node_types << reader.node_type
15
- end
16
-
17
- # There are no more nodes
18
- assert(!reader.read)
19
-
20
- # Check what was read
21
- expected = [XML::Reader::TYPE_PROCESSING_INSTRUCTION,
22
- XML::Reader::TYPE_ELEMENT,
23
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
24
- XML::Reader::TYPE_COMMENT,
25
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
26
- XML::Reader::TYPE_ELEMENT,
27
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
28
- XML::Reader::TYPE_ELEMENT,
29
- XML::Reader::TYPE_CDATA,
30
- XML::Reader::TYPE_END_ELEMENT,
31
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
32
- XML::Reader::TYPE_ELEMENT,
33
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
34
- XML::Reader::TYPE_ELEMENT,
35
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
36
- XML::Reader::TYPE_ELEMENT,
37
- XML::Reader::TYPE_TEXT,
38
- XML::Reader::TYPE_END_ELEMENT,
39
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
40
- XML::Reader::TYPE_END_ELEMENT,
41
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
42
- XML::Reader::TYPE_END_ELEMENT,
43
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
44
- XML::Reader::TYPE_END_ELEMENT,
45
- XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
46
- XML::Reader::TYPE_END_ELEMENT]
47
-
48
- assert_equal(expected, node_types)
49
- end
50
-
51
- def test_document
52
- reader = XML::Reader.document(XML::Document.file(XML_FILE))
53
- verify_simple(reader)
54
- end
55
-
56
- def test_file
57
- reader = XML::Reader.file(XML_FILE)
58
- verify_simple(reader)
59
- end
60
-
61
- def test_invalid_file
62
- assert_raise(XML::Error) do
63
- XML::Reader.file('/does/not/exist')
64
- end
65
- end
66
-
67
- def test_string
68
- reader = XML::Reader.string(File.read(XML_FILE))
69
- verify_simple(reader)
70
- end
71
-
72
- def test_io
73
- File.open(XML_FILE, 'rb') do |io|
74
- reader = XML::Reader.io(io)
75
- verify_simple(reader)
76
- end
77
- end
78
-
79
- def test_io_gc
80
- # Test that the reader keeps a reference
81
- # to the io object
82
- file = File.open(XML_FILE, 'rb')
83
- reader = XML::Reader.io(file)
84
- file = nil
85
- GC.start
86
- assert(reader.read)
87
- end
88
-
89
- def test_string_io
90
- data = File.read(XML_FILE)
91
- string_io = StringIO.new(data)
92
- reader = XML::Reader.io(string_io)
93
- verify_simple(reader)
94
- end
95
-
96
- def test_error
97
- reader = XML::Reader.string('<foo blah')
98
-
99
- error = assert_raise(XML::Error) do
100
- reader.read
101
- end
102
- assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", error.to_s)
103
- end
104
-
105
- def test_deprecated_error_handler
106
- called = false
107
- reader = XML::Reader.string('<foo blah')
108
- reader.set_error_handler do |error|
109
- called = true
110
- end
111
-
112
- assert_raise(XML::Error) do
113
- reader.read
114
- end
115
-
116
- assert(called)
117
- end
118
-
119
- def test_deprecated_reset_error_handler
120
- called = false
121
- reader = XML::Reader.string('<foo blah')
122
- reader.set_error_handler do |error|
123
- called = true
124
- end
125
- reader.reset_error_handler
126
-
127
- assert_raise(XML::Error) do
128
- reader.read
129
- end
130
-
131
- assert(!called)
132
- end
133
-
134
- def test_attr
135
- parser = XML::Reader.string("<foo x='1' y='2'/>")
136
- assert(parser.read)
137
- assert_equal('foo', parser.name)
138
- assert_equal('1', parser['x'])
139
- assert_equal('1', parser[0])
140
- assert_equal('2', parser['y'])
141
- assert_equal('2', parser[1])
142
- assert_equal(nil, parser['z'])
143
- assert_equal(nil, parser[2])
144
- end
145
-
146
- def test_value
147
- parser = XML::Reader.string("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
148
- assert(parser.read)
149
- assert_equal('foo', parser.name)
150
- assert_equal(nil, parser.value)
151
- 3.times do |i|
152
- assert(parser.read)
153
- assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
154
- assert_equal('bar', parser.name)
155
- assert(parser.read)
156
- assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
157
- assert_equal((i + 1).to_s, parser.value)
158
- assert(parser.read)
159
- assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
160
- end
161
- end
162
-
163
- def test_expand
164
- reader = XML::Reader.file(XML_FILE)
165
- reader.read
166
- node = reader.expand
167
- doc = node.doc
168
- reader.close
169
- GC.start
170
-
171
- doc.standalone?
172
- end
173
-
174
- def test_mode
175
- reader = XML::Reader.string('<xml/>')
176
- assert_equal(XML::Reader::MODE_INITIAL, reader.read_state)
177
- reader.read
178
- assert_equal(XML::Reader::MODE_EOF, reader.read_state)
179
- end
180
-
181
- def test_bytes_consumed
182
- reader = XML::Reader.file(XML_FILE)
183
- reader.read
184
- assert_equal(416, reader.byte_consumed)
185
- end
186
-
187
- def test_node
188
- XML.default_line_numbers = true
189
- reader = XML::Reader.file(XML_FILE)
190
-
191
- # first try to get a node
192
- assert_nil(reader.node)
193
-
194
- reader.read
195
- assert_instance_of(XML::Node, reader.node)
196
- end
197
-
198
- def test_base_uri
199
- # UTF8:
200
- # ö - c3 b6 in hex, \303\266 in octal
201
- # ü - c3 bc in hex, \303\274 in octal
202
- xml = "<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>"
203
- reader = XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org")
204
-
205
- reader.read
206
- assert_equal(reader.base_uri, "http://libxml.rubyforge.org")
207
- end
208
-
209
- def test_options
210
- xml = <<-EOS
211
- <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
212
- <test>
213
- <cdata><![CDATA[something]]></cdata>
214
- <entity>&foo;</entity>
215
- </test>
216
- EOS
217
-
218
- # Parse normally
219
- reader = XML::Reader.string(xml)
220
- reader.read # foo
221
- reader.read # test
222
- reader.read # text
223
- reader.read # cdata
224
- reader.read # cdata-section
225
- assert_equal(XML::Node::CDATA_SECTION_NODE, reader.node_type)
226
-
227
- # Convert cdata section to text
228
- reader = XML::Reader.string(xml, :options => XML::Parser::Options::NOCDATA)
229
- reader.read # foo
230
- reader.read # test
231
- reader.read # text
232
- reader.read # cdata
233
- reader.read # cdata-section
234
- assert_equal(XML::Node::TEXT_NODE, reader.node_type)
235
- end
236
-
237
- def test_encoding
238
- # ISO_8859_1:
239
- # ö - f6 in hex, \366 in octal
240
- # ü - fc in hex, \374 in octal
241
- xml = "<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>"
242
-
243
- reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
244
- reader.read
245
-
246
- # libxml converts all data sources to utf8 internally
247
- 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>",
248
- reader.read_outer_xml)
249
- end
250
-
251
- def test_invalid_encoding
252
- # ISO_8859_1:
253
- # ö - f6 in hex, \366 in octal
254
- # ü - fc in hex, \374 in octal
255
- xml = "<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>"
256
-
257
- reader = XML::Reader.string(xml)
258
- error = assert_raise(XML::Error) do
259
- node = reader.read
260
- end
261
-
262
- assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
263
- error.to_s)
264
-
265
- end
266
-
267
- def test_file_encoding
268
- reader = XML::Reader.file(XML_FILE)
269
- reader.read
270
- assert_equal(reader.encoding, XML::Encoding::UTF_8)
271
- end
272
-
273
- def test_string_encoding
274
- # ISO_8859_1:
275
- # ö - f6 in hex, \366 in octal
276
- # ü - fc in hex, \374 in octal
277
- xml = "<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>"
278
- reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
279
- reader.read
280
-
281
- # Encoding is always null for strings, very annoying!
282
- assert_equal(reader.encoding, XML::Encoding::NONE)
283
- end
1
+ require 'xml'
2
+ require 'stringio'
3
+ require 'test/unit'
4
+
5
+ class TestReader < Test::Unit::TestCase
6
+ XML_FILE = File.join(File.dirname(__FILE__), 'model/atom.xml')
7
+
8
+ def verify_simple(reader)
9
+ node_types = []
10
+
11
+ # Read each node
12
+ 26.times do
13
+ assert(reader.read)
14
+ node_types << reader.node_type
15
+ end
16
+
17
+ # There are no more nodes
18
+ assert(!reader.read)
19
+
20
+ # Check what was read
21
+ expected = [XML::Reader::TYPE_PROCESSING_INSTRUCTION,
22
+ XML::Reader::TYPE_ELEMENT,
23
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
24
+ XML::Reader::TYPE_COMMENT,
25
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
26
+ XML::Reader::TYPE_ELEMENT,
27
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
28
+ XML::Reader::TYPE_ELEMENT,
29
+ XML::Reader::TYPE_CDATA,
30
+ XML::Reader::TYPE_END_ELEMENT,
31
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
32
+ XML::Reader::TYPE_ELEMENT,
33
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
34
+ XML::Reader::TYPE_ELEMENT,
35
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
36
+ XML::Reader::TYPE_ELEMENT,
37
+ XML::Reader::TYPE_TEXT,
38
+ XML::Reader::TYPE_END_ELEMENT,
39
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
40
+ XML::Reader::TYPE_END_ELEMENT,
41
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
42
+ XML::Reader::TYPE_END_ELEMENT,
43
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
44
+ XML::Reader::TYPE_END_ELEMENT,
45
+ XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
46
+ XML::Reader::TYPE_END_ELEMENT]
47
+
48
+ assert_equal(expected, node_types)
49
+ end
50
+
51
+ def test_document
52
+ reader = XML::Reader.document(XML::Document.file(XML_FILE))
53
+ verify_simple(reader)
54
+ end
55
+
56
+ def test_file
57
+ reader = XML::Reader.file(XML_FILE)
58
+ verify_simple(reader)
59
+ end
60
+
61
+ def test_invalid_file
62
+ assert_raise(XML::Error) do
63
+ XML::Reader.file('/does/not/exist')
64
+ end
65
+ end
66
+
67
+ def test_string
68
+ reader = XML::Reader.string(File.read(XML_FILE))
69
+ verify_simple(reader)
70
+ end
71
+
72
+ def test_io
73
+ File.open(XML_FILE, 'rb') do |io|
74
+ reader = XML::Reader.io(io)
75
+ verify_simple(reader)
76
+ end
77
+ end
78
+
79
+ def test_io_gc
80
+ # Test that the reader keeps a reference
81
+ # to the io object
82
+ file = File.open(XML_FILE, 'rb')
83
+ reader = XML::Reader.io(file)
84
+ file = nil
85
+ GC.start
86
+ assert(reader.read)
87
+ end
88
+
89
+ def test_string_io
90
+ data = File.read(XML_FILE)
91
+ string_io = StringIO.new(data)
92
+ reader = XML::Reader.io(string_io)
93
+ verify_simple(reader)
94
+ end
95
+
96
+ def test_error
97
+ reader = XML::Reader.string('<foo blah')
98
+
99
+ error = assert_raise(XML::Error) do
100
+ reader.read
101
+ end
102
+ assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", error.to_s)
103
+ end
104
+
105
+ def test_deprecated_error_handler
106
+ called = false
107
+ reader = XML::Reader.string('<foo blah')
108
+ reader.set_error_handler do |error|
109
+ called = true
110
+ end
111
+
112
+ assert_raise(XML::Error) do
113
+ reader.read
114
+ end
115
+
116
+ assert(called)
117
+ end
118
+
119
+ def test_deprecated_reset_error_handler
120
+ called = false
121
+ reader = XML::Reader.string('<foo blah')
122
+ reader.set_error_handler do |error|
123
+ called = true
124
+ end
125
+ reader.reset_error_handler
126
+
127
+ assert_raise(XML::Error) do
128
+ reader.read
129
+ end
130
+
131
+ assert(!called)
132
+ end
133
+
134
+ def test_attr
135
+ parser = XML::Reader.string("<foo x='1' y='2'/>")
136
+ assert(parser.read)
137
+ assert_equal('foo', parser.name)
138
+ assert_equal('1', parser['x'])
139
+ assert_equal('1', parser[0])
140
+ assert_equal('2', parser['y'])
141
+ assert_equal('2', parser[1])
142
+ assert_equal(nil, parser['z'])
143
+ assert_equal(nil, parser[2])
144
+ end
145
+
146
+ def test_value
147
+ parser = XML::Reader.string("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
148
+ assert(parser.read)
149
+ assert_equal('foo', parser.name)
150
+ assert_equal(nil, parser.value)
151
+ 3.times do |i|
152
+ assert(parser.read)
153
+ assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
154
+ assert_equal('bar', parser.name)
155
+ assert(parser.read)
156
+ assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
157
+ assert_equal((i + 1).to_s, parser.value)
158
+ assert(parser.read)
159
+ assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
160
+ end
161
+ end
162
+
163
+ def test_expand
164
+ reader = XML::Reader.file(XML_FILE)
165
+ reader.read
166
+ node = reader.expand
167
+ doc = node.doc
168
+ reader.close
169
+ GC.start
170
+
171
+ doc.standalone?
172
+ end
173
+
174
+ def test_mode
175
+ reader = XML::Reader.string('<xml/>')
176
+ assert_equal(XML::Reader::MODE_INITIAL, reader.read_state)
177
+ reader.read
178
+ assert_equal(XML::Reader::MODE_EOF, reader.read_state)
179
+ end
180
+
181
+ def test_bytes_consumed
182
+ reader = XML::Reader.file(XML_FILE)
183
+ reader.read
184
+ assert_equal(416, reader.byte_consumed)
185
+ end
186
+
187
+ def test_node
188
+ XML.default_line_numbers = true
189
+ reader = XML::Reader.file(XML_FILE)
190
+
191
+ # first try to get a node
192
+ assert_nil(reader.node)
193
+
194
+ reader.read
195
+ assert_instance_of(XML::Node, reader.node)
196
+ end
197
+
198
+ def test_base_uri
199
+ # UTF8:
200
+ # ö - c3 b6 in hex, \303\266 in octal
201
+ # ü - c3 bc in hex, \303\274 in octal
202
+ xml = "<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>"
203
+ reader = XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org")
204
+
205
+ reader.read
206
+ assert_equal(reader.base_uri, "http://libxml.rubyforge.org")
207
+ end
208
+
209
+ def test_options
210
+ xml = <<-EOS
211
+ <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
212
+ <test>
213
+ <cdata><![CDATA[something]]></cdata>
214
+ <entity>&foo;</entity>
215
+ </test>
216
+ EOS
217
+
218
+ # Parse normally
219
+ reader = XML::Reader.string(xml)
220
+ reader.read # foo
221
+ reader.read # test
222
+ reader.read # text
223
+ reader.read # cdata
224
+ reader.read # cdata-section
225
+ assert_equal(XML::Node::CDATA_SECTION_NODE, reader.node_type)
226
+
227
+ # Convert cdata section to text
228
+ reader = XML::Reader.string(xml, :options => XML::Parser::Options::NOCDATA)
229
+ reader.read # foo
230
+ reader.read # test
231
+ reader.read # text
232
+ reader.read # cdata
233
+ reader.read # cdata-section
234
+ assert_equal(XML::Node::TEXT_NODE, reader.node_type)
235
+ end
236
+
237
+ def test_encoding
238
+ # ISO_8859_1:
239
+ # ö - f6 in hex, \366 in octal
240
+ # ü - fc in hex, \374 in octal
241
+ xml = "<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>"
242
+
243
+ reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
244
+ reader.read
245
+
246
+ # libxml converts all data sources to utf8 internally
247
+ 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>",
248
+ reader.read_outer_xml)
249
+ end
250
+
251
+ def test_invalid_encoding
252
+ # ISO_8859_1:
253
+ # ö - f6 in hex, \366 in octal
254
+ # ü - fc in hex, \374 in octal
255
+ xml = "<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>"
256
+
257
+ reader = XML::Reader.string(xml)
258
+ error = assert_raise(XML::Error) do
259
+ node = reader.read
260
+ end
261
+
262
+ assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
263
+ error.to_s)
264
+
265
+ end
266
+
267
+ def test_file_encoding
268
+ reader = XML::Reader.file(XML_FILE)
269
+ reader.read
270
+ assert_equal(reader.encoding, XML::Encoding::UTF_8)
271
+ end
272
+
273
+ def test_string_encoding
274
+ # ISO_8859_1:
275
+ # ö - f6 in hex, \366 in octal
276
+ # ü - fc in hex, \374 in octal
277
+ xml = "<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>"
278
+ reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
279
+ reader.read
280
+
281
+ # Encoding is always null for strings, very annoying!
282
+ assert_equal(reader.encoding, XML::Encoding::NONE)
283
+ end
284
284
  end