rss 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +38 -0
- data/README.md +11 -11
- data/lib/rss/itunes.rb +10 -1
- data/lib/rss/maker/itunes.rb +2 -0
- data/lib/rss/rss.rb +43 -15
- data/lib/rss/utils.rb +0 -18
- data/lib/rss/version.rb +1 -1
- data/lib/rss/xml-stylesheet.rb +3 -4
- data/lib/rss/xml.rb +3 -2
- data/lib/rss.rb +11 -11
- metadata +7 -101
- data/Gemfile +0 -6
- data/Rakefile +0 -15
- data/rss.gemspec +0 -30
- data/test/dot.png +0 -0
- data/test/rss-assertions.rb +0 -2116
- data/test/rss-testcase.rb +0 -479
- data/test/run-test.rb +0 -15
- data/test/test_1.0.rb +0 -308
- data/test/test_2.0.rb +0 -412
- data/test/test_accessor.rb +0 -104
- data/test/test_atom.rb +0 -684
- data/test/test_content.rb +0 -105
- data/test/test_dublincore.rb +0 -270
- data/test/test_image.rb +0 -215
- data/test/test_inherit.rb +0 -41
- data/test/test_itunes.rb +0 -360
- data/test/test_maker_0.9.rb +0 -477
- data/test/test_maker_1.0.rb +0 -519
- data/test/test_maker_2.0.rb +0 -758
- data/test/test_maker_atom_entry.rb +0 -394
- data/test/test_maker_atom_feed.rb +0 -455
- data/test/test_maker_content.rb +0 -48
- data/test/test_maker_dc.rb +0 -150
- data/test/test_maker_image.rb +0 -63
- data/test/test_maker_itunes.rb +0 -488
- data/test/test_maker_slash.rb +0 -38
- data/test/test_maker_sy.rb +0 -45
- data/test/test_maker_taxo.rb +0 -82
- data/test/test_maker_trackback.rb +0 -42
- data/test/test_maker_xml-stylesheet.rb +0 -84
- data/test/test_parser.rb +0 -122
- data/test/test_parser_1.0.rb +0 -529
- data/test/test_parser_2.0.rb +0 -123
- data/test/test_parser_atom_entry.rb +0 -164
- data/test/test_parser_atom_feed.rb +0 -277
- data/test/test_setup_maker_0.9.rb +0 -247
- data/test/test_setup_maker_1.0.rb +0 -551
- data/test/test_setup_maker_2.0.rb +0 -309
- data/test/test_setup_maker_atom_entry.rb +0 -410
- data/test/test_setup_maker_atom_feed.rb +0 -446
- data/test/test_setup_maker_itunes.rb +0 -146
- data/test/test_setup_maker_slash.rb +0 -39
- data/test/test_slash.rb +0 -65
- data/test/test_syndication.rb +0 -126
- data/test/test_taxonomy.rb +0 -173
- data/test/test_to_s.rb +0 -701
- data/test/test_trackback.rb +0 -136
- data/test/test_xml-stylesheet.rb +0 -109
data/test/rss-assertions.rb
DELETED
@@ -1,2116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require 'erb'
|
3
|
-
|
4
|
-
module RSS
|
5
|
-
module Assertions
|
6
|
-
def assert_parse(rss, assert_method, *args)
|
7
|
-
__send__("assert_#{assert_method}", *args) do
|
8
|
-
::RSS::Parser.parse(rss)
|
9
|
-
end
|
10
|
-
__send__("assert_#{assert_method}", *args) do
|
11
|
-
::RSS::Parser.parse(rss, false).validate
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def assert_ns(prefix, uri)
|
16
|
-
_wrap_assertion do
|
17
|
-
begin
|
18
|
-
yield
|
19
|
-
flunk("Not raise NSError")
|
20
|
-
rescue ::RSS::NSError => e
|
21
|
-
assert_equal(prefix, e.prefix)
|
22
|
-
assert_equal(uri, e.uri)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def assert_missing_tag(tag, parent)
|
28
|
-
_wrap_assertion do
|
29
|
-
begin
|
30
|
-
yield
|
31
|
-
flunk("Not raise MissingTagError")
|
32
|
-
rescue ::RSS::MissingTagError => e
|
33
|
-
assert_equal(tag, e.tag)
|
34
|
-
assert_equal(parent, e.parent)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def assert_too_much_tag(tag, parent)
|
40
|
-
_wrap_assertion do
|
41
|
-
begin
|
42
|
-
yield
|
43
|
-
flunk("Not raise TooMuchTagError")
|
44
|
-
rescue ::RSS::TooMuchTagError => e
|
45
|
-
assert_equal(tag, e.tag)
|
46
|
-
assert_equal(parent, e.parent)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def assert_missing_attribute(tag, attrname)
|
52
|
-
_wrap_assertion do
|
53
|
-
begin
|
54
|
-
yield
|
55
|
-
flunk("Not raise MissingAttributeError")
|
56
|
-
rescue ::RSS::MissingAttributeError => e
|
57
|
-
assert_equal(tag, e.tag)
|
58
|
-
assert_equal(attrname, e.attribute)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def assert_not_expected_tag(tag, uri, parent)
|
64
|
-
_wrap_assertion do
|
65
|
-
begin
|
66
|
-
yield
|
67
|
-
flunk("Not raise NotExpectedTagError")
|
68
|
-
rescue ::RSS::NotExpectedTagError => e
|
69
|
-
assert_equal(tag, e.tag)
|
70
|
-
assert_equal(uri, e.uri)
|
71
|
-
assert_equal(parent, e.parent)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def assert_not_available_value(tag, value, attribute=nil)
|
77
|
-
_wrap_assertion do
|
78
|
-
begin
|
79
|
-
yield
|
80
|
-
flunk("Not raise NotAvailableValueError")
|
81
|
-
rescue ::RSS::NotAvailableValueError => e
|
82
|
-
assert_equal(tag, e.tag)
|
83
|
-
assert_equal(value, e.value)
|
84
|
-
assert_equal(attribute, e.attribute)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def assert_not_set_error(name, variables)
|
90
|
-
_wrap_assertion do
|
91
|
-
begin
|
92
|
-
yield
|
93
|
-
flunk("Not raise NotSetError")
|
94
|
-
rescue ::RSS::NotSetError => e
|
95
|
-
assert_equal(name, e.name)
|
96
|
-
assert_kind_of(Array, variables)
|
97
|
-
assert_equal(variables.sort, e.variables.sort)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def assert_xml_declaration(version, encoding, standalone, rss)
|
103
|
-
_wrap_assertion do
|
104
|
-
assert_equal(version, rss.version)
|
105
|
-
assert_equal(encoding, rss.encoding)
|
106
|
-
assert_equal(standalone, rss.standalone)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def assert_xml_stylesheet_attrs(attrs, xsl)
|
111
|
-
_wrap_assertion do
|
112
|
-
n_attrs = normalized_attrs(attrs)
|
113
|
-
::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
|
114
|
-
assert_equal(n_attrs[name], xsl.__send__(name))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def assert_xml_stylesheet(target, attrs, xsl)
|
120
|
-
_wrap_assertion do
|
121
|
-
if attrs.has_key?(:href)
|
122
|
-
if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
|
123
|
-
attrs[:type] = attrs[:guess_type]
|
124
|
-
end
|
125
|
-
assert_equal("xml-stylesheet", target)
|
126
|
-
assert_xml_stylesheet_attrs(attrs, xsl)
|
127
|
-
else
|
128
|
-
assert_nil(target)
|
129
|
-
assert_equal("", xsl.to_s)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def assert_xml_stylesheet_pis(attrs_ary, rss=nil)
|
135
|
-
_wrap_assertion do
|
136
|
-
if rss.nil?
|
137
|
-
rss = ::RSS::RDF.new
|
138
|
-
setup_rss10(rss)
|
139
|
-
end
|
140
|
-
xss_strs = []
|
141
|
-
attrs_ary.each do |attrs|
|
142
|
-
xss = ::RSS::XMLStyleSheet.new(attrs)
|
143
|
-
xss_strs.push(xss.to_s)
|
144
|
-
rss.xml_stylesheets.push(xss)
|
145
|
-
end
|
146
|
-
pi_str = rss.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<[^\?].*\z/m, "")
|
147
|
-
assert_equal(xss_strs.join("\n"), pi_str)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def assert_xml_stylesheets(attrs, xss)
|
152
|
-
_wrap_assertion do
|
153
|
-
xss.each_with_index do |xs, i|
|
154
|
-
assert_xml_stylesheet_attrs(attrs[i], xs)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
def assert_atom_person(tag_name, generator)
|
161
|
-
_wrap_assertion do
|
162
|
-
name = "Mark Pilgrim"
|
163
|
-
uri = "http://example.org/"
|
164
|
-
email = "f8dy@example.com"
|
165
|
-
|
166
|
-
assert_parse(generator.call(<<-EOA), :missing_tag, "name", tag_name)
|
167
|
-
<#{tag_name}/>
|
168
|
-
EOA
|
169
|
-
|
170
|
-
assert_parse(generator.call(<<-EOA), :missing_tag, "name", tag_name)
|
171
|
-
<#{tag_name}>
|
172
|
-
<uri>#{uri}</uri>
|
173
|
-
<email>#{email}</email>
|
174
|
-
</#{tag_name}>
|
175
|
-
EOA
|
176
|
-
|
177
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
178
|
-
<#{tag_name}>
|
179
|
-
<name>#{name}</name>
|
180
|
-
</#{tag_name}>
|
181
|
-
EOA
|
182
|
-
|
183
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
184
|
-
<#{tag_name}>
|
185
|
-
<name>#{name}</name>
|
186
|
-
<uri>#{uri}</uri>
|
187
|
-
<email>#{email}</email>
|
188
|
-
</#{tag_name}>
|
189
|
-
EOA
|
190
|
-
|
191
|
-
person = yield(feed)
|
192
|
-
assert_not_nil(person)
|
193
|
-
assert_equal(name, person.name.content)
|
194
|
-
assert_equal(uri, person.uri.content)
|
195
|
-
assert_equal(email, person.email.content)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def assert_atom_category(generator)
|
200
|
-
_wrap_assertion do
|
201
|
-
term = "Music"
|
202
|
-
scheme = "http://xmlns.com/wordnet/1.6/"
|
203
|
-
label = "music"
|
204
|
-
|
205
|
-
missing_args = [:missing_attribute, "category", "term"]
|
206
|
-
assert_parse(generator.call(<<-EOA), *missing_args)
|
207
|
-
<category/>
|
208
|
-
EOA
|
209
|
-
|
210
|
-
assert_parse(generator.call(<<-EOA), *missing_args)
|
211
|
-
<category scheme="#{scheme}" label="#{label}"/>
|
212
|
-
EOA
|
213
|
-
|
214
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
215
|
-
<category term="#{term}"/>
|
216
|
-
EOA
|
217
|
-
|
218
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
219
|
-
<category term="#{term}" scheme="#{scheme}" label="#{label}"/>
|
220
|
-
EOA
|
221
|
-
|
222
|
-
category = yield(feed)
|
223
|
-
assert_not_nil(category)
|
224
|
-
assert_equal(term, category.term)
|
225
|
-
assert_equal(scheme, category.scheme)
|
226
|
-
assert_equal(label, category.label)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def assert_atom_link(generator)
|
231
|
-
_wrap_assertion do
|
232
|
-
href = "http://example.org/feed.atom"
|
233
|
-
rel = "self"
|
234
|
-
type = "application/atom+xml"
|
235
|
-
hreflang = "en"
|
236
|
-
title = "Atom"
|
237
|
-
length = "1024"
|
238
|
-
|
239
|
-
assert_parse(generator.call(<<-EOA), :missing_attribute, "link", "href")
|
240
|
-
<link/>
|
241
|
-
EOA
|
242
|
-
|
243
|
-
assert_parse(generator.call(<<-EOA), :missing_attribute, "link", "href")
|
244
|
-
<link rel="#{rel}" type="#{type}" hreflang="#{hreflang}"
|
245
|
-
title="#{title}" length="#{length}"/>
|
246
|
-
EOA
|
247
|
-
|
248
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
249
|
-
<link href="#{href}"/>
|
250
|
-
EOA
|
251
|
-
|
252
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
253
|
-
<link href="#{href}" rel="#{rel}" type="#{type}" hreflang="#{hreflang}"
|
254
|
-
title="#{title}" length="#{length}"/>
|
255
|
-
EOA
|
256
|
-
|
257
|
-
link = yield(feed)
|
258
|
-
assert_not_nil(link)
|
259
|
-
assert_equal(href, link.href)
|
260
|
-
assert_equal(rel, link.rel)
|
261
|
-
assert_equal(type, link.type)
|
262
|
-
assert_equal(hreflang, link.hreflang)
|
263
|
-
assert_equal(title, link.title)
|
264
|
-
assert_equal(length, link.length)
|
265
|
-
|
266
|
-
|
267
|
-
href = "http://example.org/index.html.ja"
|
268
|
-
parent = link.parent.tag_name
|
269
|
-
return if parent == "source"
|
270
|
-
|
271
|
-
optional_attributes = %w(hreflang="ja" type="text/html")
|
272
|
-
0.upto(optional_attributes.size) do |i|
|
273
|
-
combination(optional_attributes, i).each do |attributes|
|
274
|
-
attrs = attributes.join(" ")
|
275
|
-
assert_parse(generator.call(<<-EOA), :too_much_tag, "link", parent)
|
276
|
-
<link rel="alternate" #{attrs} href="#{href}"/>
|
277
|
-
<link rel="alternate" #{attrs} href="#{href}"/>
|
278
|
-
EOA
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
def assert_atom_generator(generator)
|
285
|
-
_wrap_assertion do
|
286
|
-
uri = "http://www.example.com/"
|
287
|
-
version = "1.0"
|
288
|
-
content = "Example Toolkit"
|
289
|
-
|
290
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
291
|
-
<generator/>
|
292
|
-
EOA
|
293
|
-
|
294
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
295
|
-
<generator uri="#{uri}" version="#{version}"/>
|
296
|
-
EOA
|
297
|
-
|
298
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
299
|
-
<generator uri="#{uri}" version="#{version}">#{content}</generator>
|
300
|
-
EOA
|
301
|
-
|
302
|
-
gen = yield(feed)
|
303
|
-
assert_not_nil(gen)
|
304
|
-
assert_equal(uri, gen.uri)
|
305
|
-
assert_equal(version, gen.version)
|
306
|
-
assert_equal(content, gen.content)
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
def assert_atom_icon(generator)
|
311
|
-
_wrap_assertion do
|
312
|
-
content = "http://www.example.com/example.png"
|
313
|
-
|
314
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
315
|
-
<icon/>
|
316
|
-
EOA
|
317
|
-
|
318
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
319
|
-
<icon>#{content}</icon>
|
320
|
-
EOA
|
321
|
-
|
322
|
-
icon = yield(feed)
|
323
|
-
assert_not_nil(icon)
|
324
|
-
assert_equal(content, icon.content)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
def assert_atom_text_construct(tag_name, generator)
|
329
|
-
_wrap_assertion do
|
330
|
-
[nil, "text", "html"].each do |type|
|
331
|
-
attr = ""
|
332
|
-
attr = " type=\"#{type}\"" if type
|
333
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
334
|
-
<#{tag_name}#{attr}/>
|
335
|
-
EOA
|
336
|
-
end
|
337
|
-
|
338
|
-
assert_parse(generator.call(<<-EOA), :missing_tag, "div", tag_name)
|
339
|
-
<#{tag_name} type="xhtml"/>
|
340
|
-
EOA
|
341
|
-
|
342
|
-
args = ["x", Atom::URI, tag_name]
|
343
|
-
assert_parse(generator.call(<<-EOA), :not_expected_tag, *args)
|
344
|
-
<#{tag_name} type="xhtml"><x/></#{tag_name}>
|
345
|
-
EOA
|
346
|
-
|
347
|
-
invalid_value = "invalid"
|
348
|
-
args = ["type", invalid_value]
|
349
|
-
assert_parse(generator.call(<<-EOA), :not_available_value, *args)
|
350
|
-
<#{tag_name} type="#{invalid_value}"/>
|
351
|
-
EOA
|
352
|
-
|
353
|
-
[
|
354
|
-
[nil, "A lot of effort went into making this effortless"],
|
355
|
-
["text", "A lot of effort went into making this effortless"],
|
356
|
-
["html", "A <em>lot</em> of effort went into making this effortless"],
|
357
|
-
].each do |type, content|
|
358
|
-
attr = ""
|
359
|
-
attr = " type=\"#{type}\"" if type
|
360
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
361
|
-
<#{tag_name}#{attr}>#{h content}</#{tag_name}>
|
362
|
-
EOA
|
363
|
-
|
364
|
-
element = yield(feed)
|
365
|
-
assert_not_nil(element)
|
366
|
-
assert_equal(type, element.type)
|
367
|
-
assert_equal(content, element.content)
|
368
|
-
end
|
369
|
-
|
370
|
-
[false, true].each do |with_space|
|
371
|
-
xhtml_uri = "http://www.w3.org/1999/xhtml"
|
372
|
-
xhtml_content = "<div xmlns=\"#{xhtml_uri}\">abc</div>"
|
373
|
-
xhtml_element = RSS::XML::Element.new("div", nil, xhtml_uri,
|
374
|
-
{"xmlns" => xhtml_uri},
|
375
|
-
["abc"])
|
376
|
-
content = xhtml_content
|
377
|
-
content = " #{content} " if with_space
|
378
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
379
|
-
<#{tag_name} type="xhtml">#{content}</#{tag_name}>
|
380
|
-
EOA
|
381
|
-
|
382
|
-
element = yield(feed)
|
383
|
-
assert_not_nil(element)
|
384
|
-
assert_equal("xhtml", element.type)
|
385
|
-
assert_equal(xhtml_content, element.content)
|
386
|
-
assert_equal(xhtml_element, element.xhtml)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
def assert_atom_date_construct(tag_name, generator)
|
392
|
-
_wrap_assertion do
|
393
|
-
args = [tag_name, ""]
|
394
|
-
assert_parse(generator.call(<<-EOR), :not_available_value, *args)
|
395
|
-
<#{tag_name}/>
|
396
|
-
EOR
|
397
|
-
|
398
|
-
[
|
399
|
-
["xxx", false],
|
400
|
-
["2007", false],
|
401
|
-
["2007/02/09", true],
|
402
|
-
].each do |invalid_value, can_parse|
|
403
|
-
assert_not_available_value(tag_name, invalid_value) do
|
404
|
-
RSS::Parser.parse(generator.call(<<-EOR))
|
405
|
-
<#{tag_name}>#{invalid_value}</#{tag_name}>
|
406
|
-
EOR
|
407
|
-
end
|
408
|
-
|
409
|
-
feed = RSS::Parser.parse(generator.call(<<-EOR), false)
|
410
|
-
<#{tag_name}>#{invalid_value}</#{tag_name}>
|
411
|
-
EOR
|
412
|
-
value = yield(feed).content
|
413
|
-
if can_parse
|
414
|
-
assert_equal(Time.parse(invalid_value), value)
|
415
|
-
else
|
416
|
-
assert_nil(value)
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
[
|
421
|
-
"2003-12-13T18:30:02Z",
|
422
|
-
"2003-12-13T18:30:02.25Z",
|
423
|
-
"2003-12-13T18:30:02+01:00",
|
424
|
-
"2003-12-13T18:30:02.25+01:00",
|
425
|
-
].each do |valid_value|
|
426
|
-
assert_parse(generator.call(<<-EOR), :nothing_raised)
|
427
|
-
<#{tag_name}>#{valid_value}</#{tag_name}>
|
428
|
-
EOR
|
429
|
-
|
430
|
-
feed = RSS::Parser.parse(generator.call(<<-EOR))
|
431
|
-
<#{tag_name}>#{valid_value}</#{tag_name}>
|
432
|
-
EOR
|
433
|
-
assert_equal(Time.parse(valid_value), yield(feed).content)
|
434
|
-
end
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
def assert_atom_logo(generator)
|
439
|
-
_wrap_assertion do
|
440
|
-
content = "http://www.example.com/example.png"
|
441
|
-
|
442
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
443
|
-
<logo/>
|
444
|
-
EOA
|
445
|
-
|
446
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
447
|
-
<logo>#{content}</logo>
|
448
|
-
EOA
|
449
|
-
|
450
|
-
logo = yield(feed)
|
451
|
-
assert_not_nil(logo)
|
452
|
-
assert_equal(content, logo.content)
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
def assert_atom_content(generator, &getter)
|
457
|
-
_wrap_assertion do
|
458
|
-
assert_atom_content_inline_text(generator, &getter)
|
459
|
-
assert_atom_content_inline_xhtml(generator, &getter)
|
460
|
-
assert_atom_content_inline_other(generator, &getter)
|
461
|
-
assert_atom_content_out_of_line(generator, &getter)
|
462
|
-
end
|
463
|
-
end
|
464
|
-
|
465
|
-
def assert_atom_content_inline_text(generator)
|
466
|
-
_wrap_assertion do
|
467
|
-
[nil, "text", "html"].each do |type|
|
468
|
-
content = "<content"
|
469
|
-
content << " type='#{type}'" if type
|
470
|
-
|
471
|
-
suffix = "/>"
|
472
|
-
assert_parse(generator.call(content + suffix), :nothing_raised)
|
473
|
-
suffix = ">xxx</content>"
|
474
|
-
assert_parse(generator.call(content + suffix), :nothing_raised)
|
475
|
-
end
|
476
|
-
|
477
|
-
[
|
478
|
-
["text", "sample content"],
|
479
|
-
["text/plain", "sample content"],
|
480
|
-
["html", "<em>sample</em> content"]
|
481
|
-
].each do |type, content_content|
|
482
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
483
|
-
<content type="#{type}">#{h content_content}</content>
|
484
|
-
EOA
|
485
|
-
content = yield(feed)
|
486
|
-
assert_equal(type, content.type)
|
487
|
-
if %w(text html).include?(type)
|
488
|
-
assert(content.inline_text?)
|
489
|
-
else
|
490
|
-
assert(!content.inline_text?)
|
491
|
-
end
|
492
|
-
if type == "html"
|
493
|
-
assert(content.inline_html?)
|
494
|
-
else
|
495
|
-
assert(!content.inline_html?)
|
496
|
-
end
|
497
|
-
assert(!content.inline_xhtml?)
|
498
|
-
if type == "text/plain"
|
499
|
-
assert(content.inline_other?)
|
500
|
-
assert(content.inline_other_text?)
|
501
|
-
else
|
502
|
-
assert(!content.inline_other?)
|
503
|
-
assert(!content.inline_other_text?)
|
504
|
-
end
|
505
|
-
assert(!content.inline_other_xml?)
|
506
|
-
assert(!content.inline_other_base64?)
|
507
|
-
assert(!content.out_of_line?)
|
508
|
-
assert(!content.have_xml_content?)
|
509
|
-
assert_equal(content_content, content.content)
|
510
|
-
end
|
511
|
-
end
|
512
|
-
end
|
513
|
-
|
514
|
-
def assert_atom_content_inline_xhtml(generator)
|
515
|
-
_wrap_assertion do
|
516
|
-
args = ["div", "content"]
|
517
|
-
assert_parse(generator.call(<<-EOA), :missing_tag, *args)
|
518
|
-
<content type="xhtml"/>
|
519
|
-
EOA
|
520
|
-
|
521
|
-
args = ["x", Atom::URI, "content"]
|
522
|
-
assert_parse(generator.call(<<-EOA), :not_expected_tag, *args)
|
523
|
-
<content type="xhtml"><x/></content>
|
524
|
-
EOA
|
525
|
-
|
526
|
-
xhtml_uri = "http://www.w3.org/1999/xhtml"
|
527
|
-
xhtml_content = "<div xmlns=\"#{xhtml_uri}\">abc</div>"
|
528
|
-
xhtml_element = RSS::XML::Element.new("div", nil, xhtml_uri,
|
529
|
-
{"xmlns" => xhtml_uri},
|
530
|
-
["abc"])
|
531
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
532
|
-
<content type="xhtml">#{xhtml_content}</content>
|
533
|
-
EOA
|
534
|
-
|
535
|
-
content = yield(feed)
|
536
|
-
assert_not_nil(content)
|
537
|
-
assert_equal("xhtml", content.type)
|
538
|
-
assert(!content.inline_text?)
|
539
|
-
assert(!content.inline_html?)
|
540
|
-
assert(content.inline_xhtml?)
|
541
|
-
assert(!content.inline_other?)
|
542
|
-
assert(!content.inline_other_text?)
|
543
|
-
assert(!content.inline_other_xml?)
|
544
|
-
assert(!content.inline_other_base64?)
|
545
|
-
assert(!content.out_of_line?)
|
546
|
-
assert(content.have_xml_content?)
|
547
|
-
assert_equal(xhtml_content, content.content)
|
548
|
-
assert_equal(xhtml_element, content.xhtml)
|
549
|
-
end
|
550
|
-
end
|
551
|
-
|
552
|
-
def assert_atom_content_inline_other(generator, &getter)
|
553
|
-
_wrap_assertion do
|
554
|
-
assert_atom_content_inline_other_text(generator, &getter)
|
555
|
-
assert_atom_content_inline_other_xml(generator, &getter)
|
556
|
-
end
|
557
|
-
end
|
558
|
-
|
559
|
-
def assert_atom_content_inline_other_text(generator)
|
560
|
-
_wrap_assertion do
|
561
|
-
type = "image/png"
|
562
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
563
|
-
<content type="#{type}"/>
|
564
|
-
EOA
|
565
|
-
|
566
|
-
png_file = File.join(File.dirname(__FILE__), "dot.png")
|
567
|
-
png = File.open(png_file, "rb") do |file|
|
568
|
-
file.read.force_encoding("binary")
|
569
|
-
end
|
570
|
-
base64_content = [png].pack("m").delete("\n")
|
571
|
-
|
572
|
-
[false, true].each do |with_space|
|
573
|
-
xml_content = base64_content
|
574
|
-
xml_content = " #{base64_content}" if with_space
|
575
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
576
|
-
<content type="#{type}">#{xml_content}</content>
|
577
|
-
EOA
|
578
|
-
|
579
|
-
content = yield(feed)
|
580
|
-
assert_not_nil(content)
|
581
|
-
assert_equal(type, content.type)
|
582
|
-
assert(!content.inline_text?)
|
583
|
-
assert(!content.inline_html?)
|
584
|
-
assert(!content.inline_xhtml?)
|
585
|
-
assert(content.inline_other?)
|
586
|
-
assert(!content.inline_other_text?)
|
587
|
-
assert(!content.inline_other_xml?)
|
588
|
-
assert(content.inline_other_base64?)
|
589
|
-
assert(!content.out_of_line?)
|
590
|
-
assert(!content.have_xml_content?)
|
591
|
-
assert_equal(png, content.content)
|
592
|
-
|
593
|
-
xml = REXML::Document.new(content.to_s).root
|
594
|
-
assert_rexml_element([], {"type" => type}, base64_content, xml)
|
595
|
-
end
|
596
|
-
end
|
597
|
-
end
|
598
|
-
|
599
|
-
def assert_atom_content_inline_other_xml(generator)
|
600
|
-
_wrap_assertion do
|
601
|
-
type = "image/svg+xml"
|
602
|
-
|
603
|
-
assert_parse(generator.call(<<-EOA), :nothing_raised)
|
604
|
-
<content type="#{type}"/>
|
605
|
-
EOA
|
606
|
-
|
607
|
-
svg_uri = "http://www.w3.org/2000/svg"
|
608
|
-
svg_width = "50pt"
|
609
|
-
svg_height = "20pt"
|
610
|
-
svg_version = "1.0"
|
611
|
-
text_x = "15"
|
612
|
-
text_y = "15"
|
613
|
-
text = "text"
|
614
|
-
svg_content = <<-EOS
|
615
|
-
<svg
|
616
|
-
xmlns="#{svg_uri}"
|
617
|
-
width="#{svg_width}"
|
618
|
-
height="#{svg_height}"
|
619
|
-
version="#{svg_version}"
|
620
|
-
><text x="#{text_x}" y="#{text_y}">#{text}</text
|
621
|
-
></svg>
|
622
|
-
EOS
|
623
|
-
|
624
|
-
text_element = RSS::XML::Element.new("text", nil, svg_uri,
|
625
|
-
{
|
626
|
-
"x" => text_x,
|
627
|
-
"y" => text_y,
|
628
|
-
},
|
629
|
-
[text])
|
630
|
-
svg_element = RSS::XML::Element.new("svg", nil, svg_uri,
|
631
|
-
{
|
632
|
-
"xmlns" => svg_uri,
|
633
|
-
"width" => svg_width,
|
634
|
-
"height" => svg_height,
|
635
|
-
"version" => svg_version,
|
636
|
-
},
|
637
|
-
[text_element])
|
638
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
639
|
-
<content type="#{type}">#{svg_content}</content>
|
640
|
-
EOA
|
641
|
-
|
642
|
-
content = yield(feed)
|
643
|
-
assert_not_nil(content)
|
644
|
-
assert_equal(type, content.type)
|
645
|
-
assert(!content.inline_text?)
|
646
|
-
assert(!content.inline_html?)
|
647
|
-
assert(!content.inline_xhtml?)
|
648
|
-
assert(content.inline_other?)
|
649
|
-
assert(!content.inline_other_text?)
|
650
|
-
assert(content.inline_other_xml?)
|
651
|
-
assert(!content.inline_other_base64?)
|
652
|
-
assert(!content.out_of_line?)
|
653
|
-
assert(content.have_xml_content?)
|
654
|
-
assert_equal(REXML::Document.new(svg_content).to_s.chomp,
|
655
|
-
REXML::Document.new(content.content).to_s.chomp)
|
656
|
-
assert_equal(svg_element, content.xml)
|
657
|
-
assert_nil(content.xhtml)
|
658
|
-
end
|
659
|
-
end
|
660
|
-
|
661
|
-
def assert_atom_content_out_of_line(generator)
|
662
|
-
_wrap_assertion do
|
663
|
-
text_type = "text/plain"
|
664
|
-
text_src = "http://example.com/README.txt"
|
665
|
-
|
666
|
-
missing_args = [:missing_attribute, "content", "type"]
|
667
|
-
# RSS Parser raises error even if this is "should" not "must".
|
668
|
-
assert_parse(generator.call(<<-EOA), *missing_args)
|
669
|
-
<content src="#{text_src}"/>
|
670
|
-
EOA
|
671
|
-
|
672
|
-
content_content = "xxx"
|
673
|
-
not_available_value_args = [:not_available_value,
|
674
|
-
"content", content_content]
|
675
|
-
assert_parse(generator.call(<<-EOA), *not_available_value_args)
|
676
|
-
<content type="#{text_type}" src="#{text_src}">#{content_content}</content>
|
677
|
-
EOA
|
678
|
-
|
679
|
-
feed = RSS::Parser.parse(generator.call(<<-EOA))
|
680
|
-
<content type="#{text_type}" src="#{text_src}"/>
|
681
|
-
EOA
|
682
|
-
content = yield(feed)
|
683
|
-
assert_not_nil(content)
|
684
|
-
assert_equal(text_type, content.type)
|
685
|
-
assert_equal(text_src, content.src)
|
686
|
-
assert(!content.inline_text?)
|
687
|
-
assert(!content.inline_html?)
|
688
|
-
assert(!content.inline_xhtml?)
|
689
|
-
assert(!content.inline_other?)
|
690
|
-
assert(!content.inline_other_text?)
|
691
|
-
assert(!content.inline_other_xml?)
|
692
|
-
assert(!content.inline_other_base64?)
|
693
|
-
assert(content.out_of_line?)
|
694
|
-
assert(!content.have_xml_content?)
|
695
|
-
assert_nil(content.xml)
|
696
|
-
assert_nil(content.xhtml)
|
697
|
-
assert_equal("", content.content)
|
698
|
-
end
|
699
|
-
end
|
700
|
-
|
701
|
-
def assert_atom_source(generator, &getter)
|
702
|
-
_wrap_assertion do
|
703
|
-
assert_atom_source_author(generator, &getter)
|
704
|
-
assert_atom_source_category(generator, &getter)
|
705
|
-
assert_atom_source_contributor(generator, &getter)
|
706
|
-
assert_atom_source_generator(generator, &getter)
|
707
|
-
assert_atom_source_icon(generator, &getter)
|
708
|
-
assert_atom_source_id(generator, &getter)
|
709
|
-
assert_atom_source_link(generator, &getter)
|
710
|
-
assert_atom_source_logo(generator, &getter)
|
711
|
-
assert_atom_source_rights(generator, &getter)
|
712
|
-
assert_atom_source_subtitle(generator, &getter)
|
713
|
-
assert_atom_source_title(generator, &getter)
|
714
|
-
assert_atom_source_updated(generator, &getter)
|
715
|
-
end
|
716
|
-
end
|
717
|
-
|
718
|
-
def assert_atom_source_author(generator)
|
719
|
-
assert_atom_person("author", generator) do |feed|
|
720
|
-
source = yield(feed)
|
721
|
-
assert_equal(1, source.authors.size)
|
722
|
-
source.author
|
723
|
-
end
|
724
|
-
end
|
725
|
-
|
726
|
-
def assert_atom_source_category(generator)
|
727
|
-
assert_atom_category(generator) do |feed|
|
728
|
-
source = yield(feed)
|
729
|
-
assert_equal(1, source.categories.size)
|
730
|
-
source.category
|
731
|
-
end
|
732
|
-
end
|
733
|
-
|
734
|
-
def assert_atom_source_contributor(generator)
|
735
|
-
assert_atom_person("contributor", generator) do |feed|
|
736
|
-
source = yield(feed)
|
737
|
-
assert_equal(1, source.contributors.size)
|
738
|
-
source.contributor
|
739
|
-
end
|
740
|
-
end
|
741
|
-
|
742
|
-
def assert_atom_source_generator(generator)
|
743
|
-
assert_atom_generator(generator) do |feed|
|
744
|
-
yield(feed).generator
|
745
|
-
end
|
746
|
-
end
|
747
|
-
|
748
|
-
def assert_atom_source_icon(generator)
|
749
|
-
assert_atom_icon(generator) do |feed|
|
750
|
-
yield(feed).icon
|
751
|
-
end
|
752
|
-
end
|
753
|
-
|
754
|
-
def assert_atom_source_id(generator)
|
755
|
-
id_content = "urn:uuid:a2fb588b-5674-4898-b420-265a734fea69"
|
756
|
-
id = "<id>#{id_content}</id>"
|
757
|
-
feed = RSS::Parser.parse(generator.call(id))
|
758
|
-
assert_equal(id_content, yield(feed).id.content)
|
759
|
-
end
|
760
|
-
|
761
|
-
def assert_atom_source_link(generator)
|
762
|
-
assert_atom_link(generator) do |feed|
|
763
|
-
source = yield(feed)
|
764
|
-
assert_equal(1, source.links.size)
|
765
|
-
source.link
|
766
|
-
end
|
767
|
-
end
|
768
|
-
|
769
|
-
def assert_atom_source_logo(generator)
|
770
|
-
assert_atom_logo(generator) do |feed|
|
771
|
-
yield(feed).logo
|
772
|
-
end
|
773
|
-
end
|
774
|
-
|
775
|
-
def assert_atom_source_rights(generator)
|
776
|
-
assert_atom_text_construct("rights", generator) do |feed|
|
777
|
-
yield(feed).rights
|
778
|
-
end
|
779
|
-
end
|
780
|
-
|
781
|
-
def assert_atom_source_subtitle(generator)
|
782
|
-
assert_atom_text_construct("subtitle", generator) do |feed|
|
783
|
-
yield(feed).subtitle
|
784
|
-
end
|
785
|
-
end
|
786
|
-
|
787
|
-
def assert_atom_source_title(generator)
|
788
|
-
assert_atom_text_construct("title", generator) do |feed|
|
789
|
-
yield(feed).title
|
790
|
-
end
|
791
|
-
end
|
792
|
-
|
793
|
-
def assert_atom_source_updated(generator)
|
794
|
-
assert_atom_date_construct("updated", generator) do |feed|
|
795
|
-
yield(feed).updated
|
796
|
-
end
|
797
|
-
end
|
798
|
-
|
799
|
-
def assert_dublin_core(elems, target)
|
800
|
-
_wrap_assertion do
|
801
|
-
elems.each do |name, value|
|
802
|
-
assert_equal(value, target.__send__("dc_#{name}"))
|
803
|
-
end
|
804
|
-
end
|
805
|
-
end
|
806
|
-
|
807
|
-
def assert_multiple_dublin_core(elems, target)
|
808
|
-
_wrap_assertion do
|
809
|
-
elems.each do |name, values, plural|
|
810
|
-
plural ||= "#{name}s"
|
811
|
-
actual = target.__send__("dc_#{plural}").collect{|x| x.value}
|
812
|
-
assert_equal(values, actual)
|
813
|
-
end
|
814
|
-
end
|
815
|
-
end
|
816
|
-
|
817
|
-
def assert_syndication(elems, target)
|
818
|
-
_wrap_assertion do
|
819
|
-
elems.each do |name, value|
|
820
|
-
meth = "sy_#{name}"
|
821
|
-
value = value.to_i if meth == "sy_updateFrequency"
|
822
|
-
assert_equal(value, target.__send__(meth ))
|
823
|
-
end
|
824
|
-
end
|
825
|
-
end
|
826
|
-
|
827
|
-
def assert_content(elems, target)
|
828
|
-
_wrap_assertion do
|
829
|
-
elems.each do |name, value|
|
830
|
-
assert_equal(value, target.__send__("content_#{name}"))
|
831
|
-
end
|
832
|
-
end
|
833
|
-
end
|
834
|
-
|
835
|
-
def assert_trackback(attrs, target)
|
836
|
-
_wrap_assertion do
|
837
|
-
n_attrs = normalized_attrs(attrs)
|
838
|
-
if n_attrs["ping"]
|
839
|
-
assert_equal(n_attrs["ping"], target.trackback_ping)
|
840
|
-
end
|
841
|
-
if n_attrs["abouts"]
|
842
|
-
n_attrs["abouts"].each_with_index do |about, i|
|
843
|
-
assert_equal(about, target.trackback_abouts[i].value)
|
844
|
-
end
|
845
|
-
end
|
846
|
-
end
|
847
|
-
end
|
848
|
-
|
849
|
-
def assert_taxo_topic(topics, target)
|
850
|
-
_wrap_assertion do
|
851
|
-
topics.each_with_index do |topic, i|
|
852
|
-
taxo_topic = target.taxo_topics[i]
|
853
|
-
topic.each do |name, value|
|
854
|
-
case name
|
855
|
-
when :link
|
856
|
-
assert_equal(value, taxo_topic.about)
|
857
|
-
assert_equal(value, taxo_topic.taxo_link)
|
858
|
-
when :topics
|
859
|
-
assert_equal(value, taxo_topic.taxo_topics.resources)
|
860
|
-
else
|
861
|
-
assert_equal(value, taxo_topic.__send__("dc_#{name}"))
|
862
|
-
end
|
863
|
-
end
|
864
|
-
end
|
865
|
-
end
|
866
|
-
end
|
867
|
-
|
868
|
-
|
869
|
-
def assert_attributes(attrs, names, target)
|
870
|
-
_wrap_assertion do
|
871
|
-
n_attrs = normalized_attrs(attrs)
|
872
|
-
names.each do |info|
|
873
|
-
if info.is_a?(String)
|
874
|
-
name = info
|
875
|
-
type = nil
|
876
|
-
else
|
877
|
-
name, type = info
|
878
|
-
end
|
879
|
-
value = n_attrs[name]
|
880
|
-
if value.is_a?(Time)
|
881
|
-
actual = target.__send__(name)
|
882
|
-
assert_instance_of(Time, actual)
|
883
|
-
assert_equal(value.to_i, actual.to_i)
|
884
|
-
elsif value
|
885
|
-
case type
|
886
|
-
when :integer
|
887
|
-
value = value.to_i
|
888
|
-
when :boolean
|
889
|
-
value = value == "true" if value.is_a?(String)
|
890
|
-
end
|
891
|
-
assert_equal(value, target.__send__(name))
|
892
|
-
end
|
893
|
-
end
|
894
|
-
end
|
895
|
-
end
|
896
|
-
|
897
|
-
def assert_rexml_element(children, attrs, text, element, text_type=nil)
|
898
|
-
_wrap_assertion do
|
899
|
-
if children
|
900
|
-
children_info = element.elements.collect {|e| [e.namespace, e.name]}
|
901
|
-
assert_equal(children.collect {|uri, name| [uri, name]}.sort,
|
902
|
-
children_info.sort)
|
903
|
-
end
|
904
|
-
if attrs
|
905
|
-
assert_equal(attrs.collect {|k, v| [k, v]}.sort,
|
906
|
-
element.attributes.collect {|k, v| [k, v]}.sort)
|
907
|
-
end
|
908
|
-
case text_type
|
909
|
-
when :time
|
910
|
-
assert_not_nil(element.text)
|
911
|
-
assert_equal(Time.parse(text).to_s, Time.parse(element.text).to_s)
|
912
|
-
else
|
913
|
-
assert_equal(text, element.text)
|
914
|
-
end
|
915
|
-
end
|
916
|
-
end
|
917
|
-
|
918
|
-
def _assert_maker_atom_persons(feed_type, maker_readers, feed_readers)
|
919
|
-
_wrap_assertion do
|
920
|
-
persons = []
|
921
|
-
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
|
922
|
-
yield maker
|
923
|
-
targets = chain_reader(maker, maker_readers)
|
924
|
-
targets.each do |target|
|
925
|
-
person = {
|
926
|
-
:name => target.name,
|
927
|
-
:uri => target.uri,
|
928
|
-
:email => target.email,
|
929
|
-
}
|
930
|
-
persons << person if person[:name]
|
931
|
-
end
|
932
|
-
end
|
933
|
-
|
934
|
-
actual_persons = chain_reader(feed, feed_readers) || []
|
935
|
-
actual_persons = actual_persons.collect do |person|
|
936
|
-
{
|
937
|
-
:name => person.name ? person.name.content : nil,
|
938
|
-
:uri => person.uri ? person.uri.content : nil,
|
939
|
-
:email => person.email ? person.email.content : nil,
|
940
|
-
}
|
941
|
-
end
|
942
|
-
assert_equal(persons, actual_persons)
|
943
|
-
end
|
944
|
-
end
|
945
|
-
|
946
|
-
def assert_maker_atom_persons(feed_type, maker_readers, feed_readers,
|
947
|
-
not_set_error_name=nil,
|
948
|
-
parent_not_set_error_name=nil,
|
949
|
-
parent_not_set_variable=nil)
|
950
|
-
_wrap_assertion do
|
951
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
952
|
-
|
953
|
-
args = [feed_type, maker_readers, feed_readers]
|
954
|
-
if parent_not_set_error_name or parent_not_set_variable
|
955
|
-
assert_not_set_error(parent_not_set_error_name,
|
956
|
-
parent_not_set_variable) do
|
957
|
-
_assert_maker_atom_persons(*args) do |maker|
|
958
|
-
yield maker
|
959
|
-
end
|
960
|
-
end
|
961
|
-
else
|
962
|
-
_assert_maker_atom_persons(*args) do |maker|
|
963
|
-
yield maker
|
964
|
-
end
|
965
|
-
end
|
966
|
-
|
967
|
-
assert_not_set_error(not_set_error_name, %w(name)) do
|
968
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
969
|
-
feed_readers) do |maker|
|
970
|
-
yield maker
|
971
|
-
targets = chain_reader(maker, maker_readers)
|
972
|
-
targets.new_child
|
973
|
-
end
|
974
|
-
end
|
975
|
-
|
976
|
-
assert_not_set_error(not_set_error_name, %w(name)) do
|
977
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
978
|
-
feed_readers) do |maker|
|
979
|
-
yield maker
|
980
|
-
targets = chain_reader(maker, maker_readers)
|
981
|
-
target = targets.new_child
|
982
|
-
target.uri = "http://example.com/~me/"
|
983
|
-
end
|
984
|
-
end
|
985
|
-
|
986
|
-
assert_not_set_error(not_set_error_name, %w(name)) do
|
987
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
988
|
-
feed_readers) do |maker|
|
989
|
-
yield maker
|
990
|
-
targets = chain_reader(maker, maker_readers)
|
991
|
-
target = targets.new_child
|
992
|
-
target.email = "me@example.com"
|
993
|
-
end
|
994
|
-
end
|
995
|
-
|
996
|
-
assert_not_set_error(not_set_error_name, %w(name)) do
|
997
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
998
|
-
feed_readers) do |maker|
|
999
|
-
yield maker
|
1000
|
-
targets = chain_reader(maker, maker_readers)
|
1001
|
-
target = targets.new_child
|
1002
|
-
target.uri = "http://example.com/~me/"
|
1003
|
-
target.email = "me@example.com"
|
1004
|
-
end
|
1005
|
-
end
|
1006
|
-
|
1007
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
1008
|
-
feed_readers) do |maker|
|
1009
|
-
yield maker
|
1010
|
-
targets = chain_reader(maker, maker_readers)
|
1011
|
-
target = targets.new_child
|
1012
|
-
target.name = "me"
|
1013
|
-
end
|
1014
|
-
|
1015
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
1016
|
-
feed_readers) do |maker|
|
1017
|
-
yield maker
|
1018
|
-
targets = chain_reader(maker, maker_readers)
|
1019
|
-
target = targets.new_child
|
1020
|
-
target.name = "me"
|
1021
|
-
target.uri = "http://example.com/~me/"
|
1022
|
-
end
|
1023
|
-
|
1024
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
1025
|
-
feed_readers) do |maker|
|
1026
|
-
yield maker
|
1027
|
-
targets = chain_reader(maker, maker_readers)
|
1028
|
-
target = targets.new_child
|
1029
|
-
target.name = "me"
|
1030
|
-
target.email = "me@example.com"
|
1031
|
-
end
|
1032
|
-
|
1033
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
1034
|
-
feed_readers) do |maker|
|
1035
|
-
yield maker
|
1036
|
-
targets = chain_reader(maker, maker_readers)
|
1037
|
-
target = targets.new_child
|
1038
|
-
target.name = "me"
|
1039
|
-
target.uri = "http://example.com/~me/"
|
1040
|
-
target.email = "me@example.com"
|
1041
|
-
end
|
1042
|
-
|
1043
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
1044
|
-
feed_readers) do |maker|
|
1045
|
-
yield maker
|
1046
|
-
targets = chain_reader(maker, maker_readers)
|
1047
|
-
|
1048
|
-
target = targets.new_child
|
1049
|
-
target.name = "me"
|
1050
|
-
target.uri = "http://example.com/~me/"
|
1051
|
-
target.email = "me@example.com"
|
1052
|
-
|
1053
|
-
target = targets.new_child
|
1054
|
-
target.name = "you"
|
1055
|
-
target.uri = "http://example.com/~you/"
|
1056
|
-
target.email = "you@example.com"
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
assert_not_set_error(not_set_error_name, %w(name)) do
|
1060
|
-
_assert_maker_atom_persons(feed_type, maker_readers,
|
1061
|
-
feed_readers) do |maker|
|
1062
|
-
yield maker
|
1063
|
-
targets = chain_reader(maker, maker_readers)
|
1064
|
-
|
1065
|
-
target = targets.new_child
|
1066
|
-
target.name = "me"
|
1067
|
-
target.uri = "http://example.com/~me/"
|
1068
|
-
target.email = "me@example.com"
|
1069
|
-
|
1070
|
-
targets.new_child
|
1071
|
-
end
|
1072
|
-
end
|
1073
|
-
end
|
1074
|
-
end
|
1075
|
-
|
1076
|
-
def _assert_maker_atom_text_construct(feed_type, maker_readers,
|
1077
|
-
feed_readers, &block)
|
1078
|
-
maker_extractor = Proc.new do |target|
|
1079
|
-
text = {
|
1080
|
-
:type => target.type,
|
1081
|
-
:content => target.content,
|
1082
|
-
:xml_content => target.xml_content,
|
1083
|
-
}
|
1084
|
-
if text[:type] == "xhtml"
|
1085
|
-
if text[:xml_content]
|
1086
|
-
xml_content = text[:xml_content]
|
1087
|
-
xhtml_uri = "http://www.w3.org/1999/xhtml"
|
1088
|
-
unless xml_content.is_a?(RSS::XML::Element) and
|
1089
|
-
["div", xhtml_uri] == [xml_content.name, xml_content.uri]
|
1090
|
-
children = xml_content
|
1091
|
-
children = [children] unless children.is_a?(Array)
|
1092
|
-
xml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
|
1093
|
-
{"xmlns" => xhtml_uri},
|
1094
|
-
children)
|
1095
|
-
text[:xml_content] = xml_content
|
1096
|
-
end
|
1097
|
-
text
|
1098
|
-
else
|
1099
|
-
nil
|
1100
|
-
end
|
1101
|
-
else
|
1102
|
-
text[:content] ? text : nil
|
1103
|
-
end
|
1104
|
-
end
|
1105
|
-
feed_extractor = Proc.new do |target|
|
1106
|
-
{
|
1107
|
-
:type => target.type,
|
1108
|
-
:content => target.content,
|
1109
|
-
:xml_content => target.xhtml,
|
1110
|
-
}
|
1111
|
-
end
|
1112
|
-
_assert_maker_atom_element(feed_type,
|
1113
|
-
maker_readers, true,
|
1114
|
-
feed_readers,
|
1115
|
-
maker_extractor,
|
1116
|
-
feed_extractor,
|
1117
|
-
&block)
|
1118
|
-
end
|
1119
|
-
|
1120
|
-
def assert_maker_atom_text_construct(feed_type, maker_readers, feed_readers,
|
1121
|
-
parent_not_set_error_name=nil,
|
1122
|
-
parent_not_set_variable=nil,
|
1123
|
-
not_set_error_name=nil)
|
1124
|
-
_wrap_assertion do
|
1125
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1126
|
-
|
1127
|
-
args = [feed_type, maker_readers, feed_readers]
|
1128
|
-
if parent_not_set_error_name or parent_not_set_variable
|
1129
|
-
assert_not_set_error(parent_not_set_error_name,
|
1130
|
-
parent_not_set_variable) do
|
1131
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1132
|
-
yield maker
|
1133
|
-
end
|
1134
|
-
end
|
1135
|
-
else
|
1136
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1137
|
-
yield maker
|
1138
|
-
end
|
1139
|
-
end
|
1140
|
-
|
1141
|
-
assert_not_set_error(not_set_error_name, %w(content)) do
|
1142
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1143
|
-
yield maker
|
1144
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1145
|
-
target.type = "text"
|
1146
|
-
end
|
1147
|
-
end
|
1148
|
-
|
1149
|
-
assert_not_set_error(not_set_error_name, %w(content)) do
|
1150
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1151
|
-
yield maker
|
1152
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1153
|
-
target.type = "html"
|
1154
|
-
end
|
1155
|
-
end
|
1156
|
-
|
1157
|
-
assert_not_set_error(not_set_error_name, %w(xml_content)) do
|
1158
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1159
|
-
yield maker
|
1160
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1161
|
-
target.type = "xhtml"
|
1162
|
-
end
|
1163
|
-
end
|
1164
|
-
|
1165
|
-
assert_not_set_error(not_set_error_name, %w(xml_content)) do
|
1166
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1167
|
-
yield maker
|
1168
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1169
|
-
target.type = "xhtml"
|
1170
|
-
target.content = "Content"
|
1171
|
-
end
|
1172
|
-
end
|
1173
|
-
|
1174
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1175
|
-
yield maker
|
1176
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1177
|
-
target.type = "text"
|
1178
|
-
target.content = "Content"
|
1179
|
-
end
|
1180
|
-
|
1181
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1182
|
-
yield maker
|
1183
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1184
|
-
target.type = "html"
|
1185
|
-
target.content = "<em>Content</em>"
|
1186
|
-
end
|
1187
|
-
|
1188
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1189
|
-
yield maker
|
1190
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1191
|
-
target.type = "xhtml"
|
1192
|
-
target.xml_content = "text only"
|
1193
|
-
end
|
1194
|
-
|
1195
|
-
_assert_maker_atom_text_construct(*args) do |maker|
|
1196
|
-
yield maker
|
1197
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1198
|
-
target.type = "xhtml"
|
1199
|
-
target.xml_content = RSS::XML::Element.new("unknown")
|
1200
|
-
end
|
1201
|
-
end
|
1202
|
-
end
|
1203
|
-
|
1204
|
-
def _assert_maker_atom_date_construct(feed_type, maker_readers,
|
1205
|
-
feed_readers, &block)
|
1206
|
-
maker_extractor = Proc.new do |target|
|
1207
|
-
date = {
|
1208
|
-
:content => target,
|
1209
|
-
}
|
1210
|
-
date[:content] ? date : nil
|
1211
|
-
end
|
1212
|
-
feed_extractor = Proc.new do |target|
|
1213
|
-
{
|
1214
|
-
:content => target.content,
|
1215
|
-
}
|
1216
|
-
end
|
1217
|
-
_assert_maker_atom_element(feed_type,
|
1218
|
-
maker_readers, false,
|
1219
|
-
feed_readers,
|
1220
|
-
maker_extractor,
|
1221
|
-
feed_extractor,
|
1222
|
-
&block)
|
1223
|
-
end
|
1224
|
-
|
1225
|
-
def assert_maker_atom_date_construct(feed_type, maker_readers, feed_readers,
|
1226
|
-
parent_not_set_error_name=nil,
|
1227
|
-
parent_not_set_variable=nil)
|
1228
|
-
_wrap_assertion do
|
1229
|
-
args = [feed_type, maker_readers, feed_readers]
|
1230
|
-
if parent_not_set_error_name or parent_not_set_variable
|
1231
|
-
assert_not_set_error(parent_not_set_error_name,
|
1232
|
-
parent_not_set_variable) do
|
1233
|
-
_assert_maker_atom_date_construct(*args) do |maker|
|
1234
|
-
yield maker
|
1235
|
-
end
|
1236
|
-
end
|
1237
|
-
else
|
1238
|
-
_assert_maker_atom_date_construct(*args) do |maker|
|
1239
|
-
yield maker
|
1240
|
-
end
|
1241
|
-
end
|
1242
|
-
|
1243
|
-
maker_readers = maker_readers.dup
|
1244
|
-
writer = "#{maker_readers.pop}="
|
1245
|
-
_assert_maker_atom_date_construct(*args) do |maker|
|
1246
|
-
yield maker
|
1247
|
-
target = chain_reader(maker, maker_readers)
|
1248
|
-
target.__send__(writer, Time.now)
|
1249
|
-
end
|
1250
|
-
end
|
1251
|
-
end
|
1252
|
-
|
1253
|
-
def _assert_maker_atom_element(feed_type,
|
1254
|
-
maker_readers,
|
1255
|
-
maker_readers_need_block,
|
1256
|
-
feed_readers,
|
1257
|
-
maker_extractor,
|
1258
|
-
feed_extractor)
|
1259
|
-
_wrap_assertion do
|
1260
|
-
element = nil
|
1261
|
-
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1262
|
-
yield maker
|
1263
|
-
if maker_readers_need_block
|
1264
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1265
|
-
else
|
1266
|
-
target = chain_reader(maker, maker_readers)
|
1267
|
-
end
|
1268
|
-
element = maker_extractor.call(target)
|
1269
|
-
end
|
1270
|
-
|
1271
|
-
target = chain_reader(feed, feed_readers)
|
1272
|
-
if target
|
1273
|
-
actual_element = feed_extractor.call(target)
|
1274
|
-
else
|
1275
|
-
actual_element = nil
|
1276
|
-
end
|
1277
|
-
assert_equal(element, actual_element)
|
1278
|
-
end
|
1279
|
-
end
|
1280
|
-
|
1281
|
-
def _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
|
1282
|
-
maker_extractor, feed_extractor,
|
1283
|
-
invalid_feed_checker=nil)
|
1284
|
-
_wrap_assertion do
|
1285
|
-
elements = []
|
1286
|
-
invalid_feed_exception = nil
|
1287
|
-
feed = nil
|
1288
|
-
begin
|
1289
|
-
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1290
|
-
yield maker
|
1291
|
-
targets = chain_reader(maker, maker_readers)
|
1292
|
-
targets.each do |target|
|
1293
|
-
element = maker_extractor.call(target)
|
1294
|
-
elements << element if element
|
1295
|
-
end
|
1296
|
-
if invalid_feed_checker
|
1297
|
-
invalid_feed_exception = invalid_feed_checker.call(targets)
|
1298
|
-
end
|
1299
|
-
end
|
1300
|
-
rescue RSS::Error
|
1301
|
-
if invalid_feed_exception.is_a?(RSS::TooMuchTagError)
|
1302
|
-
assert_too_much_tag(invalid_feed_exception.tag,
|
1303
|
-
invalid_feed_exception.parent) do
|
1304
|
-
raise
|
1305
|
-
end
|
1306
|
-
else
|
1307
|
-
raise
|
1308
|
-
end
|
1309
|
-
end
|
1310
|
-
|
1311
|
-
if invalid_feed_exception.nil?
|
1312
|
-
actual_elements = chain_reader(feed, feed_readers) || []
|
1313
|
-
actual_elements = actual_elements.collect do |target|
|
1314
|
-
feed_extractor.call(target)
|
1315
|
-
end
|
1316
|
-
assert_equal(elements, actual_elements)
|
1317
|
-
end
|
1318
|
-
end
|
1319
|
-
end
|
1320
|
-
|
1321
|
-
def assert_maker_atom_element(feed_type, maker_readers, feed_readers,
|
1322
|
-
setup_target, optional_variables,
|
1323
|
-
required_variable, assert_method_name,
|
1324
|
-
not_set_error_name=nil,
|
1325
|
-
*additional_args)
|
1326
|
-
_wrap_assertion do
|
1327
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1328
|
-
|
1329
|
-
0.upto(optional_variables.size) do |i|
|
1330
|
-
combination(optional_variables, i).each do |names|
|
1331
|
-
have = {}
|
1332
|
-
names.each do |name|
|
1333
|
-
have[name.intern] = true
|
1334
|
-
end
|
1335
|
-
have_required_variable_too =
|
1336
|
-
have.merge({required_variable.intern => true})
|
1337
|
-
|
1338
|
-
assert_not_set_error(not_set_error_name, [required_variable]) do
|
1339
|
-
__send__(assert_method_name, feed_type, maker_readers,
|
1340
|
-
feed_readers, *additional_args) do |maker|
|
1341
|
-
yield maker
|
1342
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1343
|
-
setup_target.call(target, have)
|
1344
|
-
end
|
1345
|
-
end
|
1346
|
-
|
1347
|
-
__send__(assert_method_name, feed_type, maker_readers, feed_readers,
|
1348
|
-
*additional_args) do |maker|
|
1349
|
-
yield maker
|
1350
|
-
target = chain_reader(maker, maker_readers) {|x| x}
|
1351
|
-
setup_target.call(target, have_required_variable_too)
|
1352
|
-
end
|
1353
|
-
end
|
1354
|
-
end
|
1355
|
-
end
|
1356
|
-
end
|
1357
|
-
|
1358
|
-
def assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
|
1359
|
-
setup_target, optional_variables,
|
1360
|
-
required_variable, assert_method_name,
|
1361
|
-
not_set_error_name=nil,
|
1362
|
-
*additional_args)
|
1363
|
-
_wrap_assertion do
|
1364
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1365
|
-
|
1366
|
-
0.upto(optional_variables.size) do |i|
|
1367
|
-
combination(optional_variables, i).each do |names|
|
1368
|
-
have = {}
|
1369
|
-
names.each do |name|
|
1370
|
-
have[name.intern] = true
|
1371
|
-
end
|
1372
|
-
have_required_variable_too =
|
1373
|
-
have.merge({required_variable.intern => true})
|
1374
|
-
|
1375
|
-
assert_not_set_error(not_set_error_name, [required_variable]) do
|
1376
|
-
__send__(assert_method_name, feed_type, maker_readers,
|
1377
|
-
feed_readers, *additional_args) do |maker|
|
1378
|
-
yield maker
|
1379
|
-
targets = chain_reader(maker, maker_readers)
|
1380
|
-
setup_target.call(targets, have)
|
1381
|
-
end
|
1382
|
-
end
|
1383
|
-
|
1384
|
-
__send__(assert_method_name, feed_type, maker_readers, feed_readers,
|
1385
|
-
*additional_args) do |maker|
|
1386
|
-
yield maker
|
1387
|
-
targets = chain_reader(maker, maker_readers)
|
1388
|
-
setup_target.call(targets, have_required_variable_too)
|
1389
|
-
end
|
1390
|
-
|
1391
|
-
__send__(assert_method_name, feed_type, maker_readers, feed_readers,
|
1392
|
-
*additional_args) do |maker|
|
1393
|
-
yield maker
|
1394
|
-
targets = chain_reader(maker, maker_readers)
|
1395
|
-
setup_target.call(targets, have_required_variable_too)
|
1396
|
-
setup_target.call(targets, have_required_variable_too)
|
1397
|
-
end
|
1398
|
-
|
1399
|
-
assert_not_set_error(not_set_error_name, [required_variable]) do
|
1400
|
-
__send__(assert_method_name, feed_type, maker_readers, feed_readers,
|
1401
|
-
*additional_args) do |maker|
|
1402
|
-
yield maker
|
1403
|
-
targets = chain_reader(maker, maker_readers)
|
1404
|
-
setup_target.call(targets, have_required_variable_too)
|
1405
|
-
setup_target.call(targets, have)
|
1406
|
-
end
|
1407
|
-
end
|
1408
|
-
end
|
1409
|
-
end
|
1410
|
-
end
|
1411
|
-
end
|
1412
|
-
|
1413
|
-
def _assert_maker_atom_categories(feed_type, maker_readers,
|
1414
|
-
feed_readers, &block)
|
1415
|
-
maker_extractor = Proc.new do |target|
|
1416
|
-
category = {
|
1417
|
-
:term => target.term,
|
1418
|
-
:scheme => target.scheme,
|
1419
|
-
:label => target.label,
|
1420
|
-
}
|
1421
|
-
category[:term] ? category : nil
|
1422
|
-
end
|
1423
|
-
feed_extractor = Proc.new do |target|
|
1424
|
-
{
|
1425
|
-
:term => target.term,
|
1426
|
-
:scheme => target.scheme,
|
1427
|
-
:label => target.label,
|
1428
|
-
}
|
1429
|
-
end
|
1430
|
-
_assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
|
1431
|
-
maker_extractor, feed_extractor, &block)
|
1432
|
-
end
|
1433
|
-
|
1434
|
-
def assert_maker_atom_categories(feed_type, maker_readers, feed_readers,
|
1435
|
-
not_set_error_name=nil, &block)
|
1436
|
-
_wrap_assertion do
|
1437
|
-
_assert_maker_atom_categories(feed_type, maker_readers,
|
1438
|
-
feed_readers) do |maker|
|
1439
|
-
yield maker
|
1440
|
-
end
|
1441
|
-
|
1442
|
-
setup_target = Proc.new do |targets, have|
|
1443
|
-
target = targets.new_child
|
1444
|
-
target.term = "music" if have[:term]
|
1445
|
-
target.scheme = "http://example.com/category/music" if have[:scheme]
|
1446
|
-
target.label = "Music" if have[:label]
|
1447
|
-
end
|
1448
|
-
|
1449
|
-
optional_variables = %w(scheme label)
|
1450
|
-
|
1451
|
-
assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
|
1452
|
-
setup_target, optional_variables,
|
1453
|
-
"term", :_assert_maker_atom_categories,
|
1454
|
-
not_set_error_name, &block)
|
1455
|
-
end
|
1456
|
-
end
|
1457
|
-
|
1458
|
-
def _assert_maker_atom_generator(feed_type, maker_readers,
|
1459
|
-
feed_readers, &block)
|
1460
|
-
maker_extractor = Proc.new do |target|
|
1461
|
-
generator = {
|
1462
|
-
:uri => target.uri,
|
1463
|
-
:version => target.version,
|
1464
|
-
:content => target.content,
|
1465
|
-
}
|
1466
|
-
generator[:content] ? generator : nil
|
1467
|
-
end
|
1468
|
-
feed_extractor = Proc.new do |target|
|
1469
|
-
{
|
1470
|
-
:uri => target.uri,
|
1471
|
-
:version => target.version,
|
1472
|
-
:content => target.content,
|
1473
|
-
}
|
1474
|
-
end
|
1475
|
-
_assert_maker_atom_element(feed_type,
|
1476
|
-
maker_readers, true,
|
1477
|
-
feed_readers,
|
1478
|
-
maker_extractor,
|
1479
|
-
feed_extractor,
|
1480
|
-
&block)
|
1481
|
-
end
|
1482
|
-
|
1483
|
-
def assert_maker_atom_generator(feed_type, maker_readers, feed_readers,
|
1484
|
-
not_set_error_name=nil, &block)
|
1485
|
-
_wrap_assertion do
|
1486
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1487
|
-
|
1488
|
-
_assert_maker_atom_generator(feed_type, maker_readers,
|
1489
|
-
feed_readers) do |maker|
|
1490
|
-
yield maker
|
1491
|
-
end
|
1492
|
-
|
1493
|
-
setup_target = Proc.new do |target, have|
|
1494
|
-
target.content = "RSS Maker" if have[:content]
|
1495
|
-
target.uri = "http://example.com/rss/maker" if have[:uri]
|
1496
|
-
target.version = "0.0.1" if have[:version]
|
1497
|
-
end
|
1498
|
-
|
1499
|
-
optional_variables = %w(uri version)
|
1500
|
-
|
1501
|
-
assert_maker_atom_element(feed_type, maker_readers, feed_readers,
|
1502
|
-
setup_target, optional_variables,
|
1503
|
-
"content", :_assert_maker_atom_generator,
|
1504
|
-
not_set_error_name, &block)
|
1505
|
-
end
|
1506
|
-
end
|
1507
|
-
|
1508
|
-
def _assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
|
1509
|
-
accessor_base, &block)
|
1510
|
-
maker_extractor = Proc.new do |target|
|
1511
|
-
icon = {
|
1512
|
-
:content => target.__send__(accessor_base),
|
1513
|
-
}
|
1514
|
-
icon[:content] ? icon : nil
|
1515
|
-
end
|
1516
|
-
feed_extractor = Proc.new do |target|
|
1517
|
-
{
|
1518
|
-
:content => target.content,
|
1519
|
-
}
|
1520
|
-
end
|
1521
|
-
_assert_maker_atom_element(feed_type,
|
1522
|
-
maker_readers, true,
|
1523
|
-
feed_readers,
|
1524
|
-
maker_extractor,
|
1525
|
-
feed_extractor,
|
1526
|
-
&block)
|
1527
|
-
end
|
1528
|
-
|
1529
|
-
def assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
|
1530
|
-
accessor_base=nil, not_set_error_name=nil)
|
1531
|
-
_wrap_assertion do
|
1532
|
-
accessor_base ||= "url"
|
1533
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1534
|
-
|
1535
|
-
_assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
|
1536
|
-
accessor_base) do |maker|
|
1537
|
-
yield maker
|
1538
|
-
end
|
1539
|
-
|
1540
|
-
_assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
|
1541
|
-
accessor_base) do |maker|
|
1542
|
-
yield maker
|
1543
|
-
target = chain_reader(maker, maker_readers)
|
1544
|
-
target.__send__("#{accessor_base}=", "http://example.com/icon.png")
|
1545
|
-
end
|
1546
|
-
end
|
1547
|
-
end
|
1548
|
-
|
1549
|
-
def _assert_maker_atom_links(feed_type, maker_readers, feed_readers,
|
1550
|
-
allow_duplication=false, &block)
|
1551
|
-
maker_extractor = Proc.new do |target|
|
1552
|
-
link = {
|
1553
|
-
:href => target.href,
|
1554
|
-
:rel => target.rel,
|
1555
|
-
:type => target.type,
|
1556
|
-
:hreflang => target.hreflang,
|
1557
|
-
:title => target.title,
|
1558
|
-
:length => target.length,
|
1559
|
-
}
|
1560
|
-
link[:href] ? link : nil
|
1561
|
-
end
|
1562
|
-
feed_extractor = Proc.new do |target|
|
1563
|
-
{
|
1564
|
-
:href => target.href,
|
1565
|
-
:rel => target.rel,
|
1566
|
-
:type => target.type,
|
1567
|
-
:hreflang => target.hreflang,
|
1568
|
-
:title => target.title,
|
1569
|
-
:length => target.length,
|
1570
|
-
}
|
1571
|
-
end
|
1572
|
-
|
1573
|
-
if feed_readers.first == "entries"
|
1574
|
-
parent = "entry"
|
1575
|
-
else
|
1576
|
-
parent = feed_type
|
1577
|
-
end
|
1578
|
-
invalid_feed_checker = Proc.new do |targets|
|
1579
|
-
infos = {}
|
1580
|
-
invalid_exception = nil
|
1581
|
-
targets.each do |target|
|
1582
|
-
key = [target.hreflang, target.type]
|
1583
|
-
if infos.has_key?(key)
|
1584
|
-
invalid_exception = RSS::TooMuchTagError.new("link", parent)
|
1585
|
-
break
|
1586
|
-
end
|
1587
|
-
infos[key] = true if target.rel.nil? or target.rel == "alternate"
|
1588
|
-
end
|
1589
|
-
invalid_exception
|
1590
|
-
end
|
1591
|
-
invalid_feed_checker = nil if allow_duplication
|
1592
|
-
_assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
|
1593
|
-
maker_extractor, feed_extractor,
|
1594
|
-
invalid_feed_checker,
|
1595
|
-
&block)
|
1596
|
-
end
|
1597
|
-
|
1598
|
-
def assert_maker_atom_links(feed_type, maker_readers, feed_readers,
|
1599
|
-
not_set_error_name=nil, allow_duplication=false,
|
1600
|
-
&block)
|
1601
|
-
_wrap_assertion do
|
1602
|
-
_assert_maker_atom_links(feed_type, maker_readers,
|
1603
|
-
feed_readers) do |maker|
|
1604
|
-
yield maker
|
1605
|
-
end
|
1606
|
-
|
1607
|
-
langs = %(ja en fr zh po)
|
1608
|
-
setup_target = Proc.new do |targets, have|
|
1609
|
-
target = targets.new_child
|
1610
|
-
lang = langs[targets.size % langs.size]
|
1611
|
-
target.href = "http://example.com/index.html.#{lang}" if have[:href]
|
1612
|
-
target.rel = "alternate" if have[:rel]
|
1613
|
-
target.type = "text/xhtml" if have[:type]
|
1614
|
-
target.hreflang = lang if have[:hreflang]
|
1615
|
-
target.title = "FrontPage(#{lang})" if have[:title]
|
1616
|
-
target.length = 1024 if have[:length]
|
1617
|
-
end
|
1618
|
-
|
1619
|
-
optional_variables = %w(rel type hreflang title length)
|
1620
|
-
|
1621
|
-
assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
|
1622
|
-
setup_target, optional_variables,
|
1623
|
-
"href", :_assert_maker_atom_links,
|
1624
|
-
not_set_error_name, allow_duplication,
|
1625
|
-
&block)
|
1626
|
-
end
|
1627
|
-
end
|
1628
|
-
|
1629
|
-
def _assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
|
1630
|
-
accessor_base, &block)
|
1631
|
-
maker_extractor = Proc.new do |target|
|
1632
|
-
logo = {
|
1633
|
-
:uri => target.__send__(accessor_base),
|
1634
|
-
}
|
1635
|
-
logo[:uri] ? logo : nil
|
1636
|
-
end
|
1637
|
-
feed_extractor = Proc.new do |target|
|
1638
|
-
{
|
1639
|
-
:uri => target.content,
|
1640
|
-
}
|
1641
|
-
end
|
1642
|
-
_assert_maker_atom_element(feed_type,
|
1643
|
-
maker_readers, true,
|
1644
|
-
feed_readers,
|
1645
|
-
maker_extractor,
|
1646
|
-
feed_extractor,
|
1647
|
-
&block)
|
1648
|
-
end
|
1649
|
-
|
1650
|
-
def assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
|
1651
|
-
accessor_base=nil, not_set_error_name=nil)
|
1652
|
-
_wrap_assertion do
|
1653
|
-
accessor_base ||= "uri"
|
1654
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1655
|
-
|
1656
|
-
_assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
|
1657
|
-
accessor_base) do |maker|
|
1658
|
-
yield maker
|
1659
|
-
end
|
1660
|
-
|
1661
|
-
_assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
|
1662
|
-
accessor_base) do |maker|
|
1663
|
-
yield maker
|
1664
|
-
target = chain_reader(maker, maker_readers)
|
1665
|
-
target.__send__("#{accessor_base}=", "http://example.com/logo.png")
|
1666
|
-
end
|
1667
|
-
end
|
1668
|
-
end
|
1669
|
-
|
1670
|
-
def _assert_maker_atom_id(feed_type, maker_readers, feed_readers, &block)
|
1671
|
-
maker_extractor = Proc.new do |target|
|
1672
|
-
id = {
|
1673
|
-
:uri => target.id,
|
1674
|
-
}
|
1675
|
-
id[:uri] ? id : nil
|
1676
|
-
end
|
1677
|
-
feed_extractor = Proc.new do |target|
|
1678
|
-
if target.id
|
1679
|
-
{
|
1680
|
-
:uri => target.id.content,
|
1681
|
-
}
|
1682
|
-
else
|
1683
|
-
nil
|
1684
|
-
end
|
1685
|
-
end
|
1686
|
-
_assert_maker_atom_element(feed_type,
|
1687
|
-
maker_readers, true,
|
1688
|
-
feed_readers,
|
1689
|
-
maker_extractor,
|
1690
|
-
feed_extractor,
|
1691
|
-
&block)
|
1692
|
-
end
|
1693
|
-
|
1694
|
-
def assert_maker_atom_id(feed_type, maker_readers, feed_readers,
|
1695
|
-
not_set_error_name=nil)
|
1696
|
-
_wrap_assertion do
|
1697
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1698
|
-
|
1699
|
-
args = [feed_type, maker_readers, feed_readers]
|
1700
|
-
_assert_maker_atom_id(*args) do |maker|
|
1701
|
-
yield maker
|
1702
|
-
end
|
1703
|
-
|
1704
|
-
_assert_maker_atom_id(*args) do |maker|
|
1705
|
-
yield maker
|
1706
|
-
target = chain_reader(maker, maker_readers)
|
1707
|
-
target.id = "http://example.com/id/1"
|
1708
|
-
end
|
1709
|
-
end
|
1710
|
-
end
|
1711
|
-
|
1712
|
-
def _assert_maker_atom_content(feed_type, maker_readers,
|
1713
|
-
feed_readers, &block)
|
1714
|
-
maker_extractor = Proc.new do |target|
|
1715
|
-
content = {
|
1716
|
-
:type => target.type,
|
1717
|
-
:src => target.src,
|
1718
|
-
:content => target.content,
|
1719
|
-
:xml => target.xml,
|
1720
|
-
:inline_text => target.inline_text?,
|
1721
|
-
:inline_html => target.inline_html?,
|
1722
|
-
:inline_xhtml => target.inline_xhtml?,
|
1723
|
-
:inline_other => target.inline_other?,
|
1724
|
-
:inline_other_text => target.inline_other_text?,
|
1725
|
-
:inline_other_xml => target.inline_other_xml?,
|
1726
|
-
:inline_other_base64 => target.inline_other_base64?,
|
1727
|
-
:out_of_line => target.out_of_line?,
|
1728
|
-
}
|
1729
|
-
content[:src] = nil if content[:src] and content[:content]
|
1730
|
-
if content[:type] or content[:content]
|
1731
|
-
content
|
1732
|
-
else
|
1733
|
-
nil
|
1734
|
-
end
|
1735
|
-
end
|
1736
|
-
feed_extractor = Proc.new do |target|
|
1737
|
-
{
|
1738
|
-
:type => target.type,
|
1739
|
-
:src => target.src,
|
1740
|
-
:content => target.content,
|
1741
|
-
:xml => target.xml,
|
1742
|
-
:inline_text => target.inline_text?,
|
1743
|
-
:inline_html => target.inline_html?,
|
1744
|
-
:inline_xhtml => target.inline_xhtml?,
|
1745
|
-
:inline_other => target.inline_other?,
|
1746
|
-
:inline_other_text => target.inline_other_text?,
|
1747
|
-
:inline_other_xml => target.inline_other_xml?,
|
1748
|
-
:inline_other_base64 => target.inline_other_base64?,
|
1749
|
-
:out_of_line => target.out_of_line?,
|
1750
|
-
}
|
1751
|
-
end
|
1752
|
-
_assert_maker_atom_element(feed_type,
|
1753
|
-
maker_readers, true,
|
1754
|
-
feed_readers,
|
1755
|
-
maker_extractor,
|
1756
|
-
feed_extractor,
|
1757
|
-
&block)
|
1758
|
-
end
|
1759
|
-
|
1760
|
-
def assert_maker_atom_content(feed_type, maker_readers, feed_readers,
|
1761
|
-
not_set_error_name=nil, &block)
|
1762
|
-
_wrap_assertion do
|
1763
|
-
not_set_error_name ||= "maker.#{maker_readers.join('.')}"
|
1764
|
-
args = [feed_type, maker_readers, feed_readers, not_set_error_name]
|
1765
|
-
assert_maker_atom_content_inline_text(*args, &block)
|
1766
|
-
assert_maker_atom_content_inline_xhtml(*args, &block)
|
1767
|
-
assert_maker_atom_content_inline_other(*args, &block)
|
1768
|
-
assert_maker_atom_content_out_of_line(*args, &block)
|
1769
|
-
end
|
1770
|
-
end
|
1771
|
-
|
1772
|
-
def assert_maker_atom_content_inline_text(feed_type, maker_readers,
|
1773
|
-
feed_readers, not_set_error_name)
|
1774
|
-
_wrap_assertion do
|
1775
|
-
args = [feed_type, maker_readers, feed_readers]
|
1776
|
-
_assert_maker_atom_content(*args) do |maker|
|
1777
|
-
yield maker
|
1778
|
-
end
|
1779
|
-
|
1780
|
-
assert_not_set_error(not_set_error_name, %w(content)) do
|
1781
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1782
|
-
yield maker
|
1783
|
-
target = chain_reader(maker, maker_readers)
|
1784
|
-
target.type = "text"
|
1785
|
-
end
|
1786
|
-
end
|
1787
|
-
|
1788
|
-
assert_not_set_error(not_set_error_name, %w(content)) do
|
1789
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1790
|
-
yield maker
|
1791
|
-
target = chain_reader(maker, maker_readers)
|
1792
|
-
target.type = "html"
|
1793
|
-
end
|
1794
|
-
end
|
1795
|
-
|
1796
|
-
_assert_maker_atom_content(*args) do |maker|
|
1797
|
-
yield maker
|
1798
|
-
target = chain_reader(maker, maker_readers)
|
1799
|
-
target.content = ""
|
1800
|
-
end
|
1801
|
-
|
1802
|
-
_assert_maker_atom_content(*args) do |maker|
|
1803
|
-
yield maker
|
1804
|
-
target = chain_reader(maker, maker_readers)
|
1805
|
-
target.type = "text"
|
1806
|
-
target.content = "example content"
|
1807
|
-
end
|
1808
|
-
|
1809
|
-
_assert_maker_atom_content(*args) do |maker|
|
1810
|
-
yield maker
|
1811
|
-
target = chain_reader(maker, maker_readers)
|
1812
|
-
target.type = "html"
|
1813
|
-
target.content = "<em>text</em>"
|
1814
|
-
end
|
1815
|
-
end
|
1816
|
-
end
|
1817
|
-
|
1818
|
-
def assert_maker_atom_content_inline_xhtml(feed_type, maker_readers,
|
1819
|
-
feed_readers, not_set_error_name)
|
1820
|
-
_wrap_assertion do
|
1821
|
-
args = [feed_type, maker_readers, feed_readers]
|
1822
|
-
assert_not_set_error(not_set_error_name, %w(xml_content)) do
|
1823
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1824
|
-
yield maker
|
1825
|
-
target = chain_reader(maker, maker_readers)
|
1826
|
-
target.type = "xhtml"
|
1827
|
-
end
|
1828
|
-
end
|
1829
|
-
|
1830
|
-
assert_not_set_error(not_set_error_name, %w(xml_content)) do
|
1831
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1832
|
-
yield maker
|
1833
|
-
target = chain_reader(maker, maker_readers)
|
1834
|
-
target.type = "xhtml"
|
1835
|
-
target.content = "dummy"
|
1836
|
-
end
|
1837
|
-
end
|
1838
|
-
|
1839
|
-
_assert_maker_atom_content(*args) do |maker|
|
1840
|
-
yield maker
|
1841
|
-
target = chain_reader(maker, maker_readers)
|
1842
|
-
target.type = "xhtml"
|
1843
|
-
target.xml_content = "text"
|
1844
|
-
end
|
1845
|
-
|
1846
|
-
_assert_maker_atom_content(*args) do |maker|
|
1847
|
-
yield maker
|
1848
|
-
target = chain_reader(maker, maker_readers)
|
1849
|
-
target.type = "xhtml"
|
1850
|
-
target.xml = "text"
|
1851
|
-
end
|
1852
|
-
|
1853
|
-
_assert_maker_atom_content(*args) do |maker|
|
1854
|
-
yield maker
|
1855
|
-
target = chain_reader(maker, maker_readers)
|
1856
|
-
target.type = "xhtml"
|
1857
|
-
target.xml_content =
|
1858
|
-
RSS::XML::Element.new("em", nil, nil, {}, ["text"])
|
1859
|
-
end
|
1860
|
-
|
1861
|
-
_assert_maker_atom_content(*args) do |maker|
|
1862
|
-
yield maker
|
1863
|
-
target = chain_reader(maker, maker_readers)
|
1864
|
-
target.type = "xhtml"
|
1865
|
-
target.xml = RSS::XML::Element.new("em", nil, nil, {}, ["text"])
|
1866
|
-
end
|
1867
|
-
|
1868
|
-
|
1869
|
-
xhtml_uri = "http://www.w3.org/1999/xhtml"
|
1870
|
-
em = RSS::XML::Element.new("em", nil, nil, {}, ["text"])
|
1871
|
-
em_with_xhtml_uri =
|
1872
|
-
RSS::XML::Element.new("em", nil, xhtml_uri, {}, ["text"])
|
1873
|
-
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1874
|
-
yield maker
|
1875
|
-
target = chain_reader(maker, maker_readers)
|
1876
|
-
target.type = "xhtml"
|
1877
|
-
target.xml = em
|
1878
|
-
end
|
1879
|
-
assert_equal(RSS::XML::Element.new("div", nil, xhtml_uri,
|
1880
|
-
{"xmlns" => xhtml_uri},
|
1881
|
-
[em_with_xhtml_uri]),
|
1882
|
-
chain_reader(feed, feed_readers).xml)
|
1883
|
-
|
1884
|
-
div = RSS::XML::Element.new("div", nil, xhtml_uri,
|
1885
|
-
{"xmlns" => xhtml_uri,
|
1886
|
-
"class" => "sample"},
|
1887
|
-
["text"])
|
1888
|
-
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1889
|
-
yield maker
|
1890
|
-
target = chain_reader(maker, maker_readers)
|
1891
|
-
target.type = "xhtml"
|
1892
|
-
target.xml = div
|
1893
|
-
end
|
1894
|
-
assert_equal(div, chain_reader(feed, feed_readers).xml)
|
1895
|
-
end
|
1896
|
-
end
|
1897
|
-
|
1898
|
-
def assert_maker_atom_content_inline_other(*args, &block)
|
1899
|
-
_wrap_assertion do
|
1900
|
-
assert_maker_atom_content_inline_other_xml(*args, &block)
|
1901
|
-
assert_maker_atom_content_inline_other_text(*args, &block)
|
1902
|
-
assert_maker_atom_content_inline_other_base64(*args, &block)
|
1903
|
-
end
|
1904
|
-
end
|
1905
|
-
|
1906
|
-
def assert_maker_atom_content_inline_other_xml(feed_type, maker_readers,
|
1907
|
-
feed_readers,
|
1908
|
-
not_set_error_name)
|
1909
|
-
_wrap_assertion do
|
1910
|
-
args = [feed_type, maker_readers, feed_readers]
|
1911
|
-
assert_not_set_error(not_set_error_name, %w(xml_content)) do
|
1912
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1913
|
-
yield maker
|
1914
|
-
target = chain_reader(maker, maker_readers)
|
1915
|
-
target.type = "application/xml"
|
1916
|
-
end
|
1917
|
-
end
|
1918
|
-
|
1919
|
-
assert_not_set_error(not_set_error_name, %w(xml_content)) do
|
1920
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1921
|
-
yield maker
|
1922
|
-
target = chain_reader(maker, maker_readers)
|
1923
|
-
target.type = "svg/image+xml"
|
1924
|
-
end
|
1925
|
-
end
|
1926
|
-
|
1927
|
-
svg_uri = "http://www.w3.org/2000/svg"
|
1928
|
-
rect = RSS::XML::Element.new("rect", nil, svg_uri,
|
1929
|
-
{"x" => "0.5cm",
|
1930
|
-
"y" => "0.5cm",
|
1931
|
-
"width" => "2cm",
|
1932
|
-
"height" => "1cm"})
|
1933
|
-
svg = RSS::XML::Element.new("svg", nil, svg_uri,
|
1934
|
-
{"xmlns" => svg_uri,
|
1935
|
-
"version" => "1.1",
|
1936
|
-
"width" => "5cm",
|
1937
|
-
"height" => "4cm"},
|
1938
|
-
[rect])
|
1939
|
-
_assert_maker_atom_content(*args) do |maker|
|
1940
|
-
yield maker
|
1941
|
-
target = chain_reader(maker, maker_readers)
|
1942
|
-
target.type = "image/svg+xml"
|
1943
|
-
target.xml = svg
|
1944
|
-
end
|
1945
|
-
|
1946
|
-
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1947
|
-
yield maker
|
1948
|
-
target = chain_reader(maker, maker_readers)
|
1949
|
-
target.type = "image/svg+xml"
|
1950
|
-
target.xml = svg
|
1951
|
-
end
|
1952
|
-
assert_equal(svg, chain_reader(feed, feed_readers).xml)
|
1953
|
-
end
|
1954
|
-
end
|
1955
|
-
|
1956
|
-
def assert_maker_atom_content_inline_other_text(feed_type, maker_readers,
|
1957
|
-
feed_readers,
|
1958
|
-
not_set_error_name)
|
1959
|
-
_wrap_assertion do
|
1960
|
-
args = [feed_type, maker_readers, feed_readers]
|
1961
|
-
assert_not_set_error(not_set_error_name, %w(content)) do
|
1962
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
1963
|
-
yield maker
|
1964
|
-
target = chain_reader(maker, maker_readers)
|
1965
|
-
target.type = "text/plain"
|
1966
|
-
end
|
1967
|
-
end
|
1968
|
-
|
1969
|
-
_assert_maker_atom_content(*args) do |maker|
|
1970
|
-
yield maker
|
1971
|
-
target = chain_reader(maker, maker_readers)
|
1972
|
-
target.type = "text/plain"
|
1973
|
-
target.content = "text"
|
1974
|
-
end
|
1975
|
-
end
|
1976
|
-
end
|
1977
|
-
|
1978
|
-
def assert_maker_atom_content_inline_other_base64(feed_type, maker_readers,
|
1979
|
-
feed_readers,
|
1980
|
-
not_set_error_name)
|
1981
|
-
_wrap_assertion do
|
1982
|
-
args = [feed_type, maker_readers, feed_readers]
|
1983
|
-
content = "\211PNG\r\n\032\n"
|
1984
|
-
_assert_maker_atom_content(*args) do |maker|
|
1985
|
-
yield maker
|
1986
|
-
target = chain_reader(maker, maker_readers)
|
1987
|
-
target.type = "image/png"
|
1988
|
-
target.content = content
|
1989
|
-
end
|
1990
|
-
|
1991
|
-
_assert_maker_atom_content(*args) do |maker|
|
1992
|
-
yield maker
|
1993
|
-
target = chain_reader(maker, maker_readers)
|
1994
|
-
target.type = "image/png"
|
1995
|
-
target.src = "http://example.com/logo.png"
|
1996
|
-
target.content = content
|
1997
|
-
end
|
1998
|
-
|
1999
|
-
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
|
2000
|
-
yield maker
|
2001
|
-
target = chain_reader(maker, maker_readers)
|
2002
|
-
target.type = "image/png"
|
2003
|
-
target.src = "http://example.com/logo.png"
|
2004
|
-
target.content = content
|
2005
|
-
end
|
2006
|
-
target = chain_reader(feed, feed_readers)
|
2007
|
-
assert_nil(target.src)
|
2008
|
-
assert_equal(content, target.content)
|
2009
|
-
end
|
2010
|
-
end
|
2011
|
-
|
2012
|
-
def assert_maker_atom_content_out_of_line(feed_type, maker_readers,
|
2013
|
-
feed_readers, not_set_error_name)
|
2014
|
-
_wrap_assertion do
|
2015
|
-
args = [feed_type, maker_readers, feed_readers]
|
2016
|
-
assert_not_set_error(not_set_error_name, %w(content)) do
|
2017
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
2018
|
-
yield maker
|
2019
|
-
target = chain_reader(maker, maker_readers)
|
2020
|
-
target.type = "image/png"
|
2021
|
-
end
|
2022
|
-
end
|
2023
|
-
|
2024
|
-
assert_not_set_error(not_set_error_name, %w(type)) do
|
2025
|
-
RSS::Maker.make("atom:#{feed_type}") do |maker|
|
2026
|
-
yield maker
|
2027
|
-
target = chain_reader(maker, maker_readers)
|
2028
|
-
target.src = "http://example.com/logo.png"
|
2029
|
-
end
|
2030
|
-
end
|
2031
|
-
|
2032
|
-
_assert_maker_atom_content(*args) do |maker|
|
2033
|
-
yield maker
|
2034
|
-
target = chain_reader(maker, maker_readers)
|
2035
|
-
target.type = "image/png"
|
2036
|
-
target.src = "http://example.com/logo.png"
|
2037
|
-
end
|
2038
|
-
|
2039
|
-
_assert_maker_atom_content(*args) do |maker|
|
2040
|
-
yield maker
|
2041
|
-
target = chain_reader(maker, maker_readers)
|
2042
|
-
target.type = "image/png"
|
2043
|
-
target.content = "\211PNG\r\n\032\n"
|
2044
|
-
end
|
2045
|
-
|
2046
|
-
_assert_maker_atom_content(*args) do |maker|
|
2047
|
-
yield maker
|
2048
|
-
target = chain_reader(maker, maker_readers)
|
2049
|
-
target.type = "application/xml"
|
2050
|
-
target.src = "http://example.com/sample.xml"
|
2051
|
-
end
|
2052
|
-
|
2053
|
-
|
2054
|
-
_assert_maker_atom_content(*args) do |maker|
|
2055
|
-
yield maker
|
2056
|
-
target = chain_reader(maker, maker_readers)
|
2057
|
-
target.type = "text/plain"
|
2058
|
-
target.src = "http://example.com/README.txt"
|
2059
|
-
end
|
2060
|
-
end
|
2061
|
-
end
|
2062
|
-
|
2063
|
-
def assert_slash_elements(expected, target)
|
2064
|
-
assert_equal(expected,
|
2065
|
-
{
|
2066
|
-
"section" => target.slash_section,
|
2067
|
-
"department" => target.slash_department,
|
2068
|
-
"comments" => target.slash_comments,
|
2069
|
-
"hit_parades" => target.slash_hit_parades,
|
2070
|
-
})
|
2071
|
-
assert_equal(expected["hit_parades"].join(","),
|
2072
|
-
target.slash_hit_parade)
|
2073
|
-
end
|
2074
|
-
|
2075
|
-
def chain_reader(target, readers, &block)
|
2076
|
-
readers.inject(target) do |result, reader|
|
2077
|
-
return nil if result.nil?
|
2078
|
-
result.__send__(reader, &block)
|
2079
|
-
end
|
2080
|
-
end
|
2081
|
-
|
2082
|
-
def normalized_attrs(attrs)
|
2083
|
-
n_attrs = {}
|
2084
|
-
attrs.each do |name, value|
|
2085
|
-
n_attrs[name.to_s] = value
|
2086
|
-
end
|
2087
|
-
n_attrs
|
2088
|
-
end
|
2089
|
-
|
2090
|
-
def combination(elements, n)
|
2091
|
-
if n <= 0 or elements.size < n
|
2092
|
-
[]
|
2093
|
-
elsif n == 1
|
2094
|
-
elements.collect {|element| [element]}
|
2095
|
-
else
|
2096
|
-
first, *rest = elements
|
2097
|
-
combination(rest, n - 1).collect do |sub_elements|
|
2098
|
-
[first, *sub_elements]
|
2099
|
-
end + combination(rest, n)
|
2100
|
-
end
|
2101
|
-
end
|
2102
|
-
|
2103
|
-
def tag(name, content=nil, attributes={})
|
2104
|
-
attributes = attributes.collect do |key, value|
|
2105
|
-
"#{ERB::Util.h(key)}=\"#{ERB::Util.h(value)}\""
|
2106
|
-
end.join(" ")
|
2107
|
-
begin_tag = "<#{name}"
|
2108
|
-
begin_tag << " #{attributes}" unless attributes.empty?
|
2109
|
-
if content
|
2110
|
-
"#{begin_tag}>#{content}</#{name}>\n"
|
2111
|
-
else
|
2112
|
-
"#{begin_tag}/>\n"
|
2113
|
-
end
|
2114
|
-
end
|
2115
|
-
end
|
2116
|
-
end
|