~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to test/rss/rss-assertions.rb

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'erb'
 
2
 
1
3
module RSS
2
4
  module Assertions
3
5
    def assert_parse(rss, assert_method, *args)
90
92
          flunk("Not raise NotSetError")
91
93
        rescue ::RSS::NotSetError => e
92
94
          assert_equal(name, e.name)
 
95
          assert_kind_of(Array, variables)
93
96
          assert_equal(variables.sort, e.variables.sort)
94
97
        end
95
98
      end
152
155
      end
153
156
    end
154
157
 
155
 
    
156
 
    def assert_channel10(attrs, channel)
157
 
      _wrap_assertion do
158
 
        n_attrs = normalized_attrs(attrs)
159
 
        
160
 
        names = %w(about title link description)
161
 
        assert_attributes(attrs, names, channel)
162
 
 
163
 
        %w(image items textinput).each do |name|
164
 
          value = n_attrs[name]
165
 
          if value
166
 
            target = channel.__send__(name)
167
 
            __send__("assert_channel10_#{name}", value, target)
168
 
          end
169
 
        end
170
 
      end
171
 
    end
172
 
 
173
 
    def assert_channel10_image(attrs, image)
174
 
      _wrap_assertion do
175
 
        assert_attributes(attrs, %w(resource), image)
176
 
      end
177
 
    end
178
 
    
179
 
    def assert_channel10_textinput(attrs, textinput)
180
 
      _wrap_assertion do
181
 
        assert_attributes(attrs, %w(resource), textinput)
182
 
      end
183
 
    end
184
 
 
185
 
    def assert_channel10_items(attrs, items)
186
 
      _wrap_assertion do
187
 
        assert_equal(items.resources, items.Seq.lis.collect {|x| x.resource})
188
 
        items.Seq.lis.each_with_index do |li, i|
189
 
          assert_attributes(attrs[i], %w(resource), li)
190
 
        end
191
 
      end
192
 
    end
193
 
 
194
 
    def assert_image10(attrs, image)
195
 
      _wrap_assertion do
196
 
        names = %w(about title url link)
197
 
        assert_attributes(attrs, names, image)
198
 
      end
199
 
    end
200
 
 
201
 
    def assert_items10(attrs, items)
202
 
      _wrap_assertion do
203
 
        names = %w(about title link description)
204
 
        items.each_with_index do |item, i|
205
 
          assert_attributes(attrs[i], names, item)
206
 
        end
207
 
      end
208
 
    end
209
 
 
210
 
    def assert_textinput10(attrs, textinput)
211
 
      _wrap_assertion do
212
 
        names = %w(about title description name link)
213
 
        assert_attributes(attrs, names, textinput)
214
 
      end
215
 
    end
216
 
 
217
 
 
218
 
    def assert_channel09(attrs, channel)
219
 
      _wrap_assertion do
220
 
        n_attrs = normalized_attrs(attrs)
221
 
 
222
 
        names = %w(title description link language rating
223
 
                   copyright pubDate lastBuildDate docs
224
 
                   managingEditor webMaster)
225
 
        assert_attributes(attrs, names, channel)
226
 
        
227
 
        %w(skipHours skipDays).each do |name|
228
 
          value = n_attrs[name]
229
 
          if value
230
 
            target = channel.__send__(name)
231
 
            __send__("assert_channel09_#{name}", value, target)
232
 
          end
233
 
        end
234
 
      end
235
 
    end
236
 
 
237
 
    def assert_channel09_skipDays(contents, skipDays)
238
 
      _wrap_assertion do
239
 
        days = skipDays.days
240
 
        contents.each_with_index do |content, i|
241
 
          assert_equal(content, days[i].content)
242
 
        end
243
 
      end
244
 
    end
245
 
    
246
 
    def assert_channel09_skipHours(contents, skipHours)
247
 
      _wrap_assertion do
248
 
        hours = skipHours.hours
249
 
        contents.each_with_index do |content, i|
250
 
          assert_equal(content.to_i, hours[i].content)
251
 
        end
252
 
      end
253
 
    end
254
 
    
255
 
    def assert_image09(attrs, image)
