nokogiri 1.6.8.rc3-x86-mingw32 → 1.6.8-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

@@ -422,6 +422,19 @@ module Nokogiri
422
422
  old_node = @node.at('.//employee')
423
423
  assert_raises(ArgumentError){ old_node.replace new_node }
424
424
  end
425
+
426
+ def test_unlink_on_unlinked_node_1
427
+ node = Nokogiri::XML::Node.new 'div', Nokogiri::XML::Document.new
428
+ node.unlink # must_not_raise
429
+ assert_nil node.parent
430
+ end
431
+
432
+ def test_unlink_on_unlinked_node_2
433
+ node = Nokogiri::XML('<div>foo</div>').at_css("div")
434
+ node.unlink
435
+ node.unlink # must_not_raise
436
+ assert_nil node.parent
437
+ end
425
438
  end
426
439
  end
427
440
  end
data/test_all CHANGED
@@ -25,13 +25,12 @@ RUBIES="\
25
25
  TEST_LOG=test.log
26
26
  VALGRIND_LOG=valgrind.log
27
27
 
28
- if ! grep libxml-ruby Gemfile ; then
29
- echo "ERROR: please add this line your Gemfile temporarily so we can run libxml-ruby tests:"
30
- echo
31
- echo "gem 'libxml-ruby', :platform => :mri"
32
- echo
33
- exit 1
34
- fi
28
+ # make sure we can test with libxml-ruby installed
29
+ export BUNDLE_GEMFILE="$(pwd)/Gemfile_test_all"
30
+ cat > $BUNDLE_GEMFILE <<EOF
31
+ gem "libxml-ruby", :platform => :mri, :require => false
32
+ eval_gemfile File.join(File.dirname(ENV['BUNDLE_GEMFILE']),"Gemfile")
33
+ EOF
35
34
 
36
35
  # Load RVM into a shell session *as a function*
37
36
  if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
@@ -51,20 +50,12 @@ function rvm_use {
51
50
  rvm use "${1}@nokogiri" --create
52
51
  }
53
52
 
54
- function generate_parser_and_tokenizer {
55
- old_ruby=$current_ruby
56
- rvm_use ruby-1.9.3
57
- bundle exec rake generate 2>&1 > /dev/null
58
- rvm_use $old_ruby
59
- }
60
-
61
53
  function clean {
62
54
  bundle exec rake clean clobber 2>&1 > /dev/null
63
55
  }
64
56
 
65
57
  function compile {
66
58
  echo "** compiling ..."
67
- # generate_parser_and_tokenizer
68
59
  bundle exec rake compile 2>&1 > /dev/null
69
60
  }
70
61
 
@@ -75,9 +66,9 @@ done
75
66
 
76
67
  for ruby in $RUBIES ; do
77
68
  rvm_use ${ruby}
78
- if ! [[ $(bundle -v) =~ "1.10." ]] ; then
69
+ if ! [[ $(bundle -v) =~ "1.12." ]] ; then
79
70
  yes | gem uninstall --force bundler
80
- gem install bundler -v 1.10.6
71
+ gem install bundler -v 1.12.5
81
72
  bundle -v
82
73
  fi
83
74
  bundle install --quiet --local || bundle install
@@ -85,32 +76,32 @@ for ruby in $RUBIES ; do
85
76
  done
86
77
 
87
78
  for ruby in $RUBIES ; do
79
+ rvm_use ${ruby}
80
+ echo -e "**\n** testing nokogiri on ${ruby}\n**"
81
+ clean
82
+ compile
83
+ echo "** running tests ..."
84
+ bundle exec rake test 2>&1
85
+ if [[ ! $ruby =~ "jruby" ]] ; then
86
+ echo "** running tests again with libxml-ruby loaded ..."
87
+ if ! gem list libxml-ruby | fgrep 2.8.0 ; then
88
+ gem install libxml-ruby
89
+ fi
90
+ bundle exec rake test:libxml-ruby 2>&1
91
+ fi
92
+ clean
93
+ done | tee -a $TEST_LOG
94
+
95
+ for ruby in $RUBIES ; do
96
+ if [[ ! $ruby =~ "jruby" ]] ; then
88
97
  rvm_use ${ruby}
