Browse code

Added those new tests (whoops)

Jaidyn Levesque authored on 2019-07-10 17:24:40
Showing 2 changed files
1 1
deleted file mode 100644
... ...
@@ -1,97 +0,0 @@
1
-(defpackage :rsss-testing
2
-  (:use :cl)
3
-  (:export
4
-
5
-    :do-all))
6
-
7
-(in-package :rsss-testing)
8
-
9
-
10
-(defun do-all ()
11
-  "Execute all tests."
12
-
13
-  (rt:do-tests))
14
-
15
-
16
-
17
-;; ----------------------------------------
18
-;; DATA PREP
19
-;; ----------------------------------------
20
-
21
-(defvar *rss* "")
22
-(with-open-file (file-stream "t/res/rss.xml")
23
-  (do ((line (read-line file-stream nil)
24
-             (read-line file-stream nil)))
25
-    ((null line))
26
-
27
-    (setq *rss*
28
-          (concatenate 'string *rss* (format nil "~A~%" line)))))
29
-
30
-(setq *rss* (xmls:parse-to-list *rss*))
31
-
32
-(defvar *getf-strings-list*
33
-  '(("apple" 1) ("pear" 2) ("plum" yuck) ("plum" yum) ("madoka" weeb 2)))
34
-
35
-
36
-
37
-;; ----------------------------------------
38
-;; MISC
39
-;; ----------------------------------------
40
-
41
-(rt:deftest getf-strings
42
-            (rsss:getf-strings *getf-strings-list* "apple")
43
-            (("apple" 1)))
44
-
45
-(rt:deftest getf-strings-1
46
-            (rsss:getf-strings *getf-strings-list* "plum")
47
-            (("plum" yuck) ("plum" yum)))
48
-
49
-(rt:deftest getf-strings-2
50
-            (rsss:getf-strings *getf-strings-list* "madoka")
51
-
52
-            (("madoka" weeb 2)))
53
-
54
-
55
-(rt:deftest getf-string
56
-            (rsss:getf-string *getf-strings-list* "plum")
57
-
58
-            ("plum" yuck))
59
-
60
-
61
-
62
-;; ----------------------------------------
63
-;; FEED PARSING
64
-;; ----------------------------------------
65
-
66
-(rt:deftest feed-values
67
-            (rsss:feed-values *rss* "item") 
68
-            (("item" NIL ("title" NIL "Local Resident Takes a Nap") ("description" NIL "John was reported to be \"tired\" and \"irritable\" before his nap. Not so any more.") ("link" NIL "gopher://www.news.com.co.uk.cn/nap.cgi") ("guid" (("isPermaLink" "false")) "1102345") ("pubDate" NIL "Mon, 28 Aug 2018 09:00:00 -0400")) ("item" NIL ("title" NIL "London Bridge Has Burned Down") ("description" NIL "Oh no, not again! :(") ("link" NIL "https://londonbridge.co.uk.cn/bridge.php") ("guid" (("isPermaLink" "false")) "1102345") ("pubDate" NIL "Tue, 29 Aug 2018 09:00:00 -0400"))))
69
-
70
-(rt:deftest feed-items
71
-            (rsss:feed-items *rss*) 
72
-            (("item" NIL ("title" NIL "Local Resident Takes a Nap") ("description" NIL "John was reported to be \"tired\" and \"irritable\" before his nap. Not so any more.") ("link" NIL "gopher://www.news.com.co.uk.cn/nap.cgi") ("guid" (("isPermaLink" "false")) "1102345") ("pubDate" NIL "Mon, 28 Aug 2018 09:00:00 -0400")) ("item" NIL ("title" NIL "London Bridge Has Burned Down") ("description" NIL "Oh no, not again! :(") ("link" NIL "https://londonbridge.co.uk.cn/bridge.php") ("guid" (("isPermaLink" "false")) "1102345") ("pubDate" NIL "Tue, 29 Aug 2018 09:00:00 -0400"))))
73
-
74
-(rt:deftest feed-value
75
-            (rsss:feed-value *rss* "title")
76
-            ("title" NIL "RSS Sage Emergency Broadcast"))
77
-
78
-(rt:deftest feed-value-listless
79
-            (rsss:feed-value-listless *rss* "title")
80
-            "RSS Sage Emergency Broadcast")
81
-
82
-(rt:deftest title
83
-            (rsss:title *rss*)
84
-            "RSS Sage Emergency Broadcast")
85
-
86
-(rt:deftest description
87
-            (rsss:description *rss*)
88
-            "Your daily dose of RSS Sage tests!")
89
-
90
-(rt:deftest link
91
-            (rsss:link *rss*)
92
-            "https://rsss.eunichx.us")
93
-
94
-(rt:deftest pubdate
95
-            (rsss:pubdate *rss*)
96
-            "Tue, 29 Aug 2018 09:00:00 -0400")
97
-
98 0
new file mode 100644
... ...
@@ -0,0 +1,179 @@
1
+(defpackage :rsss-testing
2
+  (:use :cl)
3
+  (:export :do-all))
4
+
5
+(in-package :rsss-testing)
6
+
7
+;; NIL → VARYING
8
+(defun do-all ()
9
+  "Execute all tests."
10
+  (rt:do-tests))
11
+
12
+;; -----------------
13
+
14
+;; To run these tests, just load up :rsss-testing and run #'do-all.
15
+;; Senproblem'!
16
+
17
+;; -----------------
18
+
19
+(defvar *atom-xml*   (alexandria:read-file-into-string #p"t/atom.xml"))
20
+(defvar *atom-node*  (xmls:parse *atom-xml*))
21
+(defvar *atom-entry* (eighth (xmls:node-children *atom-node*)))
22
+(defvar *rss1-xml*   (alexandria:read-file-into-string #p"t/rss1.xml"))
23
+(defvar *rss1-node*  (xmls:parse *rss1-xml*))
24
+(defvar *rss1-entry* (second (xmls:node-children *rss1-node*)))
25
+(defvar *rss2-xml*   (alexandria:read-file-into-string #p"t/rss2.xml"))
26
+(defvar *rss2-node*  (xmls:parse *rss2-xml*))
27
+(defvar *rss2-entry* (sixth (xmls:node-children
28
+			    (car (xmls:node-children *rss2-node*)))))
29
+
30
+;; —————————————————————————————————————
31
+;; MISC
32
+;; —————————————————————————————————————
33
+(rt:deftest append-or-replace-i
34
+	    (let ((test-list nil))
35
+	      (rsss::append-or-replace test-list 1))
36
+	    (1))
37
+(rt:deftest append-or-replace-ii
38
+	    (let ((test-list '("never again!" 2312 "well, maybe…")))
39
+	      (rsss::append-or-replace test-list "again. MAYBE."))
40
+	    ("never again!" 2312 "well, maybe…" "again. MAYBE."))
41
+
42
+(rt:deftest equ-assoc-i
43
+	    (let ((test-assoc '(("mami" 2) ("madoka" 3) ("homura" 4))))
44
+	      (rsss::equ-assoc "madoka" test-assoc))
45
+	    ("madoka" 3))
46
+(rt:deftest equ-assoc-ii
47
+	    (let ((test-assoc '(("homura" "madoka"))))
48
+	      (rsss::equ-assoc "homura" test-assoc))
49
+	    ("homura" "madoka"))
50
+
51
+(rt:deftest nilp-i
52
+	    (rsss::nilp nil)
53
+	    T)
54
+(rt:deftest nilp-ii
55
+	    (rsss::nilp 1)
56
+	    nil)
57
+
58
+(rt:deftest ie-car-i
59
+	    (multiple-value-bind (result error)
60
+	      (rsss::ie-car 1)
61
+	      (list result (not (rsss::nilp error))))
62
+	    (nil T))
63
+(rt:deftest ie-car-ii
64
+	    (multiple-value-bind (result error)
65
+	      (rsss::ie-car '((1 2) 2 3))
66
+	      (list result (not (rsss::nilp error))))
67
+	    ((1 2) nil))
68
+
69
+
70
+;; —————————————————————————————————————
71
+;; PARSING
72
+;; —————————————————————————————————————
73
+;; ATOM PARSING
74
+;; —————————————————
75
+(rt:deftest parse-atom-i
76
+	    (rsss:name (rsss::parse-atom *atom-node*))
77
+	    "Planet GNU")
78
+(rt:deftest parse-atom-ii
79
+	    (rsss:date (rsss::parse-atom *atom-node*))
80
+	    "2019-07-09T17:55:32+00:00")
81
+(rt:deftest parse-atom-iii
82
+	    (rsss:uri (rsss::parse-atom *atom-node*))
83
+	    "https://planet.gnu.org/")
84
+(rt:deftest parse-atom-iv
85
+	    (length (rsss:entries (rsss::parse-atom *atom-node*)))
86
+	    60)
87
+(rt:deftest parse-atom-v
88
+	    (rsss:name (third (rsss:entries (rsss::parse-atom *atom-node*))))
89
+	    "DW5821e firmware update integration in ModemManager and fwupd")
90
+
91
+(rt:deftest parse-atom-entry-i
92
+	    (length (rsss:text (rsss::parse-atom-entry *atom-entry*)))
93
+	    7923)
94
+(rt:deftest parse-atom-entry-ii
95
+	    (rsss:author (rsss::parse-atom-entry *atom-entry*))
96
+	    "Christopher Lemmer Webber")
97
+(rt:deftest parse-atom-entry-iii
98
+	    (rsss:date (rsss::parse-atom-entry *atom-entry*))
99
+	    "2019-07-09T14:27:00+00:00")
100
+(rt:deftest parse-atom-entry-iv
101
+	    (rsss:uri (rsss::parse-atom-entry *atom-entry*))
102
+	    "http://dustycloud.org/blog/racket-is-an-acceptable-python/")
103
+
104
+;; —————————————————
105
+;; RSS1 PARSING
106
+;; —————————————————
107
+(rt:deftest parse-rss1-i
108
+	    (rsss:name (rsss::parse-rss *rss1-node*))
109
+	    "Planet GNU")
110
+(rt:deftest parse-rss1-ii
111
+	    (rsss:date (rsss::parse-rss *rss1-node*))
112
+	    nil)
113
+(rt:deftest parse-rss1-iii
114
+	    (rsss:uri (rsss::parse-rss *rss1-node*))
115
+	    "https://planet.gnu.org/")
116
+(rt:deftest parse-rss1-iv
117
+	    (length (rsss:entries (rsss::parse-rss *rss1-node*)))
118
+	    60)
119
+(rt:deftest parse-rss1-v
120
+	    (rsss:name (third (rsss:entries (rsss::parse-rss *rss1-node*))))
121
+	    "FSF Blogs: Thank you for advancing free software: Read FSF spring news in the latest Bulletin")
122
+
123
+(rt:deftest parse-rss1-entry-i
124
+	    (length (rsss:text (rsss::parse-rss-item *rss1-entry*)))
125
+	    14616)
126
+(rt:deftest parse-rss1-entry-ii
127
+	    (rsss:author (rsss::parse-rss-item *rss1-entry*))
128
+	    "FSF Blogs")
129
+(rt:deftest parse-rss1-entry-iii
130
+	    (rsss:date (rsss::parse-rss-item *rss1-entry*))
131
+	    "2019-07-09T15:39:21+00:00")
132
+(rt:deftest parse-rss1-entry-iv
133
+	    (rsss:uri (rsss::parse-rss-item *rss1-entry*))
134
+	    "http://www.fsf.org/blogs/rms/photo-blog-2019-june-brno")
135
+
136
+;; —————————————————
137
+;; RSS2 PARSING
138
+;; —————————————————
139
+(rt:deftest parse-rss2-i
140
+	    (rsss:name (rsss::parse-rss *rss2-node*))
141
+	    "Esperanto-USA member blogs")
142
+(rt:deftest parse-rss2-ii
143
+	    (rsss:date (rsss::parse-rss *rss2-node*))
144
+	    "2019-07-09T00:00:39-07:00")
145
+(rt:deftest parse-rss2-iii
146
+	    (rsss:uri (rsss::parse-rss *rss2-node*))
147
+	    "http://esperanto-usa.org/eusa/blogs/member-blogs.rss")
148
+(rt:deftest parse-rss2-iv
149
+	    (length (rsss:entries (rsss::parse-rss *rss2-node*)))
150
+	    21)
151
+(rt:deftest parse-rss2-v
152
+	    (rsss:name (third (rsss:entries (rsss::parse-rss *rss2-node*))))
153
+	    "Maja bulteno")
154
+
155
+(rt:deftest parse-rss2-entry-i
156
+	    (length (rsss:text (rsss::parse-rss-item *rss2-entry*)))
157
+	    0)
158
+(rt:deftest parse-rss2-entry-ii
159
+	    (rsss:author (rsss::parse-rss-item *rss2-entry*))
160
+	    nil)
161
+(rt:deftest parse-rss2-entry-iii
162
+	    (rsss:date (rsss::parse-rss-item *rss2-entry*))
163
+	    "2019-06-29T00:47:00+00:00")
164
+(rt:deftest parse-rss2-entry-iv
165
+	    (rsss:uri (rsss::parse-rss-item *rss2-entry*))
166
+	    "http://eo1a.blogspot.com/2019/06/cirkau-la-mondon-post-okdek-tagoj-26.html")
167
+
168
+;; —————————————————
169
+;; GENERAL PARSING
170
+;; —————————————————
171
+(rt:deftest parse-i
172
+	    (type-of (rsss:parse *atom-xml*))
173
+	    rsss::feed)
174
+(rt:deftest parse-ii
175
+	    (type-of (rsss:parse *rss1-xml*))
176
+	    rsss::feed)
177
+(rt:deftest parse-iii
178
+	    (type-of (rsss:parse *rss2-xml*))
179
+	    rsss::feed)