From fa2fc56a0a849f745d88396774ed9578883fbf30 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 16 Feb 2019 13:57:32 +0100 Subject: [PATCH] [Timeline] Add some first tests --- .gitignore | 1 - site-lisp/timeline-tools-test.el | 103 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 site-lisp/timeline-tools-test.el diff --git a/.gitignore b/.gitignore index a662f18..cb0d39e 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,6 @@ /server/server /speed-type/* /site-lisp/timeline-tools-autoloads.el -/site-lisp/timeline-tools-test.el /.cask/ /private/ /eww-bookmarks diff --git a/site-lisp/timeline-tools-test.el b/site-lisp/timeline-tools-test.el new file mode 100644 index 0000000..f0c87fd --- /dev/null +++ b/site-lisp/timeline-tools-test.el @@ -0,0 +1,103 @@ +;;; timeline-tools-test.el -- Tests for timeline-tools -*- lexical-binding: t -*- + +;;; Code: + +(require 'ert) +(require 'timeline-tools) +(require 'cl-lib) + +;; + +(ert-deftest timeline-tools-test-parse-clocklines-1 () + "Test `timeline-tools-clocklines-in-range’ with simple setup." + (let ((result (with-temp-buffer + (insert "* Task 1\n") + (insert ":LOGBOOK:\n") + (insert "CLOCK: [2018-01-07 Sun 13:15]--[2018-01-07 Sun 14:00] => 0:45\n") + (insert ":END:\n") + (org-mode) ; otherwise parsing won’t work + (timeline-tools-clocklines-in-range 1515279600.0 1515366000.0)))) + (should (equal 1 (length result))) + (should (equal 1 (length (car result)))) + (should (markerp (car (car result)))) + (should (equal (car (cdr (car result))) + (cons 1515327300.0 1515330000.0))))) + +(ert-deftest timeline-tools-test-parse-clocklines-2 () + "Test `timeline-tools-clocklines-in-range’ with multiple clocklines." + (let ((result (with-temp-buffer + (insert "* Task 1\n") + (insert ":LOGBOOK:\n") + (insert "CLOCK: [2018-01-07 Sun 13:15]--[2018-01-07 Sun 14:00] => 0:45\n") + (insert "CLOCK: [2018-01-08 Mon 16:15]--[2018-01-10 Wed 13:10] => 44:55\n") + (insert "CLOCK: [2018-01-10 Wed 10:07]--[2018-01-12 Fri 14:00] => 51:53\n") + (insert ":END:\n") + (org-mode) + (timeline-tools-clocklines-in-range 1515279600.0 1515600000.0)))) + (should (equal 1 (length result))) + (should (equal 4 (length (car result)))) + (should (markerp (car (car result)))) + (should (equal (cdr (car result)) + (list (cons 1515327300.0 1515330000.0) + (cons 1515424500.0 1515586200.0) + (cons 1515575220.0 1515600000.0)))))) + +(ert-deftest timeline-tools-test-parse-clocklines-3 () + "Test `timeline-tools-clocklines-in-range’ with multiple tasks." + (let ((result (with-temp-buffer + (insert " +* Task 1 +:LOGBOOK: +CLOCK: [2018-01-07 Sun 13:15]--[2018-01-07 Sun 14:00] => 0:45 +CLOCK: [2018-01-08 Mon 16:15]--[2018-01-10 Wed 13:10] => 44:55 +CLOCK: [2018-01-10 Wed 10:07]--[2018-01-12 Fri 14:00] => 51:53 +:END: + +* Task 2 +:LOGBOOK: +CLOCK: [2018-01-07 Sun 15:13]--[2018-01-07 Sun 16:17] => 1:04 +CLOCK: [2018-01-08 Mon 16:00]--[2018-01-08 Mon 16:15] => 0:15 +:END: +") + (org-mode) + (timeline-tools-clocklines-in-range 1515279600.0 1515600000.0)))) + (should (equal 2 (length result))) + (should (equal '(4 3) (mapcar #'length result))) + (should (cl-every #'markerp (mapcar #'car result))) + (should (equal (mapcar #'cdr result) + '(((1515327300.0 . 1515330000.0) + (1515424500.0 . 1515586200.0) + (1515575220.0 . 1515600000.0)) + ((1515334380.0 . 1515338220.0) + (1515423600.0 . 1515424500.0))))))) + + +(ert-deftest timeline-tools-test-parse-clocklines-4 () + "Test `timeline-tools-clocklines-in-range’ with extended time range." + (let ((result (with-temp-buffer + (insert " +* Task 1 +:LOGBOOK: +CLOCK: [2018-01-07 Sun 13:15]--[2018-01-07 Sun 14:00] => 0:45 +CLOCK: [2018-01-08 Mon 16:15]--[2018-01-10 Wed 13:10] => 44:55 +CLOCK: [2018-01-10 Wed 10:07]--[2018-01-12 Fri 14:00] => 51:53 +:END: + +* Task 2 +:LOGBOOK: +CLOCK: [2018-01-07 Sun 15:13]--[2018-01-07 Sun 16:17] => 1:04 +CLOCK: [2018-01-08 Mon 16:00]--[2018-01-08 Mon 16:15] => 0:15 +:END: +") + (org-mode) + (timeline-tools-clocklines-in-range 1515279600.0 1515700000.0)))) + (should (equal 2 (length result))) + (should (equal '(4 3) (mapcar #'length result))) + (should (cl-every #'markerp (mapcar #'car result))) + (should (equal (mapcar #'cdr result) + '(((1515327300.0 . 1515330000.0) + (1515424500.0 . 1515586200.0) + (1515575220.0 . 1515700000.0)) + ((1515334380.0 . 1515338220.0) + (1515423600.0 . 1515424500.0))))))) +