Commit Diff
Diff:
bcb8cfe712a86826bed02978c4258b92bc3efbf9
033f04abccae60ae5768bba9fec49c6e496fbdfc
Commit:
033f04abccae60ae5768bba9fec49c6e496fbdfc
Tree:
cfde06fba85db4603b5696051f49dff8bfd32390
Author:
Omar Polo <op@omarpolo.com>
Date:
Fri Jan 14 16:57:34 2022 UTC
Message:
add some tests for the gemtext parser
commit - bcb8cfe712a86826bed02978c4258b92bc3efbf9
commit + 033f04abccae60ae5768bba9fec49c6e496fbdfc
blob - 56e3b193063c19313db1c76a2f621afc5a2a7f3b
blob + 6247326deb77ceca451db9d67914664b83f08563
--- phos.asd
+++ phos.asd
@@ -16,3 +16,12 @@
:description "An experimental GUI Gemini client"
:depends-on ("phos" "nodgui")
:components ((:file "ui")))
+
+(asdf:defsystem #:phos/test
+ :description "Test suite for phos."
+ :depends-on ("phos" "clunit2")
+ :serial t
+ :pathname "t"
+ :components ((:file "package")
+ (:file "all-tests")
+ (:file "gemtext-tests")))
blob - /dev/null
blob + 7b4f011726ccb8039dd2cc19c79a52e468c9fb62 (mode 644)
--- /dev/null
+++ t/all-tests.lisp
@@ -0,0 +1,9 @@
+(in-package :all-tests)
+
+(defsuite all-suite ())
+
+(defun run-all-tests (&key (use-debugger t))
+ (clunit:run-suite 'all-suite :use-debugger use-debugger
+ :report-progress t))
+
+;; (run-all-tests)
blob - /dev/null
blob + 11c6d0387a8ca0645c1dba062371db92eb4432dd (mode 644)
--- /dev/null
+++ t/gemtext-tests.lisp
@@ -0,0 +1,38 @@
+(in-package :gemtext-tests)
+
+(defsuite gemtext-suite (all-suite))
+
+(defun cmp-lines (xs ys)
+ (cond ((and (null xs) (null ys)) t)
+ ((and (null xs) ys) nil)
+ ((and xs (null ys)) nil)
+ ((not (gemtext:line-eq (car xs) (car ys))) nil)
+ (t (cmp-lines (cdr xs) (cdr ys)))))
+
+(deftest test-parse-elements (gemtext-suite)
+ (loop with suite = `(("# title" . ,(make-instance 'gemtext:title
+ :text "title"
+ :level 1))
+ ("#title" . ,(make-instance 'gemtext:title
+ :text "title"
+ :level 1))
+ ("## title" . ,(make-instance 'gemtext:title
+ :text "title"
+ :level 2))
+ ("###title" . ,(make-instance 'gemtext:title
+ :text "title"
+ :level 3))
+ ("=>/foo" . ,(make-instance 'gemtext:link
+ :url (quri:uri "/foo")))
+ ("=> /foo bar" . ,(make-instance 'gemtext:link
+ :url (quri:uri "/foo")
+ :text "bar"))
+ ("* list item " . ,(make-instance 'gemtext:item
+ :text "list item"))
+ ("*text" . ,(make-instance 'gemtext:paragraph
+ :text "*text"))
+ (">cit" . ,(make-instance 'gemtext:blockquote
+ :text "cit")))
+ for (str . exp) in suite
+ do (assert-true (cmp-lines (gemtext:parse-string str)
+ (list exp)))))
blob - /dev/null
blob + 3ae73f5d1e00d8ac0e6f9c60f4134edfae1a2524 (mode 644)
--- /dev/null
+++ t/package.lisp
@@ -0,0 +1,7 @@
+(defpackage :all-tests
+ (:use :cl :clunit)
+ (:export :all-suite :run-all-tests))
+
+(defpackage :gemtext-tests
+ (:use :cl :clunit :all-tests)
+ (:export))
Omar Polo