Start updating the member-file module and add tests.
This commit is contained in:
parent
1b00b2a020
commit
f4e3419ad3
3 changed files with 30 additions and 6 deletions
|
@ -39,4 +39,8 @@
|
|||
(dictionary-tests!)
|
||||
(month-tests!)
|
||||
(period-tests!)
|
||||
(member-file-tests!)
|
||||
(newline)
|
||||
|
||||
(load-member-file "members/joe")
|
||||
(newline)
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
member-file
|
||||
(
|
||||
load-member-file
|
||||
member-file-tests!
|
||||
)
|
||||
|
||||
(import scheme
|
||||
|
@ -35,10 +36,16 @@
|
|||
(chicken io)
|
||||
dictionary
|
||||
month
|
||||
period)
|
||||
period
|
||||
testing)
|
||||
|
||||
;; Specification of known keys for various types of parsing
|
||||
(define known-keys '(nick mail phone name born joined))
|
||||
(define start/stop-keys '(student suspend))
|
||||
(define multi-keys '(card desfire credit))
|
||||
|
||||
;; Member File Parser: remove comments from line and return the result
|
||||
(define (mfp:line:remove-comments l)
|
||||
(define (line-remove-comments l)
|
||||
(let ((si (substring-index "#" l)))
|
||||
(if si
|
||||
(if (= si 0)
|
||||
|
@ -49,7 +56,7 @@
|
|||
;; Parses given key-value line. Key is up to first space, value is the
|
||||
;; rest of the line. If the line doesn't contain anything, returns #f.
|
||||
(define (parse-member-line l)
|
||||
(let ((sp (string-split (mfp:line:remove-comments l) " ")))
|
||||
(let ((sp (string-split (line-remove-comments l) " ")))
|
||||
(and sp
|
||||
(not (null? sp))
|
||||
(list (string->symbol (car sp))
|
||||
|
@ -114,14 +121,16 @@
|
|||
;; member.
|
||||
(define (parse-member-lines ls)
|
||||
(let loop ((ls ls)
|
||||
(r (make-default-member-info)))
|
||||
(r (make-default-member-info))
|
||||
(line-number 1))
|
||||
(if (null? ls)
|
||||
(convert-member-keys:markers->periods r 'suspend 'student)
|
||||
(let ((p (parse-member-line (car ls))))
|
||||
(loop (cdr ls)
|
||||
(if p
|
||||
(apply process-member-line r p)
|
||||
r))))))
|
||||
r)
|
||||
(+ line-number 1))))))
|
||||
|
||||
;; Loads lines from given file and parses them.
|
||||
(define (load-member-file ffn)
|
||||
|
@ -131,4 +140,14 @@
|
|||
(display ".")
|
||||
md))
|
||||
|
||||
;; Performs self-tests of the member-file module.
|
||||
(define (member-file-tests!)
|
||||
(run-tests
|
||||
member-file
|
||||
(test-equal? line-remove-comments (line-remove-comments "# all comment") "")
|
||||
(test-equal? line-remove-comments (line-remove-comments "") "")
|
||||
(test-equal? line-remove-comments (line-remove-comments "test # comment") "test ")
|
||||
(test-equal? line-remove-comments (line-remove-comments "test") "test")
|
||||
))
|
||||
|
||||
)
|
||||
|
|
|
@ -125,6 +125,7 @@
|
|||
(map period->string ps)
|
||||
", "))
|
||||
|
||||
;; Performs self-tests of the period module.
|
||||
(define (period-tests!)
|
||||
(run-tests
|
||||
period
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue