Add more test cases for insert
This commit is contained in:
parent
fe9f2b494f
commit
bcff5690fc
|
@ -917,7 +917,8 @@ Return nil if BACKEND contains no records.")
|
|||
|
||||
;; [[file:chronometrist.org::*replace-last][replace-last:1]]
|
||||
(cl-defgeneric chronometrist-replace-last (backend plist)
|
||||
"Replace last record in BACKEND with PLIST.")
|
||||
"Replace last record in BACKEND with PLIST.
|
||||
Return non-nil if successful.")
|
||||
|
||||
(cl-defmethod chronometrist-replace-last :before ((_backend t) plist &key &allow-other-keys)
|
||||
(unless (cl-typep plist 'chronometrist-plist)
|
||||
|
@ -1559,7 +1560,8 @@ This is meant to be run in `chronometrist-file' when using an s-expression backe
|
|||
(chronometrist-sexp-in-file (chronometrist-backend-file backend)
|
||||
(goto-char (chronometrist-remove-last backend))
|
||||
(funcall chronometrist-sexp-pretty-print-function plist (current-buffer))
|
||||
(save-buffer)))
|
||||
(save-buffer)
|
||||
t))
|
||||
;; replace-last:1 ends here
|
||||
|
||||
;; [[file:chronometrist.org::*count-records][count-records:1]]
|
||||
|
@ -1852,7 +1854,8 @@ Return value is either a list in the form
|
|||
(chronometrist-sexp-in-file (chronometrist-backend-file backend)
|
||||
(chronometrist-remove-last backend :save nil)
|
||||
(chronometrist-insert backend plist :save nil)
|
||||
(save-buffer)))
|
||||
(save-buffer)
|
||||
t))
|
||||
;; replace-last:1 ends here
|
||||
|
||||
;; [[file:chronometrist.org::*remove-prefix][remove-prefix:1]]
|
||||
|
|
|
@ -1545,7 +1545,8 @@ Return nil if BACKEND contains no records.")
|
|||
***** replace-last :generic:function:
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(cl-defgeneric chronometrist-replace-last (backend plist)
|
||||
"Replace last record in BACKEND with PLIST.")
|
||||
"Replace last record in BACKEND with PLIST.
|
||||
Return non-nil if successful.")
|
||||
|
||||
(cl-defmethod chronometrist-replace-last :before ((_backend t) plist &key &allow-other-keys)
|
||||
(unless (cl-typep plist 'chronometrist-plist)
|
||||
|
@ -2446,7 +2447,8 @@ This is meant to be run in `chronometrist-file' when using an s-expression backe
|
|||
(chronometrist-sexp-in-file (chronometrist-backend-file backend)
|
||||
(goto-char (chronometrist-remove-last backend))
|
||||
(funcall chronometrist-sexp-pretty-print-function plist (current-buffer))
|
||||
(save-buffer)))
|
||||
(save-buffer)
|
||||
t))
|
||||
#+END_SRC
|
||||
|
||||
***** count-records :reader:method:
|
||||
|
@ -2809,7 +2811,8 @@ We apply the same hack as in the [[<<hack-note-plist-group-insert>>][insert]] me
|
|||
(chronometrist-sexp-in-file (chronometrist-backend-file backend)
|
||||
(chronometrist-remove-last backend :save nil)
|
||||
(chronometrist-insert backend plist :save nil)
|
||||
(save-buffer)))
|
||||
(save-buffer)
|
||||
t))
|
||||
#+END_SRC
|
||||
|
||||
***** count-records :reader:method:NOEXPORT:
|
||||
|
|
|
@ -456,20 +456,21 @@ The order of these tests is important - the last test for each case is one which
|
|||
#+BEGIN_SRC emacs-lisp
|
||||
(chronometrist-ert-deftest insert b
|
||||
;; (message "insert test - hash-table-count %s" (hash-table-count (chronometrist-backend-hash-table b)))
|
||||
(let ((active-record (list :name "Test" :start (chronometrist-format-time-iso8601)))
|
||||
(plist-1 (cl-first chronometrist-test-records))
|
||||
(plist-2 (cl-second chronometrist-test-records))
|
||||
(today-ts (chronometrist-date-ts)))
|
||||
(let* ((plist1 (list :name "Test" :start (chronometrist-format-time-iso8601)))
|
||||
(plist2 (append plist1 (list :stop (chronometrist-format-time-iso8601)))))
|
||||
;; * file does not exist *
|
||||
(should-error (chronometrist-insert b plist-1))
|
||||
(should-error (chronometrist-insert b plist1))
|
||||
(should (chronometrist-create-file b))
|
||||
;; * file exists but has no records *
|
||||
(should (chronometrist-insert b active-record))
|
||||
(should (equal (progn (chronometrist-reset-backend b) (chronometrist-latest-date-records b))
|
||||
(list (chronometrist-date-iso) active-record)))
|
||||
|
||||
(should (chronometrist-insert b plist1))
|
||||
(should (equal (progn (chronometrist-reset-backend b)
|
||||
(chronometrist-latest-date-records b))
|
||||
(list (chronometrist-date-iso) plist1)))
|
||||
;; * backend has a single active record *
|
||||
|
||||
(should (chronometrist-replace-last b plist2))
|
||||
(should (equal (progn (chronometrist-reset-backend b)
|
||||
(chronometrist-latest-date-records b))
|
||||
(list (chronometrist-date-iso) plist2)))
|
||||
;; * backend has a single inactive record *
|
||||
;; * backend has a single active day-crossing record *
|
||||
;; * backend has a single inactive day-crossing record *
|
||||
|
|
Reference in New Issue