1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
;;; Excercise RSS 2.0 reader. -*- Scheme -*-
;;;
;;; Copyright (C) 2008, 2009, 2012, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of Skribilo.
;;;
;;; Skribilo is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU Lesser General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; Skribilo is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (tests rss-2)
#:use-module (ice-9 match)
#:use-module (skribilo reader)
#:use-module (srfi srfi-64))
(if (or (not (false-if-exception (resolve-interface '(sxml simple))))
(not (false-if-exception (resolve-interface '(htmlprag)))))
(exit 77))
(define %rss2-read #f)
(define-syntax test-match
(syntax-rules ()
((_ name pattern xml)
;; Test whether the RSS feed in XML matches PATTERN.
(test-assert name
(match (%rss2-read (open-input-string xml))
(pattern #t)
(_ #f))))))
(test-begin "rss-2")
(test-eq "make-reader" #t
(begin
(set! %rss2-read (make-reader 'rss-2))
(procedure? %rss2-read)))
(test-match "basic"
`(document ,'#:title (list "The Channel")
(chapter ,'#:title (list "Foo Bar")
,_ ;; the date
(list "Hello world.")))
"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<rss version=\"2.0\">
<channel>
<title>The Channel</title>
<link>http://example.net/</link>
<description>Some channel description...</description>
<item>
<title>Foo Bar</title>
<pubDate>Mon, 06 Jun 2005 23:05:00 +0200</pubDate>
<description>Hello world.</description>
</item>
</channel>
</rss>")
(test-match "with HTML markup"
`(document ,'#:title (list (emph "The") " Channel")
(chapter ,'#:title (list "Foo " (bold "&") " Bar")
,_ ;; the date
(list (p "Hello world."))))
"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<rss version=\"2.0\">
<channel>
<title><em>The</em> Channel</title>
<link>http://example.net/</link>
<description>Some channel description...</description>
<item>
<title>Foo <b>&</b> Bar</title>
<pubDate>Mon, 06 Jun 2005 23:05:00 +0200</pubDate>
<description><P>Hello world.</P></description>
</item>
</channel>
</rss>")
(test-match "broken date format"
`(document ,'#:title (list "The Channel")
(chapter ,'#:title (list "Foo Bar")
,_ ;; the date
(list "Hello world.")))
"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<rss version=\"2.0\">
<channel>
<title>The Channel</title>
<link>http://example.net/</link>
<description>Some channel description...</description>
<item>
<title>Foo Bar</title>
<!-- Feeds at livejournal.com, e.g.,
http://udrepper.livejournal.com/rss.xml contain a broken date with,
e.g., \"GMT\" instead of \"+0000\". -->
<pubDate>Mon, 06 Jun 2005 23:05:00 GMT</pubDate>
<description>Hello world.</description>
</item>
</channel>
</rss>")
(test-match "table"
`(document ,'#:title (list "The Channel")
(chapter ,'#:title (list "Foo Bar")
,_ ;; the date
(list
,_ ,_ ;; whitespace
(table
(th (td "Foo") (td "Bar"))
(tr (td "001") (td "002")))
,_ ,_ ;; whitespace
)))
"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<rss version=\"2.0\">
<channel>
<title>The Channel</title>
<link>http://example.net/</link>
<description>Some channel description...</description>
<item>
<title>Foo Bar</title>
<pubDate>Mon, 06 Jun 2005 23:05:00 +0200</pubDate>
<description>
<table>
<th><td>Foo</td><td>Bar</td></th>
<tr><td>001</td><td>002</td></tr>
</table>
</description>
</item>
</channel>
</rss>")
(test-end "rss-2")
|