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

Sign up to get free protection for your applications and to get access to all the features.
data/test/model/atom.xml CHANGED
@@ -1,4 +1,13 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
+ <?xml-stylesheet type="text/xsl" href="my_stylesheet.xsl"?>
2
3
  <feed xmlns="http://www.w3.org/2005/Atom">
3
- <title type="text">Phil Bogle's Contacts</title>
4
+ <!-- Not a valid atom entry -->
5
+ <entry>
6
+ <title type="html"><![CDATA[<<strong>>]]></title>
7
+ <content type="xhtml">
8
+ <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">
9
+ <xhtml:p>hi there</xhtml:p>
10
+ </xhtml:div>
11
+ </content>
12
+ </entry>
4
13
  </feed>
data/test/tc_node_text.rb CHANGED
@@ -14,4 +14,4 @@ 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
+ end
data/test/tc_reader.rb CHANGED
@@ -34,75 +34,75 @@ class TestReader < Test::Unit::TestCase
34
34
  XML::Reader::TYPE_END_ELEMENT])
35
35
  end
36
36
 
37
- # def test_file
38
- # reader = XML::Reader.file(SIMPLE_XML)
39
- # verify_simple(reader)
40
- # end
41
- #
42
- # def test_invalid_file
43
- # assert_raises(RuntimeError) do
44
- # XML::Reader.file('/does/not/exist')
45
- # end
46
- # end
47
- #
48
- # def test_string
49
- # reader = XML::Reader.string(File.read(SIMPLE_XML))
50
- # verify_simple(reader)
51
- # end
52
- #
53
- # def test_io
54
- # File.open(SIMPLE_XML, 'rb') do |io|
55
- # reader = XML::Reader.io(io)
56
- # verify_simple(reader)
57
- # end
58
- # end
59
- #
60
- # def test_string_io
61
- # data = File.read(SIMPLE_XML)
62
- # string_io = StringIO.new(data)
63
- # reader = XML::Reader.io(string_io)
64
- # verify_simple(reader)
65
- # end
66
- #
67
- # def test_new_walker
68
- # reader = XML::Reader.walker(XML::Document.file(SIMPLE_XML))
69
- # verify_simple(reader)
70
- # end
71
- #
72
- # def test_deprecated_error_handler
73
- # called = false
74
- # reader = XML::Reader.new('<foo blah')
75
- # reader.set_error_handler do |error|
76
- # called = true
77
- # end
78
- #
79
- # reader.read
80
- # assert(called)
81
- # end
82
- #
83
- # def test_deprecated_reset_error_handler
84
- # called = false
85
- # reader = XML::Reader.new('<foo blah')
86
- # reader.set_error_handler do |error|
87
- # called = true
88
- # end
89
- # reader.reset_error_handler
90
- #
91
- # reader.read
92
- # assert(!called)
93
- # end
94
- #
95
- # def test_attr
96
- # parser = XML::Reader.new("<foo x='1' y='2'/>")
97
- # assert_equal(1, parser.read)
98
- # assert_equal('foo', parser.name)
99
- # assert_equal('1', parser['x'])
100
- # assert_equal('1', parser[0])
101
- # assert_equal('2', parser['y'])
102
- # assert_equal('2', parser[1])
103
- # assert_equal(nil, parser['z'])
104
- # assert_equal(nil, parser[2])
105
- # end
37
+ def test_file
38
+ reader = XML::Reader.file(SIMPLE_XML)
39
+ verify_simple(reader)
40
+ end
41
+
42
+ def test_invalid_file
43
+ assert_raises(XML::Error) do
44
+ XML::Reader.file('/does/not/exist')
45
+ end
46
+ end
47
+
48
+ def test_string
49
+ reader = XML::Reader.string(File.read(SIMPLE_XML))
50
+ verify_simple(reader)
51
+ end
52
+
53
+ def test_io
54
+ File.open(SIMPLE_XML, 'rb') do |io|
55
+ reader = XML::Reader.io(io)
56
+ verify_simple(reader)
57
+ end
58
+ end
59
+
60
+ def test_string_io
61
+ data = File.read(SIMPLE_XML)
62
+ string_io = StringIO.new(data)
63
+ reader = XML::Reader.io(string_io)
64
+ verify_simple(reader)
65
+ end
66
+
67
+ def test_new_walker
68
+ reader = XML::Reader.walker(XML::Document.file(SIMPLE_XML))
69
+ verify_simple(reader)
70
+ end
71
+
72
+ def test_deprecated_error_handler
73
+ called = false
74
+ reader = XML::Reader.new('<foo blah')
75
+ reader.set_error_handler do |error|
76
+ called = true
77
+ end
78
+
79
+ reader.read
80
+ assert(called)
81
+ end
82
+
83
+ def test_deprecated_reset_error_handler
84
+ called = false
85
+ reader = XML::Reader.new('<foo blah')
86
+ reader.set_error_handler do |error|
87
+ called = true
88
+ end
89
+ reader.reset_error_handler
90
+
91
+ reader.read
92
+ assert(!called)
93
+ end
94
+
95
+ def test_attr
96
+ parser = XML::Reader.new("<foo x='1' y='2'/>")
97
+ assert_equal(1, parser.read)
98
+ assert_equal('foo', parser.name)
99
+ assert_equal('1', parser['x'])
100
+ assert_equal('1', parser[0])
101
+ assert_equal('2', parser['y'])
102
+ assert_equal('2', parser[1])
103
+ assert_equal(nil, parser['z'])
104
+ assert_equal(nil, parser[2])
105
+ end
106
106
 
