Blob


1 (in-package :gemtext-tests)
3 (defsuite gemtext-suite (all-suite))
5 (defun cmp-lines (xs ys)
6 (cond ((and (null xs) (null ys)) t)
7 ((and (null xs) ys) nil)
8 ((and xs (null ys)) nil)
9 ((not (gemtext:line-eq (car xs) (car ys))) nil)
10 (t (cmp-lines (cdr xs) (cdr ys)))))
12 (deftest test-parse-elements (gemtext-suite)
13 (loop with suite = `(("# title" . ,(make-instance 'gemtext:title
14 :text "title"
15 :level 1))
16 ("#title" . ,(make-instance 'gemtext:title
17 :text "title"
18 :level 1))
19 ("## title" . ,(make-instance 'gemtext:title
20 :text "title"
21 :level 2))
22 ("###title" . ,(make-instance 'gemtext:title
23 :text "title"
24 :level 3))
25 ;; handle gracefully invalid link lines
26 ("=>" . ,(make-instance 'gemtext:paragraph
27 :text "=>"))
28 ("=>/foo" . ,(make-instance 'gemtext:link
29 :url (quri:uri "/foo")))
30 ("=> /foo bar" . ,(make-instance 'gemtext:link
31 :url (quri:uri "/foo")
32 :text "bar"))
33 ("* list item " . ,(make-instance 'gemtext:item
34 :text "list item"))
35 ("*text" . ,(make-instance 'gemtext:paragraph
36 :text "*text"))
37 (">cit" . ,(make-instance 'gemtext:blockquote
38 :text "cit")))
39 for (str . exp) in suite
40 do (assert-true (cmp-lines (gemtext:parse-string str)
41 (list exp)))))