256
 
      _wrap_assertion do
257
 
        names = %w(url link title description)
258
 
        names << ["width", :integer]
259
 
        names << ["height", :integer]
260
 
        assert_attributes(attrs, names, image)
261
 
      end
262
 
    end
263
 
 
264
 
    def assert_items09(attrs, items)
265
 
      _wrap_assertion do
266
 
        names = %w(title link description)
267
 
        items.each_with_index do |item, i|
268
 
          assert_attributes(attrs[i], names, item)
269
 
        end
270
 
      end
271
 
    end
272
 
    
273
 
    def assert_textinput09(attrs, textinput)
274
 
      _wrap_assertion do
275
 
        names = %w(title description name link)
276
 
        assert_attributes(attrs, names, textinput)
277
 
      end
278
 
    end
279
 
 
280
 
 
281
 
    def assert_channel20(attrs, channel)
282
 
      _wrap_assertion do
283
 
        n_attrs = normalized_attrs(attrs)
284
 
        
285
 
        names = %w(title link description language copyright
286
 
                   managingEditor webMaster pubDate
287
 
                   lastBuildDate generator docs rating)
288
 
        names << ["ttl", :integer]
289
 
        assert_attributes(attrs, names, channel)
290
 
 
291
 
        %w(cloud categories skipHours skipDays).each do |name|
292
 
          value = n_attrs[name]
293
 
          if value
294
 
            target = channel.__send__(name)
295
 
            __send__("assert_channel20_#{name}", value, target)
296
 
          end
297
 
        end
298
 
      end
299
 
    end
300
 
 
301
 
    def assert_channel20_skipDays(contents, skipDays)
302
 
      assert_channel09_skipDays(contents, skipDays)
303
 
    end
304
 
    
305
 
    def assert_channel20_skipHours(contents, skipHours)
306
 
      assert_channel09_skipHours(contents, skipHours)
307
 
    end
308
 
    
309
 
    def assert_channel20_cloud(attrs, cloud)
310
 
      _wrap_assertion do
311
 
        names = %w(domain path registerProcedure protocol)
312
 
        names << ["port", :integer]
313
 
        assert_attributes(attrs, names, cloud)
314
 
      end
315
 
    end
316
 
    
317
 
    def assert_channel20_categories(attrs, categories)
318
 
      _wrap_assertion do
319
 
        names = %w(domain content)
320
 
        categories.each_with_index do |category, i|
321
 
          assert_attributes(attrs[i], names, category)
322
 
        end
323
 
      end
324
 
    end
325
 
    
326
 
    def assert_image20(attrs, image)
327
 
      _wrap_assertion do
328
 
        names = %w(url link title description)
329
 
        names << ["width", :integer]
330
 
        names << ["height", :integer]
331
 
        assert_attributes(attrs, names, image)
332
 
      end
333
 
    end
334
 
 
335
 
    def assert_items20(attrs, items)
336
 
      _wrap_assertion do
337
 
        names = %w(about title link description)
338
 
        items.each_with_index do |item, i|
339
 
          assert_attributes(attrs[i], names, item)
340
 
 
341
 
          n_attrs = normalized_attrs(attrs[i])
342
 
 
343
 
          %w(source enclosure categories guid).each do |name|
344
 
            value = n_attrs[name]
345
 
            if value
346
 
              target = item.__send__(name)
347
 
              __send__("assert_items20_#{name}", value, target)
348
 
            end
349
 
          end
350
 
        end
351
 
      end
352
 
    end
353
 
 
354
 
    def assert_items20_source(attrs, source)
355
 
      _wrap_assertion do
356
 
        assert_attributes(attrs, %w(url content), source)
357
 
      end
358
 
    end
359
 
    
360
 
    def assert_items20_enclosure(attrs, enclosure)
361
 
      _wrap_assertion do
362
 
        names = ["url", ["length", :integer], "type"]
363
 
        assert_attributes(attrs, names, enclosure)
364
 
      end
365
 
    end
366
 
    
367
 
    def assert_items20_categories(attrs, categories)
368
 
      _wrap_assertion do
