summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-07-07 02:08:59 +0530
committerArun Isaac2022-07-07 02:26:08 +0530
commitdc6e932000730ede3c23a270390db9482953b41a (patch)
treefabf2402c1fcbfa5f6b54c7e394093662cb51429
parent4da22c00f8081ba8c072dd4e476de736cb7be79f (diff)
downloadtissue-dc6e932000730ede3c23a270390db9482953b41a.tar.gz
tissue-dc6e932000730ede3c23a270390db9482953b41a.tar.lz
tissue-dc6e932000730ede3c23a270390db9482953b41a.zip
tests: Add tests.
* Makefile (GUILE, tests): New variables. (check): Run tests. * tests/issue.scm: New file.
-rw-r--r--Makefile5
-rw-r--r--tests/issue.scm73
2 files changed, 77 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 68afcd4..37c912d 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ project = tissue
guile_effective_version = 3.0
GUILD ?= guild
+GUILE ?= guile
prefix ?= /usr/local
exec_prefix ?= $(prefix)
@@ -32,6 +33,7 @@ top_level_module_dir = $(project)
sources = $(wildcard $(top_level_module_dir)/*.scm) $(wildcard $(top_level_module_dir)/web/*.scm)
objects = $(sources:.scm=.go)
scripts = $(wildcard bin/*)
+tests = $(wildcard tests/*)
scmdir = $(datarootdir)/guile/site/$(guile_effective_version)
godir = $(libdir)/guile/$(guile_effective_version)/site-ccache
@@ -43,7 +45,8 @@ all: $(objects)
%.go: %.scm
GUILE_AUTO_COMPILE=0 $(GUILD) compile -L . -o $@ $<
-check: ;
+check:
+ ./pre-inst-env $(GUILE) $(tests)
install:
install -D $(scripts) --target-directory $(bindir)
diff --git a/tests/issue.scm b/tests/issue.scm
new file mode 100644
index 0000000..74fb6c3
--- /dev/null
+++ b/tests/issue.scm
@@ -0,0 +1,73 @@
+;;; tissue --- Text based issue tracker
+;;; Copyright © 2022 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 (rnrs hashtables)
+ (srfi srfi-64)
+ (srfi srfi-71)
+ (tissue issue))
+
+(define hashtable-prepend!
+ (@@ (tissue issue) hashtable-prepend!))
+
+(define list-line->alist
+ (@@ (tissue issue) list-line->alist))
+
+(define file-details
+ (@@ (tissue issue) file-details))
+
+(define (hashtable->alist hashtable)
+ (let ((keys values (hashtable-entries hashtable)))
+ (map cons
+ (vector->list keys)
+ (vector->list values))))
+
+(test-begin "issue")
+
+(test-equal "Parse list line with multiple key-value pairs"
+ '((status "unclear")
+ (keywords "dangerous feature" "ui"))
+ (list-line->alist "* keywords: ui, dangerous feature, status: unclear"))
+
+(test-equal "Parse list line with repeated keys"
+ '((keywords "foo")
+ (status "unclear")
+ (keywords "dangerous feature" "ui"))
+ (list-line->alist "* keywords: ui, dangerous feature, status: unclear, keywords: foo"))
+
+(test-equal "Parse key-value list lines case insensitively"
+ '((keywords "dangerous feature" "ui"))
+ (list-line->alist "* Keywords: ui, dangerous feature"))
+
+(test-equal "Return keywords in order"
+ '((keywords "foo" "bar" "fubar"))
+ (call-with-input-string "* keywords: foo, bar, fubar"
+ (compose hashtable->alist file-details)))
+
+(let ((hashtable (make-eq-hashtable)))
+ (hashtable-set! hashtable 'keywords (list "foo" "bar"))
+ (hashtable-prepend! hashtable 'keywords (list "foobar" "fubar"))
+ (test-equal "hashtable-prepend! should prepend, not append"
+ '((keywords "fubar" "foobar" "foo" "bar"))
+ (hashtable->alist hashtable)))
+
+(test-equal "Do not parse definition-like lines as key-value pairs"
+ '()
+ (call-with-input-string "* term: This is a definition of term."
+ (compose hashtable->alist file-details)))
+
+(test-end "issue")