agio 0.5.0
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.
- data/.gemtest +0 -0
- data/.rspec +2 -0
- data/History.rdoc +3 -0
- data/License.rdoc +23 -0
- data/Manifest.txt +23 -0
- data/README.rdoc +97 -0
- data/Rakefile +35 -0
- data/agio.gemspec +53 -0
- data/bin/agio +17 -0
- data/lib/agio.rb +171 -0
- data/lib/agio/block.rb +132 -0
- data/lib/agio/bourse.rb +340 -0
- data/lib/agio/broker.rb +415 -0
- data/lib/agio/data.rb +90 -0
- data/lib/agio/flags.rb +317 -0
- data/lib/agio/html_element_description.rb +126 -0
- data/spec/block_spec.rb +168 -0
- data/spec/bourse_spec.rb +10 -0
- data/spec/broker_spec.rb +539 -0
- data/spec/data_spec.rb +341 -0
- data/spec/flags_spec.rb +473 -0
- data/spec/html_element_description_spec.rb +52 -0
- data/spec/pmh_spec.rb +31 -0
- data/spec/spec_helper.rb +308 -0
- metadata +216 -0
data/spec/block_spec.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Agio::Block do
|
6
|
+
context "Block construction" do
|
7
|
+
it "should throw an exception if a name is not provided" do
|
8
|
+
expect { Agio::Block.new }.to raise_error(ArgumentError)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should work with standard HTML elements like 'li'" do
|
12
|
+
block = nil
|
13
|
+
expect { block = Agio::Block.new('li') }.to_not raise_error
|
14
|
+
block.name.should == 'li'
|
15
|
+
block.options.should be_empty
|
16
|
+
block.contents.should be_empty
|
17
|
+
block.description.should_not be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should work with non-standard elements like 'block'" do
|
21
|
+
block = nil
|
22
|
+
expect { block = Agio::Block.new('block') }.to_not raise_error
|
23
|
+
block.name.should == 'block'
|
24
|
+
block.options.should be_empty
|
25
|
+
block.contents.should be_empty
|
26
|
+
block.description.should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should accept an options hash" do
|
30
|
+
block = nil
|
31
|
+
expect { block = Agio::Block.new('li', :x => :y) }.to_not raise_error
|
32
|
+
block.name.should == 'li'
|
33
|
+
block.options.should == { :x => :y }
|
34
|
+
block.contents.should be_empty
|
35
|
+
block.description.should_not be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "calling #append" do
|
40
|
+
subject { Agio::Block.new('li') }
|
41
|
+
|
42
|
+
it "should append one object given as a parameter" do
|
43
|
+
expect { subject.append(1) }.to_not raise_error
|
44
|
+
subject.contents.should == [ 1 ]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should append multiple objects given as parameters" do
|
48
|
+
expect { subject.append(1, 2) }.to_not raise_error
|
49
|
+
subject.contents.should == [ 1, 2 ]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "should understand the elements represented by the Block" do
|
54
|
+
describe "HTML standard block element <p>" do
|
55
|
+
subject { Agio::Block.new('p') }
|
56
|
+
|
57
|
+
its(:name) { should == 'p' }
|
58
|
+
its(:description) { subject.to_s.should =~ /p:\s+paragraph/ }
|
59
|
+
|
60
|
+
its(:standard?) { should == true }
|
61
|
+
its(:inline?) { should == false }
|
62
|
+
its(:block?) { should == true }
|
63
|
+
its(:li?) { should == false }
|
64
|
+
its(:pre?) { should == false }
|
65
|
+
its(:ul_ol?) { should == false }
|
66
|
+
its(:definition?) { should == false }
|
67
|
+
its(:dl?) { should == false }
|
68
|
+
|
69
|
+
it "should not be able to contain a <p>" do
|
70
|
+
subject.can_contain?(Agio::Block.new('p')).should == false
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should be able to contain an <em>" do
|
74
|
+
subject.can_contain?(Agio::Block.new('em')).should == true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not be able to contain a <li>" do
|
78
|
+
subject.can_contain?(Agio::Block.new('li')).should == false
|
79
|
+
end
|
80
|
+
|
81
|
+
it "is a sibling of a <p>" do
|
82
|
+
subject.sibling_of?(Agio::Block.new('p')).should == true
|
83
|
+
end
|
84
|
+
|
85
|
+
it "is not a sibling of a <blockquote>" do
|
86
|
+
subject.sibling_of?(Agio::Block.new('blockquote')).should == false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "HTML standard block element <ol>" do
|
91
|
+
subject { Agio::Block.new('ol') }
|
92
|
+
|
93
|
+
its(:name) { should == 'ol' }
|
94
|
+
its(:description) { subject.to_s.should =~ /ol:\s+ordered list/ }
|
95
|
+
|
96
|
+
its(:standard?) { should == true }
|
97
|
+
its(:inline?) { should == false }
|
98
|
+
its(:block?) { should == true }
|
99
|
+
its(:li?) { should == false }
|
100
|
+
its(:pre?) { should == false }
|
101
|
+
its(:ul_ol?) { should == true }
|
102
|
+
its(:definition?) { should == false }
|
103
|
+
its(:dl?) { should == false }
|
104
|
+
|
105
|
+
it "should not be able to contain a <p>" do
|
106
|
+
subject.can_contain?(Agio::Block.new('p')).should == false
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should not be able to contain an <em>" do
|
110
|
+
subject.can_contain?(Agio::Block.new('em')).should == false
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should be able to contain a <li>" do
|
114
|
+
subject.can_contain?(Agio::Block.new('li')).should == true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "is a sibling of an <ol>" do
|
118
|
+
subject.sibling_of?(Agio::Block.new('ol')).should == true
|
119
|
+
end
|
120
|
+
|
121
|
+
it "is not a sibling of a <blockquote>" do
|
122
|
+
subject.sibling_of?(Agio::Block.new('blockquote')).should == false
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "HTML standard inline element <em>" do
|
127
|
+
subject { Agio::Block.new('em') }
|
128
|
+
|
129
|
+
its(:name) { should == 'em' }
|
130
|
+
its(:description) { subject.to_s.should =~ /em:\s+emphasis/ }
|
131
|
+
|
132
|
+
its(:standard?) { should == true }
|
133
|
+
its(:inline?) { should == true }
|
134
|
+
its(:block?) { should == false }
|
135
|
+
its(:li?) { should == false }
|
136
|
+
its(:pre?) { should == false }
|
137
|
+
its(:ul_ol?) { should == false }
|
138
|
+
its(:definition?) { should == false }
|
139
|
+
its(:dl?) { should == false }
|
140
|
+
|
141
|
+
it "should not be able to contain a <p>" do
|
142
|
+
subject.can_contain?(Agio::Block.new('p')).should == false
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should be able to contain an <em>" do
|
146
|
+
subject.can_contain?(Agio::Block.new('em')).should == true
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should not be able to contain a <li>" do
|
150
|
+
subject.can_contain?(Agio::Block.new('li')).should == false
|
151
|
+
end
|
152
|
+
|
153
|
+
it "is not a sibling of an <em>" do
|
154
|
+
subject.sibling_of?(Agio::Block.new('em')).should == false
|
155
|
+
end
|
156
|
+
|
157
|
+
it "is not a sibling of a <blockquote>" do
|
158
|
+
subject.sibling_of?(Agio::Block.new('blockquote')).should == false
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should be able to answer #can_contain? with a String parameter" do
|
164
|
+
Agio::Block.new('p').can_contain?('em').should == true
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# vim: ft=ruby
|
data/spec/bourse_spec.rb
ADDED
data/spec/broker_spec.rb
ADDED
@@ -0,0 +1,539 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Agio::Broker do
|
6
|
+
# We need to be able to inspect the status of the Agio::Broker during
|
7
|
+
# testing (#stack), and we need to test some otherwise private methods
|
8
|
+
# (#push, #pop).
|
9
|
+
before { PrivateMethodHandler.remove(Agio::Broker) }
|
10
|
+
after { PrivateMethodHandler.restore(Agio::Broker) }
|
11
|
+
subject { Agio::Broker.new }
|
12
|
+
|
13
|
+
context "when first created" do
|
14
|
+
its(:blocks) { should be_empty }
|
15
|
+
its(:stack) { should be_empty }
|
16
|
+
its(:errors) { should be_empty }
|
17
|
+
its(:warnings) { should be_empty }
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "#push should fail on non Agio::Data or Agio::Block objects" do
|
21
|
+
expect { subject.push(nil) }.to raise_error(ArgumentError)
|
22
|
+
expect { subject.push(1) }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#push with Agio::Data objects" do
|
26
|
+
let(:p_block) { Agio::Block.new('p') }
|
27
|
+
let(:data_result) {
|
28
|
+
p_block.append(Agio::Data.new('test'))
|
29
|
+
p_block
|
30
|
+
}
|
31
|
+
let(:cdata_result) {
|
32
|
+
p_block.append(Agio::CData.new('test'))
|
33
|
+
p_block
|
34
|
+
}
|
35
|
+
let(:comment_result) {
|
36
|
+
p_block.append(Agio::Comment.new('test'))
|
37
|
+
p_block
|
38
|
+
}
|
39
|
+
let(:xmldecl_result) {
|
40
|
+
p_block.append(Agio::XMLDecl.new('test'))
|
41
|
+
p_block
|
42
|
+
}
|
43
|
+
|
44
|
+
it "should push an Agio::Block('p') on the stack if one does not exist" do
|
45
|
+
subject.push(Agio::Data.new('test'))
|
46
|
+
subject.blocks.should be_empty
|
47
|
+
subject.stack.should_not be_empty
|
48
|
+
subject.stack.size.should == 1
|
49
|
+
subject.stack.first.should == data_result
|
50
|
+
subject.stack.first.contents.first.class.should == Agio::Data
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should create an Agio::Data object with a String argument" do
|
54
|
+
subject.push('test')
|
55
|
+
subject.blocks.should be_empty
|
56
|
+
subject.stack.should_not be_empty
|
57
|
+
subject.stack.size.should == 1
|
58
|
+
subject.stack.first.should == data_result
|
59
|
+
subject.stack.first.contents.first.class.should == Agio::Data
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should accept an Agio::CData object" do
|
63
|
+
subject.push(Agio::CData.new('test'))
|
64
|
+
subject.blocks.should be_empty
|
65
|
+
subject.stack.should_not be_empty
|
66
|
+
subject.stack.size.should == 1
|
67
|
+
subject.stack.first.should == cdata_result
|
68
|
+
subject.stack.first.contents.first.class.should == Agio::CData
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should accept an Agio::Comment object" do
|
72
|
+
subject.push(Agio::Comment.new('test'))
|
73
|
+
subject.blocks.should be_empty
|
74
|
+
subject.stack.should_not be_empty
|
75
|
+
subject.stack.size.should == 1
|
76
|
+
subject.stack.first.should == comment_result
|
77
|
+
subject.stack.first.contents.first.class.should == Agio::Comment
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should accept an Agio::XMLDecl object" do
|
81
|
+
subject.push(Agio::XMLDecl.new('test'))
|
82
|
+
subject.blocks.should_not be_empty
|
83
|
+
subject.blocks.size.should == 1
|
84
|
+
subject.blocks.first.should == Agio::XMLDecl.new('test')
|
85
|
+
subject.stack.should be_empty
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def B(tag, options = {})
|
90
|
+
Agio::Block.new(tag, options)
|
91
|
+
end
|
92
|
+
|
93
|
+
context "push with Agio::Block objects" do
|
94
|
+
it "should ignore <html> blocks" do
|
95
|
+
result = subject.push(B('html'))
|
96
|
+
result.should be_nil
|
97
|
+
subject.blocks.should be_empty
|
98
|
+
subject.stack.should be_empty
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with <head> and <body> blocks" do
|
102
|
+
before(:each) { subject.push(B('head')) }
|
103
|
+
|
104
|
+
it "should accept a <head> block" do
|
105
|
+
subject.blocks.should be_empty
|
106
|
+
subject.stack.should == [ B('head') ]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should pop a <head> block but otherwise ignore a <body> block." do
|
110
|
+
result = subject.push(B('body'))
|
111
|
+
result.should be_nil
|
112
|
+
subject.blocks.should == [ B('head') ]
|
113
|
+
subject.stack.should be_empty
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when the stack is empty" do
|
118
|
+
it "should push an implied <ul> when receiving a <li>" do
|
119
|
+
result = subject.push(B('li'))
|
120
|
+
result.should == B('li')
|
121
|
+
subject.blocks.should be_empty
|
122
|
+
subject.stack.should == [ B('ul'), B('li') ]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should push an implied <dl> when receiving a <dt>" do
|
126
|
+
result = subject.push(B('dt'))
|
127
|
+
result.should == B('dt')
|
128
|
+
subject.blocks.should be_empty
|
129
|
+
subject.stack.should == [ B('dl'), B('dt') ]
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should push an implied <dl> when receiving a <dd>" do
|
133
|
+
result = subject.push(B('dd'))
|
134
|
+
result.should == B('dd')
|
135
|
+
subject.blocks.should be_empty
|
136
|
+
subject.stack.should == [ B('dl'), B('dd') ]
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should push an implied <p> when receiving an inline block" do
|
140
|
+
result = subject.push(B('em'))
|
141
|
+
result.should == B('em')
|
142
|
+
subject.blocks.should be_empty
|
143
|
+
subject.stack.should == [ B('p'), B('em') ]
|
144
|
+
|
145
|
+
subject.stack.clear
|
146
|
+
subject.stack.should be_empty
|
147
|
+
result = subject.push(B('span'))
|
148
|
+
result.should == B('span')
|
149
|
+
subject.blocks.should be_empty
|
150
|
+
subject.stack.should == [ B('p'), B('span') ]
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should push a <div> directly" do
|
154
|
+
result = subject.push(B('div'))
|
155
|
+
result.should == B('div')
|
156
|
+
subject.blocks.should be_empty
|
157
|
+
subject.stack.should == [ B('div') ]
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should push a <blockquote> directly" do
|
161
|
+
result = subject.push(B('blockquote'))
|
162
|
+
result.should == B('blockquote')
|
163
|
+
subject.blocks.should be_empty
|
164
|
+
subject.stack.should == [ B('blockquote') ]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "when the stack has a <dl> block" do
|
169
|
+
before(:each) { subject.push(B('dl')) }
|
170
|
+
|
171
|
+
it "should append a <dt>" do
|
172
|
+
subject.push(B('dt'))
|
173
|
+
subject.blocks.should be_empty
|
174
|
+
subject.stack.should == [ B('dl'), B('dt') ]
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should append a <dd>" do
|
178
|
+
subject.push(B('dd'))
|
179
|
+
subject.blocks.should be_empty
|
180
|
+
subject.stack.should == [ B('dl'), B('dd') ]
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should shift and reset the stack when receiving a <p>" do
|
184
|
+
subject.push(B('p'))
|
185
|
+
subject.blocks.should == [ B('dl') ]
|
186
|
+
subject.stack.should == [ B('p') ]
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "when the stack has a <ol> block" do
|
191
|
+
before(:each) { subject.push(B('ol')) }
|
192
|
+
|
193
|
+
it "should append a <li>" do
|
194
|
+
subject.push(B('li'))
|
195
|
+
subject.blocks.should be_empty
|
196
|
+
subject.stack.should == [ B('ol'), B('li') ]
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should shift and reset the stack when receiving a <p>" do
|
200
|
+
subject.push(B('p'))
|
201
|
+
subject.blocks.should == [ B('ol') ]
|
202
|
+
subject.stack.should == [ B('p') ]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "when the stack has a <ul> block" do
|
207
|
+
before(:each) { subject.push(B('ul')) }
|
208
|
+
|
209
|
+
it "should append a <li>" do
|
210
|
+
subject.push(B('li'))
|
211
|
+
subject.blocks.should be_empty
|
212
|
+
subject.stack.should == [ B('ul'), B('li') ]
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should shift and reset the stack when receiving a <p>" do
|
216
|
+
subject.push(B('p'))
|
217
|
+
subject.blocks.should == [ B('ul') ]
|
218
|
+
subject.stack.should == [ B('p') ]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "when the stack has a <p> block" do
|
223
|
+
before(:each) { subject.push(B('p')) }
|
224
|
+
|
225
|
+
it "should append an inline element like <em>" do
|
226
|
+
subject.push(B('em'))
|
227
|
+
subject.blocks.should be_empty
|
228
|
+
subject.stack.should == [ B('p'), B('em') ]
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should shift and reset the stack with another <p>" do
|
232
|
+
subject.push(B('p'))
|
233
|
+
subject.blocks.should == [ B('p') ]
|
234
|
+
subject.stack.should == [ B('p') ]
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should shift and reset the stack with a <div>" do
|
238
|
+
subject.push(B('div'))
|
239
|
+
subject.blocks.should == [ B('p') ]
|
240
|
+
subject.stack.should == [ B('div') ]
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should shift and reset the stack with a <blockquote>" do
|
244
|
+
subject.push(B('blockquote'))
|
245
|
+
subject.blocks.should == [ B('p') ]
|
246
|
+
subject.stack.should == [ B('blockquote') ]
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should shift and reset the stack with a <ol>" do
|
250
|
+
subject.push(B('ol'))
|
251
|
+
subject.blocks.should == [ B('p') ]
|
252
|
+
subject.stack.should == [ B('ol') ]
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should shift and reset the stack with a <li>, imploying a <ul>" do
|
256
|
+
subject.push(B('li'))
|
257
|
+
subject.blocks.should == [ B('p') ]
|
258
|
+
subject.stack.should == [ B('ul'), B('li') ]
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context "when the stack has a <div> block" do
|
263
|
+
before(:each) { subject.push(B('div')) }
|
264
|
+
|
265
|
+
it "should append an inline element like <em>" do
|
266
|
+
subject.push(B('em'))
|
267
|
+
subject.blocks.should be_empty
|
268
|
+
subject.stack.should == [ B('div'), B('em') ]
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should append a <p>" do
|
272
|
+
subject.push(B('p'))
|
273
|
+
subject.blocks.should be_empty
|
274
|
+
subject.stack.should == [ B('div'), B('p') ]
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should append a <div>" do
|
278
|
+
subject.push(B('div'))
|
279
|
+
subject.blocks.should be_empty
|
280
|
+
subject.stack.should == [ B('div'), B('div') ]
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should append a <blockquote>" do
|
284
|
+
subject.push(B('blockquote'))
|
285
|
+
subject.blocks.should be_empty
|
286
|
+
subject.stack.should == [ B('div'), B('blockquote') ]
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should append a <ol>" do
|
290
|
+
subject.push(B('ol'))
|
291
|
+
subject.blocks.should be_empty
|
292
|
+
subject.stack.should == [ B('div'), B('ol') ]
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should append a <li>, imploying a <ul>" do
|
296
|
+
subject.push(B('li'))
|
297
|
+
subject.blocks.should be_empty
|
298
|
+
subject.stack.should == [ B('div'), B('ul'), B('li') ]
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
context "when the stack has a <blockquote> block" do
|
303
|
+
before(:each) { subject.push(B('blockquote')) }
|
304
|
+
|
305
|
+
it "should append an inline element like <em>" do
|
306
|
+
subject.push(B('em'))
|
307
|
+
subject.blocks.should be_empty
|
308
|
+
subject.stack.should == [ B('blockquote'), B('em') ]
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should append a <p>" do
|
312
|
+
subject.push(B('p'))
|
313
|
+
subject.blocks.should be_empty
|
314
|
+
subject.stack.should == [ B('blockquote'), B('p') ]
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should append a <div>" do
|
318
|
+
subject.push(B('div'))
|
319
|
+
subject.blocks.should be_empty
|
320
|
+
subject.stack.should == [ B('blockquote'), B('div') ]
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should append another <blockquote>" do
|
324
|
+
subject.push(B('blockquote'))
|
325
|
+
subject.blocks.should be_empty
|
326
|
+
subject.stack.should == [ B('blockquote'), B('blockquote') ]
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should append an <ol>" do
|
330
|
+
subject.push(B('ol'))
|
331
|
+
subject.blocks.should be_empty
|
332
|
+
subject.stack.should == [ B('blockquote'), B('ol') ]
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should append a <li>, imploying a <ul>" do
|
336
|
+
subject.push(B('li'))
|
337
|
+
subject.blocks.should be_empty
|
338
|
+
subject.stack.should == [ B('blockquote'), B('ul'), B('li') ]
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context "pop the Agio::Block stack" do
|
344
|
+
let(:em) {
|
345
|
+
r = B('em')
|
346
|
+
r.append(Agio::Data.new('text'))
|
347
|
+
r
|
348
|
+
}
|
349
|
+
let(:div) {
|
350
|
+
r = B('div')
|
351
|
+
r.append(em)
|
352
|
+
r
|
353
|
+
}
|
354
|
+
|
355
|
+
it "should return nil if the stack is empty." do
|
356
|
+
subject.stack.should be_empty
|
357
|
+
subject.pop.should == nil
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should move a Block to the blocks when there's one item on the stack" do
|
361
|
+
subject.push(B('p'))
|
362
|
+
subject.pop.should == B('p')
|
363
|
+
subject.stack.should be_empty
|
364
|
+
subject.blocks.should == [ B('p') ]
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should append a Block to the top of the stack when there's more than one item on the stack" do
|
368
|
+
subject.push(B('div'))
|
369
|
+
subject.push(B('em'))
|
370
|
+
subject.push('text')
|
371
|
+
subject.stack.should == [ B('div'), em ]
|
372
|
+
subject.pop.should == em
|
373
|
+
|
374
|
+
subject.blocks.should be_empty
|
375
|
+
subject.stack.should == [ div ]
|
376
|
+
subject.stack[-1].contents.should == [ em ]
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should pop to the named block when a name is given" do
|
380
|
+
subject.push(B('div'))
|
381
|
+
subject.push(B('em'))
|
382
|
+
subject.push('text')
|
383
|
+
subject.stack.should == [ B('div'), em ]
|
384
|
+
subject.pop('div').should == div
|
385
|
+
|
386
|
+
subject.blocks.should == [ div ]
|
387
|
+
subject.stack.should be_empty
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should pop the whole stack if a name can't be found" do
|
391
|
+
subject.push(B('div'))
|
392
|
+
subject.push(B('em'))
|
393
|
+
subject.push('text')
|
394
|
+
subject.stack.should == [ B('div'), em ]
|
395
|
+
subject.pop('p').should == div
|
396
|
+
|
397
|
+
subject.blocks.should == [ div ]
|
398
|
+
subject.stack.should be_empty
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
context "methods inherited from Nokogiri::XML::SAX::Document" do
|
403
|
+
let(:cdata) { Agio::CData.new('cdata') }
|
404
|
+
let(:comment) { Agio::CData.new('comment') }
|
405
|
+
let(:data) { Agio::Data.new('data') }
|
406
|
+
let(:div) { B('div') }
|
407
|
+
let(:em) { B('em') }
|
408
|
+
let(:nem) { B('em', :prefix => 'n', :uri => 'x:y') }
|
409
|
+
let(:xml) {
|
410
|
+
Agio::XMLDecl.new(:version => "1.0", :encoding => "UTF-8",
|
411
|
+
:standalone => false)
|
412
|
+
}
|
413
|
+
|
414
|
+
before(:each) { subject.push(div) }
|
415
|
+
|
416
|
+
it "should push an Agio::CData block when #cdata_block is called" do
|
417
|
+
div.append(cdata)
|
418
|
+
subject.cdata_block("cdata")
|
419
|
+
subject.blocks.should be_empty
|
420
|
+
subject.stack.should == [ div ]
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should push an Agio::Data block when #characters is called" do
|
424
|
+
div.append(data)
|
425
|
+
subject.characters("data")
|
426
|
+
subject.blocks.should be_empty
|
427
|
+
subject.stack.should == [ div ]
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should push an Agio::Comment block when #comment is called" do
|
431
|
+
div.append(comment)
|
432
|
+
subject.comment("data")
|
433
|
+
subject.blocks.should be_empty
|
434
|
+
subject.stack.should == [ div ]
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should clear the stack when #end_document is called" do
|
438
|
+
div.append(data)
|
439
|
+
subject.characters('data')
|
440
|
+
|
441
|
+
subject.blocks.should be_empty
|
442
|
+
subject.stack.should == [ div ]
|
443
|
+
|
444
|
+
subject.end_document
|
445
|
+
subject.blocks.should == [ div ]
|
446
|
+
subject.stack.should be_empty
|
447
|
+
end
|
448
|
+
|
449
|
+
it "should pop the named element when #end_element is called" do
|
450
|
+
em.append(data)
|
451
|
+
|
452
|
+
subject.push(B('em'))
|
453
|
+
subject.characters('data')
|
454
|
+
|
455
|
+
subject.blocks.should be_empty
|
456
|
+
subject.stack.should == [ div, em ]
|
457
|
+
|
458
|
+
div.append(em)
|
459
|
+
subject.end_element('em')
|
460
|
+
subject.blocks.should be_empty
|
461
|
+
subject.stack.should == [ div ]
|
462
|
+
|
463
|
+
subject.end_element('div')
|
464
|
+
subject.blocks.should == [ div ]
|
465
|
+
subject.stack.should be_empty
|
466
|
+
end
|
467
|
+
|
468
|
+
it "should pop the named element with namespace when #end_element_namespace is called" do
|
469
|
+
em.append(data.dup)
|
470
|
+
nem.append(data.dup)
|
471
|
+
|
472
|
+
subject.push(B('em', :prefix => 'n', :uri => 'x:y'))
|
473
|
+
subject.characters('data')
|
474
|
+
subject.push(B('em'))
|
475
|
+
subject.characters('data')
|
476
|
+
|
477
|
+
subject.blocks.should be_empty
|
478
|
+
subject.stack.should == [ div, nem, em ]
|
479
|
+
|
480
|
+
div.append(nem)
|
481
|
+
div.append(em)
|
482
|
+
|
483
|
+
subject.end_element_namespace('em', 'n', 'x:y')
|
484
|
+
subject.blocks.should be_empty
|
485
|
+
subject.stack.should == [ div ]
|
486
|
+
|
487
|
+
subject.end_element('div')
|
488
|
+
subject.blocks.should == [ div ]
|
489
|
+
subject.stack.should be_empty
|
490
|
+
end
|
491
|
+
|
492
|
+
it "should add to the #errors array when #error is called" do
|
493
|
+
subject.error("foo")
|
494
|
+
subject.errors.should == [ "foo" ]
|
495
|
+
end
|
496
|
+
|
497
|
+
it "should clear the stack when #end_document is called" do
|
498
|
+
div.append(data)
|
499
|
+
subject.characters('data')
|
500
|
+
|
501
|
+
subject.blocks.should be_empty
|
502
|
+
subject.stack.should == [ div ]
|
503
|
+
|
504
|
+
subject.start_document
|
505
|
+
subject.blocks.should == [ div ]
|
506
|
+
subject.stack.should be_empty
|
507
|
+
end
|
508
|
+
|
509
|
+
it "should push a new Agio::Block when #start_element is called" do
|
510
|
+
subject.start_element('div')
|
511
|
+
subject.blocks.should be_empty
|
512
|
+
subject.stack.should == [ div, div ]
|
513
|
+
end
|
514
|
+
|
515
|
+
it "should push a new Agio::Block when #start_element_namespace is called" do
|
516
|
+
div.options[:attrs] = []
|
517
|
+
div.options[:prefix] = 'n'
|
518
|
+
div.options[:uri] = 'x:y'
|
519
|
+
div.options[:ns] = []
|
520
|
+
|
521
|
+
subject.start_element_namespace('div', [], 'n', 'x:y')
|
522
|
+
subject.blocks.should be_empty
|
523
|
+
subject.stack.should == [ div, div ]
|
524
|
+
end
|
525
|
+
|
526
|
+
it "should add to the #warnings array when #warning is called" do
|
527
|
+
subject.warning("foo")
|
528
|
+
subject.warnings.should == [ "foo" ]
|
529
|
+
end
|
530
|
+
|
531
|
+
it "should push an XML declaration" do
|
532
|
+
subject.xmldecl("1.0", "UTF-8", false)
|
533
|
+
subject.blocks.should == [ xml ]
|
534
|
+
subject.stack.should == [ div ]
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
# vim: ft=ruby
|