369
 
        assert_channel20_categories(attrs, categories)
370
 
      end
371
 
    end
372
 
    
373
 
    def assert_items20_guid(attrs, guid)
374
 
      _wrap_assertion do
375
 
        names = [["isPermaLink", :boolean], ["content"]]
376
 
        assert_attributes(attrs, names, guid)
377
 
      end
378
 
    end
379
 
 
380
 
    def assert_textinput20(attrs, textinput)
381
 
      _wrap_assertion do
382
 
        names = %w(title description name link)
383
 
        assert_attributes(attrs, names, textinput)
384
 
      end
385
 
    end
386
158
 
387
159
    def assert_atom_person(tag_name, generator)
388
160
      _wrap_assertion do
1146
918
      end
1147
919
    end
1148
920
 
1149
 
 
1150
 
    def assert_atom_person_to_s(target_class)
1151
 
      _wrap_assertion do
1152
 
        name = "A person"
1153
 
        uri = "http://example.com/person/"
1154
 
        email = "person@example.com"
1155
 
 
1156
 
        target = target_class.new
1157
 
        assert_equal("", target.to_s)
1158
 
 
1159
 
        target = target_class.new
1160
 
        person_name = target_class::Name.new
1161
 
        person_name.content = name
1162
 
        target.name = person_name
1163
 
        xml_target = REXML::Document.new(target.to_s).root
1164
 
        assert_equal(["name"], xml_target.elements.collect {|e| e.name})
1165
 
        assert_equal([name], xml_target.elements.collect {|e| e.text})
1166
 
 
1167
 
        person_uri = target_class::Uri.new
1168
 
        person_uri.content = uri
1169
 
        target.uri = person_uri
1170
 
        xml_target = REXML::Document.new(target.to_s).root
1171
 
        assert_equal(["name", "uri"], xml_target.elements.collect {|e| e.name})
1172
 
        assert_equal([name, uri], xml_target.elements.collect {|e| e.text})
1173
 
 
1174
 
        person_email = target_class::Email.new
1175
 
        person_email.content = email
1176
 
        target.email = person_email
1177
 
        xml_target = REXML::Document.new(target.to_s).root
1178
 
        assert_equal(["name", "uri", "email"],
1179
 
                     xml_target.elements.collect {|e| e.name})
1180
 
        assert_equal([name, uri, email],
1181
 
                     xml_target.elements.collect {|e| e.text})
1182
 
      end
1183
 
    end
1184
 
 
1185
 
    def assert_atom_category_to_s(target_class)
1186
 
      _wrap_assertion do
1187
 
        term = "music"
1188
 
        scheme = "http://example.com/music"
1189
 
        label = "Music"
1190
 
 
1191
 
        category = target_class.new
1192
 
        assert_equal("", category.to_s)
1193
 
 
1194
 
        category = target_class.new
1195
 
        category.scheme = scheme
1196
 
        assert_equal("", category.to_s)
1197
 
 
1198
 
        category = target_class.new
1199
 
        category.label = label
1200
 
        assert_equal("", category.to_s)
1201
 
 
1202
 
        category = target_class.new
1203
 
        category.scheme = scheme
1204
 
        category.label = label
1205
 
        assert_equal("", category.to_s)
1206
 
 
1207
 
        category = target_class.new
1208
 
        category.term = term
1209
 
        xml = REXML::Document.new(category.to_s).root
1210
 
        assert_rexml_element([], {"term" => term}, nil, xml)
1211
 
 
1212
 
        category = target_class.new
1213
 
        category.term = term
1214
 
        category.scheme = scheme
1215
 
        xml = REXML::Document.new(category.to_s).root
1216
 
        assert_rexml_element([], {"term" => term, "scheme" => scheme}, nil, xml)
1217
 
 
1218
 
        category = target_class.new
1219
 
        category.term = term
1220
 
        category.label = label
1221
 
        xml = REXML::Document.new(category.to_s).root
1222
 
        assert_rexml_element([], {"term" => term, "label" => label}, nil, xml)
1223
 
 
1224
 
        category = target_class.new
1225
 
        category.term = term
