summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/git.scm60
-rw-r--r--tests/issue.scm38
-rw-r--r--tests/tissue.scm9
-rw-r--r--tests/web/server.scm28
4 files changed, 123 insertions, 12 deletions
diff --git a/tests/git.scm b/tests/git.scm
new file mode 100644
index 0000000..bf2d9eb
--- /dev/null
+++ b/tests/git.scm
@@ -0,0 +1,60 @@
+;;; tissue --- Text based issue tracker
+;;; Copyright © 2023 Arun Isaac <arunisaac@systemreboot.net>
+;;;
+;;; This file is part of tissue.
+;;;
+;;; tissue is free software: you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; tissue 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
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with tissue.  If not, see <https://www.gnu.org/licenses/>.
+
+(import (srfi srfi-26)
+        (srfi srfi-64)
+        (ice-9 match))
+
+(define (with-variable variable value thunk)
+  "Set VARIABLE to VALUE, run THUNK and restore the old value of
+VARIABLE. Return the value returned by THUNK."
+  (let ((old-value (variable-ref variable)))
+    (dynamic-wind
+      (cut variable-set! variable value)
+      thunk
+      (cut variable-set! variable old-value))))
+
+(define (with-variables variable-bindings thunk)
+  "Set VARIABLE-BINDINGS, run THUNK and restore the old values of the
+variables. Return the value returned by THUNK. VARIABLE-BINDINGS is a
+list of pairs mapping variables to their values."
+  (match variable-bindings
+    (((variable . value) tail ...)
+     (with-variable variable value
+       (cut with-variables tail thunk)))
+    (() (thunk))))
+
+(define-syntax-rule (var@@ module-name variable-name)
+  (module-variable (resolve-module 'module-name)
+                   'variable-name))
+
+(test-begin "git")
+
+(test-equal "Infer changes by root commit"
+  '(("foo" . "foo")
+    ("bar" . "bar"))
+  (with-variables (list (cons (var@@ (git) commit-parents)
+                              (const (list)))
+                        (cons (var@@ (git) commit-tree)
+                              (const #t))
+                        (cons (var@@ (git) tree-list)
+                              (const (list "foo" "bar"))))
+    (cut (@@ (tissue git) commit-file-changes)
+         #f #f)))
+
+(test-end "git")
diff --git a/tests/issue.scm b/tests/issue.scm
index 22982db..97541a0 100644
--- a/tests/issue.scm
+++ b/tests/issue.scm
@@ -1,5 +1,5 @@
 ;;; tissue --- Text based issue tracker
-;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2022, 2023 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This file is part of tissue.
 ;;;
@@ -19,6 +19,7 @@
 (import (rnrs hashtables)
         (srfi srfi-64)
         (srfi srfi-71)
+        (ice-9 match)
         (tissue issue))
 
 (define hashtable-prepend!
@@ -31,10 +32,20 @@
   (@@ (tissue issue) file-details))
 
 (define (hashtable->alist hashtable)
+  "Convert @var{hashtable} to association list with keys sorted as
+strings."
   (let ((keys values (hashtable-entries hashtable)))
-    (map cons
-         (vector->list keys)
-         (vector->list values))))
+    (sort (map cons
+               (vector->list keys)
+               (vector->list values))
+          (match-lambda*
+            (((key1 . _) (key2 . _))
+             (let ((maybe-symbol->string (lambda (x)
+                                           (if (symbol? x)
+                                               (symbol->string x)
+                                               x))))
+               (string<? (maybe-symbol->string key1)
+                         (maybe-symbol->string key2))))))))
 
 (test-begin "issue")
 
@@ -75,4 +86,23 @@
   (call-with-input-string "* keywords: this is a long keyword"
     (compose hashtable->alist file-details)))
 
+(test-equal "Parse checkboxes"
+  '((completed-tasks . 1)
+    (tasks . 2))
+  (call-with-input-string "* [ ] foo
+* [x] bar"
+    (compose hashtable->alist file-details)))
+
+(test-equal "Allow checkboxes without a space"
+  '((tasks . 1))
+  (call-with-input-string "* [] foo"
+    (compose hashtable->alist file-details)))
+
+(test-equal "Ignore preformatted block"
+  '()
+  (call-with-input-string "```
+# foo
+```"
+    (compose hashtable->alist file-details)))
+
 (test-end "issue")
diff --git a/tests/tissue.scm b/tests/tissue.scm
index 6fb01fa..b2aa8e0 100644
--- a/tests/tissue.scm
+++ b/tests/tissue.scm
@@ -1,5 +1,5 @@
 ;;; tissue --- Text based issue tracker
-;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2022, 2023 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This file is part of tissue.
 ;;;
@@ -18,13 +18,6 @@
 
 (import (srfi srfi-64))
 
-(define pairify
-  (@@ (tissue tissue) pairify))
-
 (test-begin "tissue")
 
-(test-equal "pairify"
-  '((1 . 2) (3 . 4) (5 . 6))
-  (pairify (list 1 2 3 4 5 6)))
-
 (test-end "tissue")
diff --git a/tests/web/server.scm b/tests/web/server.scm
new file mode 100644
index 0000000..25537ab
--- /dev/null
+++ b/tests/web/server.scm
@@ -0,0 +1,28 @@
+;;; tissue --- Text based issue tracker
+;;; Copyright © 2023 Arun Isaac <arunisaac@systemreboot.net>
+;;;
+;;; This file is part of tissue.
+;;;
+;;; tissue is free software: you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; tissue 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
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with tissue.  If not, see <https://www.gnu.org/licenses/>.
+
+(import (srfi srfi-64)
+        (tissue web server))
+
+(test-begin "web-server")
+
+(test-equal "MIME type of file without extension should be application/octet-stream"
+  '(application/octet-stream)
+  (mime-type-for-extension ""))
+
+(test-end "web-server")