89
- echo -e "**\n** testing nokogiri on ${ruby}\n**" | tee -a $TEST_LOG
98
+ echo -e "**\n** nokogiri prerelease: ${ruby}\n**"
90
99
  clean
91
100
  compile
92
- echo "** running tests ..."
93
- bundle exec rake test 2>&1 | tee -a $TEST_LOG
94
- if [[ ! $ruby =~ "jruby" ]] ; then
95
- echo "** running tests again with libxml-ruby loaded ..."
96
- if ! gem list libxml-ruby | fgrep 2.8.0 ; then
97
- gem install libxml-ruby
98
- fi
99
- bundle exec rake test:libxml-ruby 2>&1 | tee -a $TEST_LOG
100
- fi
101
+ echo "** running valgrind on tests ..."
102
+ bundle exec rake test:valgrind 2>&1
103
+ echo "** running valgrind again with libxml-ruby loaded ..."
104
+ bundle exec rake test:valgrind:libxml-ruby 2>&1
101
105
  clean
102
- done
103
-
104
- for ruby in $RUBIES ; do
105
- if [[ ! $ruby =~ "jruby" ]] ; then
106
- rvm_use ${ruby}
107
- echo -e "**\n** nokogiri prerelease: ${ruby}\n**" | tee -a $VALGRIND_LOG
108
- clean
109
- compile
110
- echo "** running valgrind on tests ..."
111
- bundle exec rake test:valgrind 2>&1 | tee -a $VALGRIND_LOG
112
- echo "** running valgrind again with libxml-ruby loaded ..."
113
- bundle exec rake test:valgrind:libxml-ruby 2>&1 | tee -a $VALGRIND_LOG
114
- clean
115
- fi
116
- done
106
+ fi
107
+ done | tee -a $VALGRIND_LOG
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.8.rc3
4
+ version: 1.6.8
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Aaron Patterson
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-02-17 00:00:00.000000000 Z
15
+ date: 2016-06-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: mini_portile2
@@ -60,16 +60,16 @@ dependencies:
60
60
  name: hoe-bundler
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - ">="
63
+ - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: '1.1'
65
+ version: 1.2.0
66
66
  type: :development
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - ">="
70
+ - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '1.1'
72
+ version: 1.2.0
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: hoe-debugging
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -88,58 +88,58 @@ dependencies:
88
88
  name: hoe-gemspec
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ">="
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '1.0'
93
+ version: 1.0.0
94
94
  type: :development
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - ">="
98
+ - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: '1.0'
100
+ version: 1.0.0
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: hoe-git
103
103
  requirement: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ">="
105
+ - - "~>"
106
106
  - !ruby/object:Gem::Version
107
- version: '1.4'
107
+ version: 1.6.0
108
108
  type: :development
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - ">="
112
+ - - "~>"
113
113
  - !ruby/object:Gem::Version
114
- version: '1.4'
114
+ version: 1.6.0
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: minitest
117
117
  requirement: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
- version: 2.2.2
121
+ version: 5.8.4
122
122
  type: :development
123
123
  prerelease: false
124
124
  version_requirements: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - "~>"
127
127
  - !ruby/object:Gem::Version
128
- version: 2.2.2
128
+ version: 5.8.4
129
129
  - !ruby/object:Gem::Dependency
130
130
  name: rake
131
131
  requirement: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - ">="
133
+ - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: '0.9'
135
+ version: 10.5.0
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - ">="
140
+ - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: '0.9'
142
+ version: 10.5.0
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: rake-compiler
145
145
  requirement: !ruby/object:Gem::Requirement
@@ -172,28 +172,28 @@ dependencies:
172
172
  name: racc
173
173
  requirement: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - ">="
175
+ - - "~>"
176
176
  - !ruby/object:Gem::Version
177
- version: 1.4.6
177
+ version: 1.4.14
178
178
  type: :development
179
179
  prerelease: false
180
180
  version_requirements: !ruby/object:Gem::Requirement
181
181
  requirements:
182
- - - ">="
182
+ - - "~>"
183
183
  - !ruby/object:Gem::Version
184
- version: 1.4.6
184
+ version: 1.4.14
185
185
  - !ruby/object:Gem::Dependency
186
186
  name: rexical