1226
 
        category.scheme = scheme
1227
 
        category.label = label
1228
 
        xml = REXML::Document.new(category.to_s).root
1229
 
        attrs = {"term" => term, "scheme" => scheme, "label" => label}
1230
 
        assert_rexml_element([], attrs, nil, xml)
1231
 
      end
1232
 
    end
1233
 
 
1234
 
    def assert_atom_generator_to_s(target_class)
1235
 
      _wrap_assertion do
1236
 
        content = "Feed generator"
1237
 
        uri = "http://example.com/generator"
1238
 
        version = "0.0.1"
1239
 
 
1240
 
        generator = target_class.new
1241
 
        assert_equal("", generator.to_s)
1242
 
 
1243
 
        generator = target_class.new
1244
 
        generator.uri = uri
1245
 
        assert_equal("", generator.to_s)
1246
 
 
1247
 
        generator = target_class.new
1248
 
        generator.version = version
1249
 
        assert_equal("", generator.to_s)
1250
 
 
1251
 
        generator = target_class.new
1252
 
        generator.uri = uri
1253
 
        generator.version = version
1254
 
        assert_equal("", generator.to_s)
1255
 
 
1256
 
        generator = target_class.new
1257
 
        generator.content = content
1258
 
        xml = REXML::Document.new(generator.to_s).root
1259
 
        assert_rexml_element([], {}, content, xml)
1260
 
 
1261
 
        generator = target_class.new
1262
 
        generator.content = content
1263
 
        generator.uri = uri
1264
 
        xml = REXML::Document.new(generator.to_s).root
1265
 
        assert_rexml_element([], {"uri" => uri}, content, xml)
1266
 
 
1267
 
        generator = target_class.new
1268
 
        generator.content = content
1269
 
        generator.version = version
1270
 
        xml = REXML::Document.new(generator.to_s).root
1271
 
        assert_rexml_element([], {"version" => version}, content, xml)
1272
 
 
1273
 
        generator = target_class.new
1274
 
        generator.content = content
1275
 
        generator.uri = uri
1276
 
        generator.version = version
1277
 
        xml = REXML::Document.new(generator.to_s).root
1278
 
        assert_rexml_element([], {"uri" => uri, "version" => version},
1279
 
                             content, xml)
1280
 
      end
1281
 
    end
1282
 
 
1283
 
    def assert_atom_icon_to_s(target_class)
1284
 
      _wrap_assertion do
1285
 
        content = "http://example.com/icon.png"
1286
 
 
1287
 
        icon = target_class.new
1288
 
        assert_equal("", icon.to_s)
1289
 
 
1290
 
        icon = target_class.new
1291
 
        icon.content = content
1292
 
        xml = REXML::Document.new(icon.to_s).root
1293
 
        assert_rexml_element([], {}, content, xml)
1294
 
      end
1295
 
    end
1296
 
 
1297
 
    def assert_atom_id_to_s(target_class)
1298
 
      _wrap_assertion do
1299
 
        content = "http://example.com/1"
1300
 
 
1301
 
        id = target_class.new
1302
 
        assert_equal("", id.to_s)
1303
 
 
1304
 
        id = target_class.new
1305
 
        id.content = content
1306
 
        xml = REXML::Document.new(id.to_s).root
1307
 
        assert_rexml_element([], {}, content, xml)
1308
 
      end
1309
 
    end
1310
 
 
1311
 
    def assert_atom_link_to_s(target_class)
1312
 
      _wrap_assertion do
1313
 
        href = "http://example.com/atom.xml"
1314
 
        rel = "self"
1315
 
        type = "application/atom+xml"
1316
 
        hreflang = "ja"
1317
 
        title = "Atom Feed"
1318
 
        length = "801"
1319
 
 
1320
 
        link = target_class.new
1321
 
        assert_equal("", link.to_s)
1322
 
 
1323
 
        link = target_class.new
1324
 
        link.href = href
1325
 
        xml = REXML::Document.new(link.to_s).root
1326
 
        assert_rexml_element([], {"href" => href}, nil, xml)
1327
 
 
1328
 
        optional_arguments = %w(rel type hreflang title length)
