From e505a66a1b22132fd429c7699b7b632143d6653c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 15 Oct 2015 22:37:40 -0400 Subject: tests: Add post tests. * tests/post.scm: New file. * Makefile.am (TESTS): Add it. --- Makefile.am | 1 + tests/post.scm | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/post.scm diff --git a/Makefile.am b/Makefile.am index 44cdb40..867b163 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,6 +70,7 @@ SOURCES += \ endif TESTS = \ + tests/post.scm \ tests/utils.scm TEST_EXTENSIONS = .scm diff --git a/tests/post.scm b/tests/post.scm new file mode 100644 index 0000000..bfc0d0e --- /dev/null +++ b/tests/post.scm @@ -0,0 +1,71 @@ +;;; Haunt --- Static site generator for GNU Guile +;;; Copyright © 2015 David Thompson +;;; +;;; This file is part of Haunt. +;;; +;;; Haunt 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. +;;; +;;; Haunt 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 Haunt. If not, see . + +(define-module (test-post) + #:use-module (srfi srfi-19) + #:use-module (srfi srfi-64) + #:use-module (haunt post)) + +(test-begin "post") + +(define (make-date* year month day) + (make-date 0 0 0 0 day month year 0)) + +(test-equal "post-ref" + '(hello test) + (post-ref (make-post "foo.skr" '((tags hello test)) '()) 'tags)) + +(test-equal "post-slug" + "hello-world" + (post-slug (make-post "foo.skr" '((title . "Hello, world!")) '()))) + +(test-equal "post-date, no date metadata" + %default-date + (post-date (make-post "foo.skr" '() '()))) + +(let ((date (make-date* 2015 10 15))) + (test-equal "post-date, date metadata" + date + (post-date (make-post "foo.skr" `((date . ,date)) '())))) + +(let ((oldest (make-post "foo.skr" `((date . ,(make-date* 2015 10 13))) '())) + (newest (make-post "bar.skr" `((date . ,(make-date* 2015 10 15))) '())) + (middle (make-post "baz.skr" `((date . ,(make-date* 2015 10 14))) '()))) + (test-equal "posts/reverse-chronological" + (list newest middle oldest) + (posts/reverse-chronological (list oldest newest middle)))) + +(let ((foo-post (make-post "foo.skr" '((tags "foo")) '())) + (another-foo-post (make-post "another-foo.skr" '((tags "foo")) '())) + (bar-post (make-post "bar.skr" '((tags "bar")) '()))) + (test-equal "posts/group-by-tag" + `(("foo" ,foo-post ,another-foo-post) ("bar" ,bar-post)) + (posts/group-by-tag (list another-foo-post foo-post bar-post)))) + +(test-equal "parse-metadata, tags" + '("foo" "bar" "baz") + (parse-metadata 'tags "foo, bar, baz")) + +(test-equal "parse-metadata, date" + (make-date 0 0 30 22 15 10 2015 (date-zone-offset (current-date))) + (parse-metadata 'date "2015-10-15 22:30")) + +(test-end) + + +(exit (zero? (test-runner-fail-count (test-runner-current)))) -- cgit v1.2.3