Archived
1
0
Disbranĉigi 0

Added those new tests (whoops)

This commit is contained in:
Jaidyn Levesque 2019-07-10 12:24:40 -05:00
parent 5e6776a75c
commit 404464e41f
2 changed files with 179 additions and 97 deletions

View File

@ -1,97 +0,0 @@
(defpackage :rsss-testing
(:use :cl)
(:export
:do-all))
(in-package :rsss-testing)
(defun do-all ()
"Execute all tests."
(rt:do-tests))
;; ----------------------------------------
;; DATA PREP
;; ----------------------------------------
(defvar *rss* "")
(with-open-file (file-stream "t/res/rss.xml")
(do ((line (read-line file-stream nil)
(read-line file-stream nil)))
((null line))
(setq *rss*
(concatenate 'string *rss* (format nil "~A~%" line)))))
(setq *rss* (xmls:parse-to-list *rss*))
(defvar *getf-strings-list*
'(("apple" 1) ("pear" 2) ("plum" yuck) ("plum" yum) ("madoka" weeb 2)))
;; ----------------------------------------
;; MISC
;; ----------------------------------------
(rt:deftest getf-strings
(rsss:getf-strings *getf-strings-list* "apple")
(("apple" 1)))
(rt:deftest getf-strings-1
(rsss:getf-strings *getf-strings-list* "plum")
(("plum" yuck) ("plum" yum)))
(rt:deftest getf-strings-2
(rsss:getf-strings *getf-strings-list* "madoka")
(("madoka" weeb 2)))
(rt:deftest getf-string
(rsss:getf-string *getf-strings-list* "plum")
("plum" yuck))
;; ----------------------------------------
;; FEED PARSING
;; ----------------------------------------
(rt:deftest feed-values
(rsss:feed-values *rss* "item")
(("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"))))
(rt:deftest feed-items
(rsss:feed-items *rss*)
(("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"))))
(rt:deftest feed-value
(rsss:feed-value *rss* "title")
("title" NIL "RSS Sage Emergency Broadcast"))
(rt:deftest feed-value-listless
(rsss:feed-value-listless *rss* "title")
"RSS Sage Emergency Broadcast")
(rt:deftest title
(rsss:title *rss*)
"RSS Sage Emergency Broadcast")
(rt:deftest description
(rsss:description *rss*)
"Your daily dose of RSS Sage tests!")
(rt:deftest link
(rsss:link *rss*)
"https://rsss.eunichx.us")
(rt:deftest pubdate
(rsss:pubdate *rss*)
"Tue, 29 Aug 2018 09:00:00 -0400")

179
t/rsss.lisp Normal file
View File

@ -0,0 +1,179 @@
(defpackage :rsss-testing
(:use :cl)
(:export :do-all))
(in-package :rsss-testing)
;; NIL → VARYING
(defun do-all ()
"Execute all tests."
(rt:do-tests))
;; -----------------
;; To run these tests, just load up :rsss-testing and run #'do-all.
;; Senproblem'!
;; -----------------
(defvar *atom-xml* (alexandria:read-file-into-string #p"t/atom.xml"))
(defvar *atom-node* (xmls:parse *atom-xml*))
(defvar *atom-entry* (eighth (xmls:node-children *atom-node*)))
(defvar *rss1-xml* (alexandria:read-file-into-string #p"t/rss1.xml"))
(defvar *rss1-node* (xmls:parse *rss1-xml*))
(defvar *rss1-entry* (second (xmls:node-children *rss1-node*)))
(defvar *rss2-xml* (alexandria:read-file-into-string #p"t/rss2.xml"))
(defvar *rss2-node* (xmls:parse *rss2-xml*))
(defvar *rss2-entry* (sixth (xmls:node-children
(car (xmls:node-children *rss2-node*)))))
;; —————————————————————————————————————
;; MISC
;; —————————————————————————————————————
(rt:deftest append-or-replace-i
(let ((test-list nil))
(rsss::append-or-replace test-list 1))
(1))
(rt:deftest append-or-replace-ii
(let ((test-list '("never again!" 2312 "well, maybe…")))
(rsss::append-or-replace test-list "again. MAYBE."))
("never again!" 2312 "well, maybe…" "again. MAYBE."))
(rt:deftest equ-assoc-i
(let ((test-assoc '(("mami" 2) ("madoka" 3) ("homura" 4))))
(rsss::equ-assoc "madoka" test-assoc))
("madoka" 3))
(rt:deftest equ-assoc-ii
(let ((test-assoc '(("homura" "madoka"))))
(rsss::equ-assoc "homura" test-assoc))
("homura" "madoka"))
(rt:deftest nilp-i
(rsss::nilp nil)
T)
(rt:deftest nilp-ii
(rsss::nilp 1)
nil)
(rt:deftest ie-car-i
(multiple-value-bind (result error)
(rsss::ie-car 1)
(list result (not (rsss::nilp error))))
(nil T))
(rt:deftest ie-car-ii
(multiple-value-bind (result error)
(rsss::ie-car '((1 2) 2 3))
(list result (not (rsss::nilp error))))
((1 2) nil))
;; —————————————————————————————————————
;; PARSING
;; —————————————————————————————————————
;; ATOM PARSING
;; —————————————————
(rt:deftest parse-atom-i
(rsss:name (rsss::parse-atom *atom-node*))
"Planet GNU")
(rt:deftest parse-atom-ii
(rsss:date (rsss::parse-atom *atom-node*))
"2019-07-09T17:55:32+00:00")
(rt:deftest parse-atom-iii
(rsss:uri (rsss::parse-atom *atom-node*))
"https://planet.gnu.org/")
(rt:deftest parse-atom-iv
(length (rsss:entries (rsss::parse-atom *atom-node*)))
60)
(rt:deftest parse-atom-v
(rsss:name (third (rsss:entries (rsss::parse-atom *atom-node*))))
"DW5821e firmware update integration in ModemManager and fwupd")
(rt:deftest parse-atom-entry-i
(length (rsss:text (rsss::parse-atom-entry *atom-entry*)))
7923)
(rt:deftest parse-atom-entry-ii
(rsss:author (rsss::parse-atom-entry *atom-entry*))
"Christopher Lemmer Webber")
(rt:deftest parse-atom-entry-iii
(rsss:date (rsss::parse-atom-entry *atom-entry*))
"2019-07-09T14:27:00+00:00")
(rt:deftest parse-atom-entry-iv
(rsss:uri (rsss::parse-atom-entry *atom-entry*))
"http://dustycloud.org/blog/racket-is-an-acceptable-python/")
;; —————————————————
;; RSS1 PARSING
;; —————————————————
(rt:deftest parse-rss1-i
(rsss:name (rsss::parse-rss *rss1-node*))
"Planet GNU")
(rt:deftest parse-rss1-ii
(rsss:date (rsss::parse-rss *rss1-node*))
nil)
(rt:deftest parse-rss1-iii
(rsss:uri (rsss::parse-rss *rss1-node*))
"https://planet.gnu.org/")
(rt:deftest parse-rss1-iv
(length (rsss:entries (rsss::parse-rss *rss1-node*)))
60)
(rt:deftest parse-rss1-v
(rsss:name (third (rsss:entries (rsss::parse-rss *rss1-node*))))
"FSF Blogs: Thank you for advancing free software: Read FSF spring news in the latest Bulletin")
(rt:deftest parse-rss1-entry-i
(length (rsss:text (rsss::parse-rss-item *rss1-entry*)))
14616)
(rt:deftest parse-rss1-entry-ii
(rsss:author (rsss::parse-rss-item *rss1-entry*))
"FSF Blogs")
(rt:deftest parse-rss1-entry-iii
(rsss:date (rsss::parse-rss-item *rss1-entry*))
"2019-07-09T15:39:21+00:00")
(rt:deftest parse-rss1-entry-iv
(rsss:uri (rsss::parse-rss-item *rss1-entry*))
"http://www.fsf.org/blogs/rms/photo-blog-2019-june-brno")
;; —————————————————
;; RSS2 PARSING
;; —————————————————
(rt:deftest parse-rss2-i
(rsss:name (rsss::parse-rss *rss2-node*))
"Esperanto-USA member blogs")
(rt:deftest parse-rss2-ii
(rsss:date (rsss::parse-rss *rss2-node*))
"2019-07-09T00:00:39-07:00")
(rt:deftest parse-rss2-iii
(rsss:uri (rsss::parse-rss *rss2-node*))
"http://esperanto-usa.org/eusa/blogs/member-blogs.rss")
(rt:deftest parse-rss2-iv
(length (rsss:entries (rsss::parse-rss *rss2-node*)))
21)
(rt:deftest parse-rss2-v
(rsss:name (third (rsss:entries (rsss::parse-rss *rss2-node*))))
"Maja bulteno")
(rt:deftest parse-rss2-entry-i
(length (rsss:text (rsss::parse-rss-item *rss2-entry*)))
0)
(rt:deftest parse-rss2-entry-ii
(rsss:author (rsss::parse-rss-item *rss2-entry*))
nil)
(rt:deftest parse-rss2-entry-iii
(rsss:date (rsss::parse-rss-item *rss2-entry*))
"2019-06-29T00:47:00+00:00")
(rt:deftest parse-rss2-entry-iv
(rsss:uri (rsss::parse-rss-item *rss2-entry*))
"http://eo1a.blogspot.com/2019/06/cirkau-la-mondon-post-okdek-tagoj-26.html")
;; —————————————————
;; GENERAL PARSING
;; —————————————————
(rt:deftest parse-i
(type-of (rsss:parse *atom-xml*))
rsss::feed)
(rt:deftest parse-ii
(type-of (rsss:parse *rss1-xml*))
rsss::feed)
(rt:deftest parse-iii
(type-of (rsss:parse *rss2-xml*))
rsss::feed)