1329
 
        optional_arguments.each do |name|
1330
 
          rest = optional_arguments.reject {|x| x == name}
1331
 
 
1332
 
          link = target_class.new
1333
 
          link.__send__("#{name}=", eval(name))
1334
 
          assert_equal("", link.to_s)
1335
 
 
1336
 
          rest.each do |n|
1337
 
            link.__send__("#{n}=", eval(n))
1338
 
            assert_equal("", link.to_s)
1339
 
          end
1340
 
 
1341
 
          link = target_class.new
1342
 
          link.href = href
1343
 
          link.__send__("#{name}=", eval(name))
1344
 
          attrs = [["href", href], [name, eval(name)]]
1345
 
          xml = REXML::Document.new(link.to_s).root
1346
 
          assert_rexml_element([], attrs, nil, xml)
1347
 
 
1348
 
          rest.each do |n|
1349
 
            link.__send__("#{n}=", eval(n))
1350
 
            attrs << [n, eval(n)]
1351
 
            xml = REXML::Document.new(link.to_s).root
1352
 
            assert_rexml_element([], attrs, nil, xml)
1353
 
          end
1354
 
        end
1355
 
      end
1356
 
    end
1357
 
 
1358
 
    def assert_atom_logo_to_s(target_class)
1359
 
      _wrap_assertion do
1360
 
        content = "http://example.com/logo.png"
1361
 
 
1362
 
        logo = target_class.new
1363
 
        assert_equal("", logo.to_s)
1364
 
 
1365
 
        logo = target_class.new
1366
 
        logo.content = content
1367
 
        xml = REXML::Document.new(logo.to_s).root
1368
 
        assert_rexml_element([], {}, content, xml)
1369
 
      end
1370
 
    end
1371
 
 
1372
 
    def assert_atom_text_construct_to_s(target_class)
1373
 
      _wrap_assertion do
1374
 
        text_content = "plain text"
1375
 
        html_content = "<em>#{text_content}</em>"
1376
 
        xhtml_uri = "http://www.w3.org/1999/xhtml"
1377
 
        xhtml_em = RSS::XML::Element.new("em", nil, xhtml_uri, {}, text_content)
1378
 
        xhtml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
1379
 
                                              {"xmlns" => xhtml_uri},
1380
 
                                              [xhtml_em])
1381
 
 
1382
 
        text = target_class.new
1383
 
        assert_equal("", text.to_s)
1384
 
 
1385
 
        text = target_class.new
1386
 
        text.type = "text"
1387
 
        assert_equal("", text.to_s)
1388
 
 
1389
 
        text = target_class.new
1390
 
        text.content = text_content
1391
 
        xml = REXML::Document.new(text.to_s).root
1392
 
        assert_rexml_element([], {}, text_content, xml)
1393
 
 
1394
 
        text = target_class.new
1395
 
        text.type = "text"
1396
 
        text.content = text_content
1397
 
        xml = REXML::Document.new(text.to_s).root
1398
 
        assert_rexml_element([], {"type" => "text"}, text_content, xml)
1399
 
 
1400
 
        text = target_class.new
1401
 
        text.type = "html"
1402
 
        text.content = html_content
1403
 
        xml = REXML::Document.new(text.to_s).root
1404
 
        assert_rexml_element([], {"type" => "html"}, html_content, xml)
1405
 
 
1406
 
        text = target_class.new
1407
 
        text.type = "xhtml"
1408
 
        text.content = xhtml_content
1409
 
        assert_equal("", text.to_s)
1410
 
 
1411
 
        text = target_class.new
1412
 
        text.type = "xhtml"
1413
 
        text.__send__(target_class.xml_setter, xhtml_content)
1414
 
        xml = REXML::Document.new(text.to_s).root
1415
 
        assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
1416
 
                             nil, xml)
1417
 
        assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
1418
 
        assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
1419
 
 
1420
 
        text = target_class.new
1421
 
        text.type = "xhtml"
1422
 
        text.__send__(target_class.xml_setter, xhtml_em)
1423
 
        xml = REXML::Document.new(text.to_s).root