187
187
  requirement: !ruby/object:Gem::Requirement
188
188
  requirements:
189
- - - ">="
189
+ - - "~>"
190
190
  - !ruby/object:Gem::Version
191
191
  version: 1.0.5
192
192
  type: :development
193
193
  prerelease: false
194
194
  version_requirements: !ruby/object:Gem::Requirement
195
195
  requirements:
196
- - - ">="
196
+ - - "~>"
197
197
  - !ruby/object:Gem::Version
198
198
  version: 1.0.5
199
199
  - !ruby/object:Gem::Dependency
@@ -202,21 +202,18 @@ dependencies:
202
202
  requirements:
203
203
  - - "~>"
204
204
  - !ruby/object:Gem::Version
205
- version: '3.14'
205
+ version: '3.15'
206
206
  type: :development
207
207
  prerelease: false
208
208
  version_requirements: !ruby/object:Gem::Requirement
209
209
  requirements:
210
210
  - - "~>"
211
211
  - !ruby/object:Gem::Version
212
- version: '3.14'
212
+ version: '3.15'
213
213
  description: |-
214
214
  Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser. Among
215
215
  Nokogiri's many features is the ability to search documents via XPath
216
216
  or CSS3 selectors.
217
-
218
- XML is like violence - if it doesn’t solve your problems, you are not
219
- using enough of it.
220
217
  email:
221
218
  - aaronp@rubyforge.org
222
219
  - mike.dalessio@gmail.com
@@ -502,7 +499,6 @@ files:
502
499
  - test/test_encoding_handler.rb
503
500
  - test/test_memory_leak.rb
504
501
  - test/test_nokogiri.rb
505
- - test/test_reader.rb
506
502
  - test/test_soap4r_sax.rb
507
503
  - test/test_xslt_transforms.rb
508
504
  - test/xml/node/test_save_options.rb
@@ -534,6 +530,7 @@ files:
534
530
  - test/xml/test_node_set.rb
535
531
  - test/xml/test_parse_options.rb
536
532
  - test/xml/test_processing_instruction.rb
533
+ - test/xml/test_reader.rb
537
534
  - test/xml/test_reader_encoding.rb
538
535
  - test/xml/test_relax_ng.rb
539
536
  - test/xml/test_schema.rb
@@ -549,8 +546,8 @@ homepage: http://nokogiri.org
549
546
  licenses:
550
547
  - MIT
551
548
  metadata: {}
552
- post_install_message: 'Nokogiri is built with the packaged libraries: libxml2-2.9.3,
553
- libxslt-1.1.28, zlib-1.2.8, libiconv-1.14.
549
+ post_install_message: 'Nokogiri is built with the packaged libraries: libxml2-2.9.4,
550
+ libxslt-1.1.29, zlib-1.2.8, libiconv-1.14.
554
551
 
555
552
  '
556
553
  rdoc_options:
@@ -568,9 +565,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
568
565
  version: '2.4'
569
566
  required_rubygems_version: !ruby/object:Gem::Requirement
570
567
  requirements:
571
- - - ">"
568
+ - - ">="
572
569
  - !ruby/object:Gem::Version
573
- version: 1.3.1
570
+ version: '0'
574
571
  requirements: []
575
572
  rubyforge_project:
576
573
  rubygems_version: 2.5.1
