|
| 1 | +import 'dart:core'; |
| 2 | +import 'dart:io'; |
| 3 | + |
| 4 | +import 'package:test/test.dart'; |
| 5 | +import 'package:webfeed/domain/rss1_feed.dart'; |
| 6 | + |
| 7 | +void main() { |
| 8 | + test('parse basic RSS 1.0', () { |
| 9 | + final xmlString = File('test/xml/RSS1-basic.xml').readAsStringSync(); |
| 10 | + final feed = new Rss1Feed.parse(xmlString); |
| 11 | + |
| 12 | + expect(feed.title, 'XML.com'); |
| 13 | + expect(feed.link, 'http://xml.com/pub'); |
| 14 | + expect( |
| 15 | + feed.description, |
| 16 | + 'XML.com features a rich mix of information and services for the XML community.', |
| 17 | + ); |
| 18 | + expect(feed.image, 'http://xml.com/universal/images/xml_tiny.gif'); |
| 19 | + |
| 20 | + expect(feed.items.length, 2); |
| 21 | + |
| 22 | + final firstItem = feed.items.first; |
| 23 | + expect(firstItem.title, 'Processing Inclusions with XSLT'); |
| 24 | + expect(firstItem.link, 'http://xml.com/pub/2000/08/09/xslt/xslt.html'); |
| 25 | + expect(firstItem.description, |
| 26 | + 'Processing document inclusions with general XML tools can be problematic. This article proposes a way of preserving inclusion information through SAX-based processing.'); |
| 27 | + }); |
| 28 | + |
| 29 | + test('parse RSS1 with syndication module', () { |
| 30 | + final xmlString = |
| 31 | + File('test/xml/RSS1-with-syndication-module.xml').readAsStringSync(); |
| 32 | + final feed = new Rss1Feed.parse(xmlString); |
| 33 | + |
| 34 | + expect(feed.title, 'Meerkat'); |
| 35 | + expect(feed.link, 'http://meerkat.oreillynet.com'); |
| 36 | + expect(feed.description, 'Meerkat: An Open Wire Service'); |
| 37 | + |
| 38 | + expect(feed.updatePeriod, UpdatePeriod.Hourly); |
| 39 | + expect(feed.updateFrequency, 2); |
| 40 | + expect(feed.updateBase, DateTime.parse('2000-01-01T12:00+00:00')); |
| 41 | + }); |
| 42 | + |
| 43 | + test('parse RSS1 with dublin core module', () { |
| 44 | + final xmlString = |
| 45 | + File('test/xml/RSS1-with-dublin-core-module.xml').readAsStringSync(); |
| 46 | + final feed = new Rss1Feed.parse(xmlString); |
| 47 | + |
| 48 | + expect(feed.title, 'Meerkat'); |
| 49 | + expect(feed.link, 'http://meerkat.oreillynet.com'); |
| 50 | + expect(feed.description, 'Meerkat: An Open Wire Service'); |
| 51 | + |
| 52 | + expect(feed.dc.publisher, 'The O\'Reilly Network'); |
| 53 | + expect(feed.dc.creator, 'Rael Dornfest (mailto:[email protected])'); |
| 54 | + expect(feed.dc.rights, 'Copyright © 2000 O\'Reilly & Associates, Inc.'); |
| 55 | + expect(feed.dc.date, '2000-01-01T12:00+00:00'); |
| 56 | + |
| 57 | + final firstItem = feed.items.first; |
| 58 | + expect( |
| 59 | + firstItem.dc.description, |
| 60 | + 'XML is placing increasingly heavy loads on the existing technical infrastructure of the Internet.', |
| 61 | + ); |
| 62 | + expect(firstItem.dc.publisher, 'The O\'Reilly Network'); |
| 63 | + expect( |
| 64 | + firstItem.dc.creator, |
| 65 | + 'Simon St.Laurent (mailto:[email protected])', |
| 66 | + ); |
| 67 | + expect( |
| 68 | + firstItem.dc.rights, 'Copyright © 2000 O\'Reilly & Associates, Inc.'); |
| 69 | + expect(firstItem.dc.subject, 'XML'); |
| 70 | + }); |
| 71 | + |
| 72 | + test('parse RSS1 with content module', () { |
| 73 | + final xmlString = |
| 74 | + File('test/xml/RSS1-with-content-module.xml').readAsStringSync(); |
| 75 | + final feed = new Rss1Feed.parse(xmlString); |
| 76 | + |
| 77 | + expect(feed.title, 'Example Feed'); |
| 78 | + expect(feed.link, 'http://www.example.org'); |
| 79 | + expect(feed.description, 'Simply for the purpose of demonstration.'); |
| 80 | + |
| 81 | + final firstItem = feed.items.first; |
| 82 | + expect( |
| 83 | + firstItem.content.value, |
| 84 | + '<p>What a <em>beautiful</em> day!</p>', |
| 85 | + ); |
| 86 | + expect( |
| 87 | + firstItem.content.images, |
| 88 | + Iterable.empty(), |
| 89 | + ); |
| 90 | + }); |
| 91 | + |
| 92 | + // Japanese Social Bookmark Service "Hatena Bookmark" is still using RSS1.0! |
| 93 | + // As I don't know english service using RSS 1.0, I use Japanese service for test case. |
| 94 | + test("parse production RSS1.0", () { |
| 95 | + var xmlString = |
| 96 | + new File("test/xml/RSS1-production_hatena.xml").readAsStringSync(); |
| 97 | + |
| 98 | + var feed = new Rss1Feed.parse(xmlString); |
| 99 | + |
| 100 | + expect(feed.title, 'sampleのはてなブックマーク'); |
| 101 | + expect(feed.link, 'https://b.hatena.ne.jp/sample/bookmark'); |
| 102 | + expect(feed.description, 'sampleのはてなブックマーク (17)'); |
| 103 | + |
| 104 | + expect(feed.items.length, 17); |
| 105 | + |
| 106 | + final firstItem = feed.items.first; |
| 107 | + |
| 108 | + expect(firstItem.description, ''); |
| 109 | + expect(firstItem.title, 'はてなスタッフのブックマーク拝見! - 営業マン編「仕事の様々なシーンでフル活用」'); |
| 110 | + expect(firstItem.link, 'http://b.hatena.ne.jp/guide/staff_bookmark_03'); |
| 111 | + expect(firstItem.dc.creator, 'sample'); |
| 112 | + expect(firstItem.dc.date, '2009-04-10T09:44:20Z'); |
| 113 | + expect(firstItem.dc.subject, 'はてな'); |
| 114 | + expect(firstItem.dc.subjects[0], 'はてな'); |
| 115 | + expect(firstItem.dc.subjects[1], 'インタビュー'); |
| 116 | + expect(firstItem.dc.subjects[2], 'はてなブックマーク'); |
| 117 | + }); |
| 118 | +} |
0 commit comments