1424
 
        assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
1425
 
                             nil, xml)
1426
 
        assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
1427
 
        assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
1428
 
      end
1429
 
    end
1430
 
 
1431
 
    def assert_atom_date_construct_to_s(target_class)
1432
 
      _wrap_assertion do
1433
 
        date = target_class.new
1434
 
        assert_equal("", date.to_s)
1435
 
 
1436
 
        [
1437
 
         "2003-12-13T18:30:02Z",
1438
 
         "2003-12-13T18:30:02.25Z",
1439
 
         "2003-12-13T18:30:02+01:00",
1440
 
         "2003-12-13T18:30:02.25+01:00",
1441
 
        ].each do |content|
1442
 
          date = target_class.new
1443
 
          date.content = content
1444
 
          xml = REXML::Document.new(date.to_s).root
1445
 
          assert_rexml_element([], {}, content, xml, :time)
1446
 
 
1447
 
          date = target_class.new
1448
 
          date.content = Time.parse(content)
1449
 
          xml = REXML::Document.new(date.to_s).root
1450
 
          assert_rexml_element([], {}, content, xml, :time)
1451
 
        end
1452
 
      end
1453
 
    end
1454
 
 
1455
 
    def assert_atom_content_to_s(target_class)
1456
 
      _wrap_assertion do
1457
 
        assert_atom_text_construct_to_s(target_class)
1458
 
        assert_atom_content_inline_other_xml_to_s(target_class)
1459
 
        assert_atom_content_inline_other_text_to_s(target_class)
1460
 
        assert_atom_content_inline_other_base64_to_s(target_class)
1461
 
        assert_atom_content_out_of_line_to_s(target_class)
1462
 
      end
1463
 
    end
1464
 
 
1465
 
    def assert_atom_content_inline_other_xml_to_s(target_class)
1466
 
      _wrap_assertion do
1467
 
        content = target_class.new
1468
 
        content.type = "text/xml"
1469
 
        assert_equal("", content.to_s)
1470
 
 
1471
 
        content = target_class.new
1472
 
        content.type = "text/xml"
1473
 
        content.xml = RSS::XML::Element.new("em")
1474
 
        xml = REXML::Document.new(content.to_s).root
1475
 
        assert_rexml_element([["", "em"]], {"type" => "text/xml"}, nil, xml)
1476
 
      end
1477
 
    end
1478
 
 
1479
 
    def assert_atom_content_inline_other_text_to_s(target_class)
1480
 
      _wrap_assertion do
1481
 
        content = target_class.new
1482
 
        content.type = "text/plain"
1483
 
        assert_equal("", content.to_s)
1484
 
 
1485
 
        content = target_class.new
1486
 
        content.type = "text/plain"
1487
 
        content.xml = RSS::XML::Element.new("em")
1488
 
        assert_equal("", content.to_s)
1489
 
 
1490
 
        content = target_class.new
1491
 
        content.type = "text/plain"
1492
 
        content.content = "content"
1493
 
        xml = REXML::Document.new(content.to_s).root
1494
 
        assert_rexml_element([], {"type" => "text/plain"}, "content", xml)
1495
 
      end
1496
 
    end
1497
 
 
1498
 
    def assert_atom_content_inline_other_base64_to_s(target_class)
1499
 
      _wrap_assertion do
1500
 
        require "zlib"
1501
 
 
1502
 
        text = ""
1503
 
        char = "a"
1504
 
        100.times do |i|
1505
 
          text << char
1506
 
          char.succ!
1507
 
        end
1508
 
 
1509
 
        type = "application/zip"
1510
 
        original_content = Zlib::Deflate.deflate(text)
1511
 
 
1512
 
        content = target_class.new
1513
 
        content.type = type
1514
 
        content.content = original_content
1515
 
        xml = REXML::Document.new(content.to_s).root
1516
 
        assert_rexml_element([], {"type" => type},
1517
 
                             Base64.encode64(original_content), xml)
1518
 
      end
1519
 
    end
1520
 
 
1521
 
    def assert_atom_content_out_of_line_to_s(target_class)
1522
 
      _wrap_assertion do
