;;; Cyborg - Cyber Organizer ;;; Copyright © 2017, 2018 Jeremy Korwin ;;; ;;; This program 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. ;;; ;;; This program 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 ;;; this program. If not, see http://www.gnu.org/licenses/. ;; Load SRFI-64 lightweight testing specification (use-modules (srfi srfi-64) (ice-9 rdelim) ) (add-to-load-path (dirname (current-filename))) (use-modules (cybo)) ;; Suppress log file output. To write logs, comment out the following line: (module-define! (resolve-module '(srfi srfi-64)) 'test-log-to-file #f) (define (clear-test-files) (let ((files (list "todo.txt"))) (map (lambda (filename) (if (access? filename F_OK) (delete-file filename))) files))) (define (file-empty filename) (let ((todo.txt-port (open-output-file filename #:encoding "UTF-8"))) (close todo.txt-port))) (define (append-task filename task) (let ((todo.txt-port (open-file filename "a" #:encoding "UTF-8"))) (write-line task todo.txt-port) (close todo.txt-port))) (test-with-runner (test-runner-simple) (test-group "Todo.txt-does-not-exists" (test-assert "Should-return-empty-task-list" (null? (next-actions "todo.txt"))))) (test-with-runner (test-runner-simple) (test-group-with-cleanup "Todo.txt-is-empty" (file-empty "todo.txt") (test-assert "Should-return-empty-task-list" (null? (next-actions "todo.txt"))) (clear-test-files))) (test-with-runner (test-runner-simple) (test-group-with-cleanup "One-task-to-do" (append-task "todo.txt" "task to do") (test-equal "Should-return-the-task-to-do" '("task to do") (next-actions "todo.txt")) (clear-test-files) (append-task "todo.txt" "another task to do") (test-equal "Should-return-the-other-task-to-do" '("another task to do") (next-actions "todo.txt")) (clear-test-files))) (test-with-runner (test-runner-simple) (test-group-with-cleanup "Two-tasks-to-do" (append-task "todo.txt" "first task to do") (append-task "todo.txt" "second task to do") (test-equal "Should-return-the-tasks-to-do" '("first task to do" "second task to do") (next-actions "todo.txt")) (clear-test-files))) (test-with-runner (test-runner-simple) (test-group-with-cleanup "Three-priorized-tasks" (append-task "todo.txt" "(B) task in-between") (append-task "todo.txt" "(A) task more important") (append-task "todo.txt" "(C) task less important") (test-equal "Should-return-tasks-sorted-by-descending-order-of-priority" '("(A) task more important" "(B) task in-between" "(C) task less important") (next-actions "todo.txt")) (clear-test-files)))