107
107
  def test_value
108
108
  parser = XML::Reader.new("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
@@ -121,21 +121,21 @@ class TestReader < Test::Unit::TestCase
121
121
  end
122
122
  end
123
123
 
124
- # def test_expand
125
- # reader = XML::Reader.file(SIMPLE_XML)
126
- # reader.read
127
- # node = reader.expand
128
- # doc = node.doc
129
- # reader.close
130
- # GC.start
131
- #
132
- # doc.standalone?
133
- # end
134
- #
135
- # def test_mode
136
- # reader = XML::Reader.string('<xml/>')
137
- # assert_equal(XML::Reader::MODE_INITIAL, reader.read_state)
138
- # reader.read
139
- # assert_equal(XML::Reader::MODE_EOF, reader.read_state)
140
- # end
124
+ def test_expand
125
+ reader = XML::Reader.file(SIMPLE_XML)
126
+ reader.read
127
+ node = reader.expand
128
+ doc = node.doc
129
+ reader.close
130
+ GC.start
131
+
132
+ doc.standalone?
133
+ end
134
+
135
+ def test_mode
136
+ reader = XML::Reader.string('<xml/>')
137
+ assert_equal(XML::Reader::MODE_INITIAL, reader.read_state)
138
+ reader.read
139
+ assert_equal(XML::Reader::MODE_EOF, reader.read_state)
140
+ end
141
141
  end
@@ -1,5 +1,6 @@
1
1
  require 'xml'
2
2
  require 'test/unit'
3
+ require 'pp'
3
4
 
4
5
  class DocTypeCallback
5
6
  include XML::SaxParser::Callbacks
@@ -10,72 +11,122 @@ end
10
11
  class TestCaseCallbacks
11
12
  include XML::SaxParser::Callbacks
12
13
 
13
- attr_accessor :test
14
+ attr_accessor :result
14
15
 
15
16
  def initialize
16
- @test = Hash.new { |h,k| h[k] = [] }
17
- @i = 0
17
+ @result = Array.new
18
18
  end
19
19
 
20
- def on_start_document
21
- @test[:startdoc] << @i+=1
20
+ def on_cdata_block(cdata)
21
+ @result << "cdata: #{cdata}"
22
22
  end
23
23
 
24
- def on_start_element(name, attr_hash)
25
- @test[:startel] << [@i+=1,name,attr_hash]
24
+ def on_characters(chars)
25
+ @result << "characters: #{chars}"
26
26
  end
27
27
 
28
- def on_characters(chars)
29
- @test[:chars] << [@i+=1,chars]
28
+ def on_comment(text)
29
+ @result << "comment: #{text}"
30
30
  end
31
31
 
32
- def on_comment(msg)
33
- @test[:comment] << [@i+=1,msg]
32
+ def on_end_document
33
+ @result << "end_document"
34
+ end
35
+
36
+ def on_end_element(name)
37
+ @result << "end_element: #{name}"
38
+ end
39
+
40
+ def on_end_element_ns(name, prefix, uri)
41
+ @result << "end_element_ns #{name}, prefix: #{prefix}, uri: #{uri}"
42
+ end
43
+
44
+ # Called for parser errors.
45
+ def on_error(error)
46
+ @result << "error: #{error}"
34
47
  end
35
48
 
36
49
  def on_processing_instruction(target, data)
37
- @test[:pinstr] << [@i+=1, target, data]
50
+ @result << "pi: #{target} #{data}"
38
51
  end
39
52
 
40
- def on_cdata_block(cdata)
41
- @test[:cdata] << [@i+=1,cdata]
53
+ def on_start_document
54
+ @result << "startdoc"
42
55
  end
43
56
 
44
- def on_end_element(name)
45
- @test[:endel] << [@i+=1,name]
57
+ def on_start_element(name, attributes)
58
+ attributes ||= Hash.new
59
+ @result << "start_element: #{name}, attr: #{attributes.inspect}"
46
60
  end
47
61
 
48
- def on_end_document
49
- @test[:enddoc] << @i+=1
62
+ def on_start_element_ns(name, attributes, prefix, uri, namespaces)
63
+ attributes ||= Hash.new
64
+ namespaces ||= Hash.new
65
+ @result << "start_element_ns: #{name}, attr: #{attributes.inspect}, prefix: #{prefix}, uri: #{uri}, ns: #{namespaces.inspect}"
50
66
  end
51
67
  end
52
68
 
53
69
  class TestSaxParser < Test::Unit::TestCase
54
70
  def setup
71
+ XML.default_keep_blanks = true
55
72
  @xp = XML::SaxParser.new
56
73
  end
57
74
 
58
75
  def teardown
59
76
  @xp = nil
77
+ XML.default_keep_blanks = true
60
78
  end
61
79
 
62
80
  def saxtest_file
63
- File.join(File.dirname(__FILE__), 'model/saxtest.xml')
81
+ File.join(File.dirname(__FILE__), 'model/atom.xml')
64
82
  end
65
83
 
66
84
  def verify
67
- assert_equal [1], @xp.callbacks.test[:startdoc]
68
- assert_equal [[2,'test',{'uga'=>'booga','foo'=>'bar'}],[3,'fixnum',{}],[6,'fixnum',{}]],
69
- @xp.callbacks.test[:startel]
70
- assert_equal [[4,'one'],[7,'two'],[9,"\n "],[11,"\n "],[13,"\n "],[15,"\n"]],
71
- @xp.callbacks.test[:chars]
72
- assert_equal [[10, ' msg ']], @xp.callbacks.test[:comment]
73
- assert_equal [[12, 'custom', 'foo="bar"']], @xp.callbacks.test[:pinstr]
74
- assert_equal [[14, 'here it goes']], @xp.callbacks.test[:cdata]
75
- assert_equal [[5,'fixnum'],[8,'fixnum'],[16,'test']], @xp.callbacks.test[:endel]
76
- assert_equal [17], @xp.callbacks.test[:enddoc]
77
- end
78
-
85
+ result = @xp.callbacks.result
86
+
87
+ i = -1
88
+ assert_equal("startdoc", result[i+=1])
89
+ assert_equal("pi: xml-stylesheet type=\"text/xsl\" href=\"my_stylesheet.xsl\"", result[i+=1])
90
+ assert_equal("start_element: feed, attr: {nil=>\"http://www.w3.org/2005/Atom\"}", result[i+=1])
91
+ assert_equal("start_element_ns: feed, attr: {nil=>\"http://www.w3.org/2005/Atom\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
92
+ assert_equal("characters: \n ", result[i+=1])
93
+ assert_equal("comment: Not a valid atom entry ", result[i+=1])
94
+ assert_equal("characters: \n ", result[i+=1])
95
+ assert_equal("start_element: entry, attr: {}", result[i+=1])
96
+ assert_equal("start_element_ns: entry, attr: {}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
97
+ assert_equal("characters: \n ", result[i+=1])
98
+ assert_equal("start_element: title, attr: {\"type\"=>\"html\"}", result[i+=1])
99
+ assert_equal("start_element_ns: title, attr: {\"type\"=>\"html\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
100
+ assert_equal("cdata: <<strong>>", result[i+=1])
101
+ assert_equal("end_element: title", result[i+=1])
102
+ assert_equal("end_element_ns title, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
103
+ assert_equal("characters: \n ", result[i+=1])
104
+ assert_equal("start_element: content, attr: {\"type\"=>\"xhtml\"}", result[i+=1])
105
+ assert_equal("start_element_ns: content, attr: {\"type\"=>\"xhtml\"}, prefix: , uri: http://www.w3.org/2005/Atom, ns: {}", result[i+=1])
106
+ assert_equal("characters: \n ", result[i+=1])
107
+ assert_equal("start_element: xhtml:div, attr: {\"xhtml\"=>\"http://www.w3.org/1999/xhtml\"}", result[i+=1])
108
+ assert_equal("start_element_ns: div, attr: {\"xhtml\"=>\"http://www.w3.org/1999/xhtml\"}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
109
+ assert_equal("characters: \n ", result[i+=1])
110
+ assert_equal("start_element: xhtml:p, attr: {}", result[i+=1])
111
+ assert_equal("start_element_ns: p, attr: {}, prefix: xhtml, uri: http://www.w3.org/1999/xhtml, ns: {}", result[i+=1])
112
+ assert_equal("characters: hi there", result[i+=1])
113
+ assert_equal("end_element: xhtml:p", result[i+=1])
114
+ assert_equal("end_element_ns p, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
115
+ assert_equal("characters: \n ", result[i+=1])
116
+ assert_equal("end_element: xhtml:div", result[i+=1])
117
+ assert_equal("end_element_ns div, prefix: xhtml, uri: http://www.w3.org/1999/xhtml", result[i+=1])
118
+ assert_equal("characters: \n ", result[i+=1])
119
+ assert_equal("end_element: content", result[i+=1])
120
+ assert_equal("end_element_ns content, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
121
+ assert_equal("characters: \n ", result[i+=1])
122
+ assert_equal("end_element: entry", result[i+=1])
123
+ assert_equal("end_element_ns entry, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
124
+ assert_equal("characters: \n", result[i+=1])
125
+ assert_equal("end_element: feed", result[i+=1])
126
+ assert_equal("end_element_ns feed, prefix: , uri: http://www.w3.org/2005/Atom", result[i+=1])
127
+ assert_equal("end_document", result[i+=1])
128
+ end
129
+
79
130
  def test_string_no_callbacks
80
131
  @xp.string = File.read(saxtest_file)
81
132
  assert_equal true, @xp.parse
@@ -131,26 +182,60 @@ EOS
131
182
  assert_not_nil(doc)
132
183
  end
133
184
 
185
+
186
+ def test_parse_warning
187
+ @xp.callbacks = TestCaseCallbacks.new
188
+ # Two xml PIs is a warning
189
+ @xp.string = <<-EOS
190
+ <?xml version="1.0" encoding="utf-8"?>
191
+ <?xml-invalid?>
192
+ <Test/>
193
+ EOS
194
+
195
+ @xp.parse
196
+
197
+ # Check callbacks
198
+ result = @xp.callbacks.result
199
+ i = -1
200
+ assert_equal("startdoc", result[i+=1])
201
+ assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
202
+ assert_equal("pi: xml-invalid ", result[i+=1])
203
+ assert_equal("start_element: Test, attr: {}", result[i+=1])
204
+ assert_equal("start_element_ns: Test, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
205
+ assert_equal("end_element: Test", result[i+=1])
206
+ assert_equal("end_element_ns Test, prefix: , uri: ", result[i+=1])
207
+ assert_equal("end_document", result[i+=1])
208
+ end
209
+
134
210
  def test_parse_error
135
211
  @xp.callbacks = TestCaseCallbacks.new
136
212
  @xp.string = <<-EOS
137
213
  <Results>
138
- <a>a1
139
- </Results>
140
214
  EOS
141
215
 
142
216
  error = assert_raise(XML::Error) do
143
217
  doc = @xp.parse
144
218
  end
145
219
 
220
+ # Check callbacks
221
+ result = @xp.callbacks.result
222
+
223
+ i = -1
224
+ assert_equal("startdoc", result[i+=1])
225
+ assert_equal("start_element: Results, attr: {}", result[i+=1])
226
+ assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
227
+ assert_equal("characters: \n", result[i+=1])
228
+ assert_equal("error: Fatal error: Premature end of data in tag Results line 1 at :2.", result[i+=1])
229
+ assert_equal("end_document", result[i+=1])
230
+
146
231
  assert_not_nil(error)
147
232
  assert_kind_of(XML::Error, error)
148
- assert_equal("Fatal error: Premature end of data in tag Results line 1 at :4.", error.message)
233
+ assert_equal("Fatal error: Premature end of data in tag Results line 1 at :2.", error.message)
149
234
  assert_equal(XML::Error::PARSER, error.domain)
150
235
  assert_equal(XML::Error::TAG_NOT_FINISHED, error.code)
151
236
  assert_equal(XML::Error::FATAL, error.level)
152
237
  assert_nil(error.file)
153
- assert_equal(4, error.line)
238
+ assert_equal(2, error.line)
154
239
  assert_equal('Results', error.str1)
155
240
  assert_nil(error.str2)
156
241
  assert_nil(error.str3)
@@ -8,5 +8,4 @@ class TestWellFormed < Test::Unit::TestCase
8
8
  parser.parse
9
9
  assert(parser.context.well_formed?)
10
10
  end
11
- end
12
-
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libxml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: x86-mswin32-60
6
6
  authors:
7
7
  - Charlie Savage
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-07 00:00:00 -07:00
12
+ date: 2008-12-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,9 +23,9 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - Rakefile
26
- - README
27
- - LICENSE
28
26
  - CHANGES
27
+ - LICENSE
28
+ - README
29
29
  - setup.rb
30
30
  - doc/css
31
31
  - doc/css/normal.css
@@ -44,7 +44,6 @@ files:
44
44
  - ext/libxml/cbg.c
45
45
  - ext/libxml/extconf.rb
46
46
  - ext/libxml/libxml.c
47
- - ext/libxml/libxml.c.rej
48
47
  - ext/libxml/ruby_libxml.h
49
48
  - ext/libxml/ruby_xml_attr.c
50
49
  - ext/libxml/ruby_xml_attr.h
@@ -76,6 +75,8 @@ files:
76
75
  - ext/libxml/ruby_xml_reader.h
77
76
  - ext/libxml/ruby_xml_relaxng.c
78
77
  - ext/libxml/ruby_xml_relaxng.h
78
+ - ext/libxml/ruby_xml_sax2_handler.c
79
+ - ext/libxml/ruby_xml_sax2_handler.h
79
80
  - ext/libxml/ruby_xml_sax_parser.c
80
81
  - ext/libxml/ruby_xml_sax_parser.h
81
82
  - ext/libxml/ruby_xml_schema.c
@@ -94,7 +95,6 @@ files:
94
95
  - ext/libxml/ruby_xml_xpath_object.h
95
96
  - ext/libxml/ruby_xml_xpointer.c
96
97
  - ext/libxml/ruby_xml_xpointer.h
97
- - ext/libxml/sax_parser_callbacks.inc
98
98
  - ext/libxml/version.h
99
99
  - ext/mingw/Rakefile
100
100
  - ext/mingw/build.rake
@@ -139,7 +139,6 @@ files:
139
139
  - test/model/ruby-lang.html
140
140
  - test/model/rubynet.xml
141
141
  - test/model/rubynet_project
142
- - test/model/saxtest.xml
143
142
  - test/model/shiporder.rnc
144
143
  - test/model/shiporder.rng
145
144
  - test/model/shiporder.xml