1523
 
        type = "application/zip"
1524
 
        src = "http://example.com/xxx.zip"
1525
 
 
1526
 
        content = target_class.new
1527
 
        assert(!content.out_of_line?)
1528
 
        content.src = src
1529
 
        assert(content.out_of_line?)
1530
 
        xml = REXML::Document.new(content.to_s).root
1531
 
        assert_rexml_element([], {"src" => src}, nil, xml)
1532
 
 
1533
 
        content = target_class.new
1534
 
        assert(!content.out_of_line?)
1535
 
        content.type = type
1536
 
        assert(!content.out_of_line?)
1537
 
        content.src = src
1538
 
        assert(content.out_of_line?)
1539
 
        xml = REXML::Document.new(content.to_s).root
1540
 
        assert_rexml_element([], {"type" => type, "src" => src}, nil, xml)
1541
 
      end
1542
 
    end
1543
 
 
1544
921
    def _assert_maker_atom_persons(feed_type, maker_readers, feed_readers)
1545
922
      _wrap_assertion do
1546
923
        persons = []
1565
942
            :email => person.email ? person.email.content : nil,
1566
943
          }
1567
944
        end
1568
 
        p [feed_readers, feed.source.authors] unless persons == actual_persons
1569
945
        assert_equal(persons, actual_persons)
1570
946
      end
1571
947
    end
1765
1141
        assert_not_set_error(not_set_error_name, %w(content)) do
1766
1142
          _assert_maker_atom_text_construct(*args) do |maker|
1767
1143
            yield maker
1768
 
            target = chain_reader(maker, maker_readers)
 
1144
            target = chain_reader(maker, maker_readers) {|x| x}
1769
1145
            target.type = "text"
1770
1146
          end
1771
1147
        end
1773
1149
        assert_not_set_error(not_set_error_name, %w(content)) do
1774
1150
          _assert_maker_atom_text_construct(*args) do |maker|
1775
1151
            yield maker
1776
 
            target = chain_reader(maker, maker_readers)
 
1152
            target = chain_reader(maker, maker_readers) {|x| x}
1777
1153
            target.type = "html"
1778
1154
          end
1779
1155
        end
1781
1157
        assert_not_set_error(not_set_error_name, %w(xml_content)) do
1782
1158
          _assert_maker_atom_text_construct(*args) do |maker|
1783
1159
            yield maker
1784
 
            target = chain_reader(maker, maker_readers)
 
1160
            target = chain_reader(maker, maker_readers) {|x| x}
1785
1161
            target.type = "xhtml"
1786
1162
          end
1787
1163
        end
1789
1165
        assert_not_set_error(not_set_error_name, %w(xml_content)) do
1790
1166
          _assert_maker_atom_text_construct(*args) do |maker|
1791
1167
            yield maker
1792
 
            target = chain_reader(maker, maker_readers)
 
1168
            target = chain_reader(maker, maker_readers) {|x| x}
1793
1169
            target.type = "xhtml"
1794
1170
            target.content = "Content"
1795
1171
          end
1797
1173
 
1798
1174
        _assert_maker_atom_text_construct(*args) do |maker|
1799
1175
          yield maker
1800
 
          target = chain_reader(maker, maker_readers)
 
1176
          target = chain_reader(maker, maker_readers) {|x| x}
1801
1177
          target.type = "text"
1802
1178
          target.content = "Content"
1803
1179
        end
1804
1180
 
1805
1181
        _assert_maker_atom_text_construct(*args) do |maker|
1806
1182
          yield maker
1807
 
          target = chain_reader(maker, maker_readers)
 
1183
          target = chain_reader(maker, maker_readers) {|x| x}
1808
1184
          target.type = "html"
1809
1185
          target.content = "<em>Content</em>"
1810
1186
        end
1811
1187
 
1812
1188
        _assert_maker_atom_text_construct(*args) do |maker|
1813
1189
          yield maker
1814
 
          target = chain_reader(maker, maker_readers)
 
1190
          target = chain_reader(maker, maker_readers) {|x| x}
1815
1191
          target.type = "xhtml"