@@ -1,577 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "helper"
3
-
4
- class TestReader < Nokogiri::TestCase
5
- def test_from_io_sets_io_as_source
6
- io = File.open SNUGGLES_FILE
7
- reader = Nokogiri::XML::Reader.from_io(io)
8
- assert_equal io, reader.source
9
- end
10
-
11
- def test_empty_element?
12
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
13
- <xml><city>Paris</city><state/></xml>
14
- eoxml
15
-
16
- results = reader.map do |node|
17
- if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
18
- node.empty_element?
19
- end
20
- end
21
- assert_equal [false, false, nil, nil, true, nil], results
22
- end
23
-
24
- def test_self_closing?
25
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
26
- <xml><city>Paris</city><state/></xml>
27
- eoxml
28
-
29
- results = reader.map do |node|
30
- if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
31
- node.self_closing?
32
- end
33
- end
34
- assert_equal [false, false, nil, nil, true, nil], results
35
- end
36
-
37
- # Issue #831
38
- # Make sure that the reader doesn't block reading the entire input
39
- def test_reader_blocking
40
- rd, wr = IO.pipe()
41
- node_out = nil
42
- t = Thread.start do
43
- reader = Nokogiri::XML::Reader(rd, 'UTF-8')
44
- reader.each do |node|
45
- node_out = node
46
- break
47
- end
48
- rd.close
49
- end
50
- sleep(1) # sleep for one second to make sure the reader will actually block for input
51
- begin
52
- wr.puts "<foo>"
53
- wr.puts "<bar/>" * 10000
54
- wr.flush
55
- rescue Errno::EPIPE
56
- end
57
- res = t.join(5) # wait 5 seconds for the thread to finish
58
- wr.close
59
- refute_nil node_out, "Didn't read any nodes, exclude the trivial case"
60
- refute_nil res, "Reader blocks trying to read the entire stream"
61
- end
62
-
63
- def test_reader_takes_block
64
- options = nil
65
- Nokogiri::XML::Reader(File.read(XML_FILE), XML_FILE) do |cfg|
66
- options = cfg
67
- options.nonet.nowarning.dtdattr
68
- end
69
- assert options.nonet?
70
- assert options.nowarning?
71
- assert options.dtdattr?
72
- end
73
-
74
- def test_nil_raises
75
- assert_raises(ArgumentError) {
76
- Nokogiri::XML::Reader.from_memory(nil)
77
- }
78
- assert_raises(ArgumentError) {
79
- Nokogiri::XML::Reader.from_io(nil)
80
- }
81
- end
82
-
83
- def test_from_io
84
- io = File.open SNUGGLES_FILE
85
- reader = Nokogiri::XML::Reader.from_io(io)
86
- assert_equal false, reader.default?
87
- assert_equal [false, false, false, false, false, false, false],
88
- reader.map(&:default?)
89
- end
90
-
91
- def test_io
92
- io = File.open SNUGGLES_FILE
93
- reader = Nokogiri::XML::Reader(io)
94
- assert_equal false, reader.default?
95
- assert_equal [false, false, false, false, false, false, false],
96
- reader.map(&:default?)
97
- end
98
-
99
- def test_string_io
100
- io = StringIO.new(<<-eoxml)
101
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
102
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
103
- </x>
104
- eoxml
105
- reader = Nokogiri::XML::Reader(io)
106
- assert_equal false, reader.default?
107
- assert_equal [false, false, false, false, false, false, false],
108
- reader.map(&:default?)
109
- end
110
-
111
- class ReallyBadIO
112
- def read(size)
113
- 'a' * size ** 10
114
- end
115
- end
116
-
117
- class ReallyBadIO4Java
118
- def read(size=1)
119
- 'a' * size ** 10
120
- end
121
- end
122
-
123
- def test_io_that_reads_too_much
124
- if Nokogiri.jruby?
125
- io = ReallyBadIO4Java.new
126
- Nokogiri::XML::Reader(io)
127
- else
128
- io = ReallyBadIO.new
129
- Nokogiri::XML::Reader(io)
130
- end
131
- end
132
-
133
- def test_in_memory
134
- assert Nokogiri::XML::Reader(<<-eoxml)
135
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
136
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
137
- </x>
138
- eoxml
139
- end
140
-
141
- def test_reader_holds_on_to_string
142
- xml = <<-eoxml
143
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
144
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
145
- </x>
146
- eoxml
147
- reader = Nokogiri::XML::Reader(xml)
148
- assert_equal xml, reader.source
149
- end
150
-
151
- def test_default?
152
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
153
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
154
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
155
- </x>
156
- eoxml
157
- assert_equal false, reader.default?
158
- assert_equal [false, false, false, false, false, false, false],
159
- reader.map(&:default?)
160
- end
161
-
162
- def test_value?
163
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
164
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
165
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
166
- </x>
167
- eoxml
168
- assert_equal false, reader.value?
169
- assert_equal [false, true, false, true, false, true, false],
170
- reader.map(&:value?)
171
- end
172
-
173
- def test_read_error_document
174
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
175
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
176
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
177
- <foo>
178
- </x>
179
- eoxml
180
- assert_raises(Nokogiri::XML::SyntaxError) do
181
- reader.each { |node| }
182
- end
183
- assert 1, reader.errors.length
184
- end
185
-
186
- def test_attributes?
187
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
188
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
189
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
190
- </x>
191
- eoxml
192
- assert_equal false, reader.attributes?
193
- assert_equal [true, false, true, false, true, false, true],
194
- reader.map(&:attributes?)
195
- end
196
-
197
- def test_attributes
198
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
199
- <x xmlns:tenderlove='http://tenderlovemaking.com/'
200
- xmlns='http://mothership.connection.com/'
201
- >
202
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
203
- </x>
204
- eoxml
205
- assert_equal({}, reader.attributes)
206
- assert_equal [{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
207
- 'xmlns'=>'http://mothership.connection.com/'},
208
- {}, {"awesome"=>"true"}, {}, {"awesome"=>"true"}, {},
209
- {'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
210
- 'xmlns'=>'http://mothership.connection.com/'}],
211
- reader.map(&:attributes)
212
- end
213
-
214
- def test_attribute_roundtrip
215
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
216
- <x xmlns:tenderlove='http://tenderlovemaking.com/'
217
- xmlns='http://mothership.connection.com/'
218
- >
219
- <tenderlove:foo awesome='true' size='giant'>snuggles!</tenderlove:foo>
220
- </x>
221
- eoxml
222
- reader.each do |node|
223
- node.attributes.each do |key, value|
224
- assert_equal value, node.attribute(key)
225
- end
226
- end
227
- end
228
-
229
- def test_attribute_at
230
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
231
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
232
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
233
- </x>
234
- eoxml
235
- assert_nil reader.attribute_at(nil)
236
- assert_nil reader.attribute_at(0)
237
- assert_equal ['http://tenderlovemaking.com/', nil, 'true', nil, 'true', nil, 'http://tenderlovemaking.com/'],
238
- reader.map { |x| x.attribute_at(0) }
239
- end
240
-
241
- def test_attribute
242
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
243
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
244
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
245
- </x>
246
- eoxml
247
- assert_nil reader.attribute(nil)
248
- assert_nil reader.attribute('awesome')
249
- assert_equal [nil, nil, 'true', nil, 'true', nil, nil],
250
- reader.map { |x| x.attribute('awesome') }
251
- end
252
-
253
- def test_attribute_length
254
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
255
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
256
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
257
- </x>
258
- eoxml
259
- assert_equal 0, reader.attribute_count
260
- assert_equal [1, 0, 1, 0, 0, 0, 0], reader.map(&:attribute_count)
261
- end
262
-
263
- def test_depth
264
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
265
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
266
- <tenderlove:foo>snuggles!</tenderlove:foo>
267
- </x>
268
- eoxml
269
- assert_equal 0, reader.depth
270
- assert_equal [0, 1, 1, 2, 1, 1, 0], reader.map(&:depth)
271
- end
272
-
273
- def test_encoding
274
- string = <<-eoxml
275
- <awesome>
276
- <p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
277
- <p xml:lang="ja">日本語が上手です</p>
278
- </awesome>
279
- eoxml
280
- reader = Nokogiri::XML::Reader.from_memory(string, nil, 'UTF-8')
281
- assert_equal ['UTF-8'], reader.map(&:encoding).uniq
282
- end
283
-
284
- def test_xml_version
285
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
286
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
287
- <tenderlove:foo>snuggles!</tenderlove:foo>
288
- </x>
289
- eoxml
290
- assert_nil reader.xml_version
291
- assert_equal ['1.0'], reader.map(&:xml_version).uniq
292
- end
293
-
294
- def test_lang
295
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
296
- <awesome>
297
- <p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
298
- <p xml:lang="ja">日本語が上手です</p>
299
- </awesome>
300
- eoxml
301
- assert_nil reader.lang
302
- assert_equal [nil, nil, "en", "en", "en", nil, "ja", "ja", "ja", nil, nil],
303
- reader.map(&:lang)
304
- end
305
-
306
- def test_value
307
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
308
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
309
- <tenderlove:foo>snuggles!</tenderlove:foo>
310
- </x>
311
- eoxml
312
- assert_nil reader.value
313
- assert_equal [nil, "\n ", nil, "snuggles!", nil, "\n ", nil],
314
- reader.map(&:value)
315
- end
316
-
317
- def test_prefix
318
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
319
- <x xmlns:edi='http://ecommerce.example.org/schema'>
320
- <edi:foo>hello</edi:foo>
321
- </x>
322
- eoxml
323
- assert_nil reader.prefix
324
- assert_equal [nil, nil, "edi", nil, "edi", nil, nil],
325
- reader.map(&:prefix)
326
- end
327
-
328
- def test_node_type
329
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
330
- <x>
331
- <y>hello</y>
332
- </x>
333
- eoxml
334
- assert_equal 0, reader.node_type
335
- assert_equal [1, 14, 1, 3, 15, 14, 15], reader.map(&:node_type)
336
- end
337
-
338
- def test_inner_xml
339
- str = "<x><y>hello</y></x>"
340
- reader = Nokogiri::XML::Reader.from_memory(str)
341
-
342
- reader.read
343
-
344
- assert_equal "<y>hello</y>", reader.inner_xml
345
- end
346
-
347
- def test_outer_xml
348
- str = ["<x><y>hello</y></x>", "<y>hello</y>", "hello", "<y/>", "<x/>"]
349
- reader = Nokogiri::XML::Reader.from_memory(str.first)
350
-
351
- xml = []
352
- reader.map { |node| xml << node.outer_xml }
353
-
354
- assert_equal str, xml
355
- end
356
-
357
- def test_outer_xml_with_empty_nodes
358
- str = ["<x><y/></x>", "<y/>", "<x/>"]
359
- reader = Nokogiri::XML::Reader.from_memory(str.first)
360
-
361
- xml = []
362
- reader.map { |node| xml << node.outer_xml }
363
-
364
- assert_equal str, xml
365
- end
366
-
367
- def test_state
368
- reader = Nokogiri::XML::Reader.from_memory('<foo>bar</bar>')
369
- assert reader.state
370
- end
371
-
372
- def test_ns_uri
373
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
374
- <x xmlns:edi='http://ecommerce.example.org/schema'>
375
- <edi:foo>hello</edi:foo>
376
- </x>
377
- eoxml
378
- assert_nil reader.namespace_uri
379
- assert_equal([nil,
380
- nil,
381
- "http://ecommerce.example.org/schema",
382
- nil,
383
- "http://ecommerce.example.org/schema",
384
- nil,
385
- nil],
386
- reader.map(&:namespace_uri))
387
- end
388
-
389
- def test_namespaced_attributes
390
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
391
- <x xmlns:edi='http://ecommerce.example.org/schema' xmlns:commons="http://rets.org/xsd/RETSCommons">
392
- <edi:foo commons:street-number="43">hello</edi:foo>
393
- <y edi:name="francis" bacon="87"/>
394
- </x>
395
- eoxml
396
- attr_ns = []
397
- while reader.read
398
- if reader.node_type == Nokogiri::XML::Node::ELEMENT_NODE
399
- reader.attribute_nodes.each {|attr| attr_ns << (attr.namespace.nil? ? nil : attr.namespace.prefix) }
400
- end
401
- end
402
- assert_equal(['commons',
403
- 'edi',
404
- nil],
405
- attr_ns)
406
- end
407
-
408
- def test_local_name
409
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
410
- <x xmlns:edi='http://ecommerce.example.org/schema'>
411
- <edi:foo>hello</edi:foo>
412
- </x>
413
- eoxml
414
- assert_nil reader.local_name
415
- assert_equal(["x", "#text", "foo", "#text", "foo", "#text", "x"],
416
- reader.map(&:local_name))
417
- end
418
-
419
- def test_name
420
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
421
- <x xmlns:edi='http://ecommerce.example.org/schema'>
422
- <edi:foo>hello</edi:foo>
423
- </x>
424
- eoxml
425
- assert_nil reader.name
426
- assert_equal(["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"],
427
- reader.map(&:name))
428
- end
429
-
430
- def test_base_uri
431
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
432
- <x xml:base="http://base.example.org/base/">
433
- <link href="link"/>
434
- <other xml:base="http://other.example.org/"/>
435
- <relative xml:base="relative">
436
- <link href="stuff" />
437
- </relative>
438
- </x>
439
- eoxml
440
-
441
- assert_nil reader.base_uri
442
- assert_equal(["http://base.example.org/base/",
443
- "http://base.example.org/base/",
444
- "http://base.example.org/base/",
445
- "http://base.example.org/base/",
446
- "http://other.example.org/",
447
- "http://base.example.org/base/",
448
- "http://base.example.org/base/relative",
449
- "http://base.example.org/base/relative",
450
- "http://base.example.org/base/relative",
451
- "http://base.example.org/base/relative",
452
- "http://base.example.org/base/relative",
453
- "http://base.example.org/base/",
454
- "http://base.example.org/base/"],
455
- reader.map(&:base_uri))
456
- end
457
-
458
- def test_xlink_href_without_base_uri
459
- reader = Nokogiri::XML::Reader(<<-eoxml)
460
- <x xmlns:xlink="http://www.w3.org/1999/xlink">
461
- <link xlink:href="#other">Link</link>
462
- <other id="other">Linked Element</other>
463
- </x>
464
- eoxml
465
-
466
- reader.each do |node|
467
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
468
- if node.name == 'link'
469
- assert_nil node.base_uri
470
- end
471
- end
472
- end
473
- end
474
-
475
- def test_xlink_href_with_base_uri
476
- reader = Nokogiri::XML::Reader(<<-eoxml)
477
- <x xml:base="http://base.example.org/base/"
478
- xmlns:xlink="http://www.w3.org/1999/xlink">
479
- <link xlink:href="#other">Link</link>
480
- <other id="other">Linked Element</other>
481
- </x>
482
- eoxml
483
-
484
- reader.each do |node|
485
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
486
- assert_equal node.base_uri, "http://base.example.org/base/"
487
- end
488
- end
489
- end
490
-
491
- def test_read_from_memory
492
- called = false
493
- reader = Nokogiri::XML::Reader.from_memory('<foo>bar</foo>')
494
- reader.each do |node|
495
- called = true
496
- assert node
497
- end
498
- assert called
499
- end
500
-
501
- def test_large_document_smoke_test
502
- # simply run on a large document to verify that there no GC issues
503
- xml = []
504
- xml << "<elements>"
505
- 10000.times { |j| xml << "<element id=\"#{j}\"/>" }
506
- xml << "</elements>"
507
- xml = xml.join("\n")
508
-
509
- Nokogiri::XML::Reader.from_memory(xml).each do |e|
510
- e.attributes
511
- end
512
- end
513
-
514
- def test_correct_outer_xml_inclusion
515
- xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
516
- <root-element>
517
- <children>
518
- <child n="1">
519
- <field>child-1</field>
520
- </child>
521
- <child n="2">
522
- <field>child-2</field>
523
- </child>
524
- <child n="3">
525
- <field>child-3</field>
526
- </child>
527
- </children>
528
- </root-element>
529
- eoxml
530
-
531
- nodelengths = []
532
- has_child2 = []
533
-
534
- xml.each do |node|
535
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
536
- nodelengths << node.outer_xml.length
537
- has_child2 << !!(node.outer_xml =~ /child-2/)
538
- end
539
- end
540
-
541
- assert_equal(nodelengths[0], nodelengths[1])
542
- assert(has_child2[1])
543
- assert(!has_child2[0])
544
- end
545
-
546
- def test_correct_inner_xml_inclusion
547
- xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
548
- <root-element>
549
- <children>
550
- <child n="1">
551
- <field>child-1</field>
552
- </child>
553
- <child n="2">
554
- <field>child-2</field>
555
- </child>
556
- <child n="3">
557
- <field>child-3</field>
558
- </child>
559
- </children>
560
- </root-element>
561
- eoxml
562
-
563
- nodelengths = []
564
- has_child2 = []
565
-
566
- xml.each do |node|
567
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
568
- nodelengths << node.inner_xml.length
569
- has_child2 << !!(node.inner_xml =~ /child-2/)
570
- end
571
- end
572
-
573
- assert_equal(nodelengths[0], nodelengths[1])
574
- assert(has_child2[1])
575
- assert(!has_child2[0])
576
- end
577
- end