Start testing member-record, fix current month inference.

This commit is contained in:
Dominik Pantůček 2023-03-18 15:54:25 +01:00
parent 023befa8f8
commit 798cfe318c
4 changed files with 35 additions and 4 deletions

View file

@ -30,6 +30,7 @@
member-record
(
print-member-record-info
member-record-tests!
)
(import scheme
@ -38,8 +39,10 @@
(chicken sort)
dictionary
period
)
testing
month)
;; Prints human-readable information
(define (print-member-record-info mr)
(let* ((id (dict-ref mr 'id))
(aliases (dict-ref mr 'symlinks))
@ -65,4 +68,30 @@
v))
(loop (cdr sinfo)))))))
;; Returns key from the top-level (members-base) record if it exists,
;; queries the 'info key otherwise. Optional default argument works
;; like with dict-ref.
(define (mr-ref mr key . dfl)
(if (dict-has-key? mr key)
(dict-ref mr key)
(if (null? dfl)
(dict-ref (dict-ref mr 'info) key)
(dict-ref (dict-ref mr 'info) key (car dfl)))))
;; Returns true if the member record represents destroyed member. The
;; *current-month* is a global parameter from period module.
(define (member-destroyed? mr)
(let ((destroyed (mr-ref mr 'destroyed #f)))
(and destroyed
(month<? (string->month destroyed)
(*current-month*)))))
;; Performs module self-tests.
(define (member-record-tests!)
(run-tests
member-record
(test-true member-destroyed?
(member-destroyed? '((info . ((destroyed . "2010-05"))))))
))
)