1816
1192
          target.xml_content = "text only"
1817
1193
        end
1818
1194
 
1819
1195
        _assert_maker_atom_text_construct(*args) do |maker|
1820
1196
          yield maker
1821
 
          target = chain_reader(maker, maker_readers)
 
1197
          target = chain_reader(maker, maker_readers) {|x| x}
1822
1198
          target.type = "xhtml"
1823
1199
          target.xml_content = RSS::XML::Element.new("unknown")
1824
1200
        end
1877
1253
        element = nil
1878
1254
        feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
1879
1255
          yield maker
1880
 
          target = chain_reader(maker, maker_readers)
 
1256
          target = chain_reader(maker, maker_readers) {|x| x}
1881
1257
          element = maker_extractor.call(target)
1882
1258
        end
1883
1259
 
1942
1318
              __send__(assert_method_name, feed_type, maker_readers,
1943
1319
                       feed_readers, *additional_args) do |maker|
1944
1320
                yield maker
1945
 
                target = chain_reader(maker, maker_readers)
 
1321
                target = chain_reader(maker, maker_readers) {|x| x}
1946
1322
                setup_target.call(target, have)
1947
1323
              end
1948
1324
            end
1950
1326
            __send__(assert_method_name, feed_type, maker_readers, feed_readers,
1951
1327
                     *additional_args) do |maker|
1952
1328
              yield maker
1953
 
              target = chain_reader(maker, maker_readers)
 
1329
              target = chain_reader(maker, maker_readers) {|x| x}
1954
1330
              setup_target.call(target, have_required_variable_too)
1955
1331
            end
1956
1332
          end
2302
1678
          :src => target.src,
2303
1679
          :content => target.content,
2304
1680
          :xml => target.xml,
2305
 
          :inline_text => target.__send!(:inline_text?),
2306
 
          :inline_html => target.__send!(:inline_html?),
2307
 
          :inline_xhtml => target.__send!(:inline_xhtml?),
2308
 
          :inline_other => target.__send!(:inline_other?),
2309
 
          :inline_other_text => target.__send!(:inline_other_text?),
2310
 
          :inline_other_xml => target.__send!(:inline_other_xml?),
2311
 
          :inline_other_base64 => target.__send!(:inline_other_base64?),
2312
 
          :out_of_line => target.__send!(:out_of_line?),
 
1681
          :inline_text => target.inline_text?,
 
1682
          :inline_html => target.inline_html?,
 
1683
          :inline_xhtml => target.inline_xhtml?,
 
1684
          :inline_other => target.inline_other?,
 
1685
          :inline_other_text => target.inline_other_text?,
 
1686
          :inline_other_xml => target.inline_other_xml?,
 
1687
          :inline_other_base64 => target.inline_other_base64?,
 
1688
          :out_of_line => target.out_of_line?,
2313
1689
        }
2314
1690
        content[:src] = nil if content[:src] and content[:content]
2315
1691
        if content[:type] or content[:content]
2642
2018
      end
2643
2019
    end
2644
2020
 
2645
 
    def chain_reader(target, readers)
 
2021
    def chain_reader(target, readers, &block)
2646
2022
      readers.inject(target) do |result, reader|
2647
2023
        return nil if result.nil?
2648
 
        result.__send__(reader)
 
2024
        result.__send__(reader, &block)
2649
2025
      end
2650
2026
    end
2651
2027
 
2669
2045
        end + combination(rest, n)
2670
2046
      end
2671
2047
    end
 
2048
 
 
2049
    def tag(name, content=nil, attributes={})
 
2050
      attributes = attributes.collect do |key, value|
 
2051
        "#{ERB::Util.h(key)}=\"#{ERB::Util.h(value)}\""
 
2052
      end.join(" ")
 
2053
      begin_tag = "<#{name}"
 
2054
      begin_tag << " #{attributes}" unless attributes.empty?
 
2055
      if content
 
2056
        "#{begin_tag}>#{content}</#{name}>\n"
 
2057
      else
 
2058
        "#{begin_tag}/>\n"
 
2059
      end
 
2060
    end
2672
2061
  end
2673
2062
end