diff --git a/brmsaptool.scm b/brmsaptool.scm index bba5cd7..5acab62 100644 --- a/brmsaptool.scm +++ b/brmsaptool.scm @@ -39,4 +39,8 @@ (dictionary-tests!) (month-tests!) (period-tests!) +(member-file-tests!) +(newline) + +(load-member-file "members/joe") (newline) diff --git a/member-file.scm b/member-file.scm index eaab132..6966cd5 100644 --- a/member-file.scm +++ b/member-file.scm @@ -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)) @@ -111,17 +118,19 @@ "2015-01")) ;; Processes all lines and returns a dictionary representing given - ;; member. + ;; 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") + )) + ) diff --git a/period.scm b/period.scm index a6848a7..b134968 100644 --- a/period.scm +++ b/period.scm @@ -125,6 +125,7 @@ (map period->string ps) ", ")) + ;; Performs self-tests of the period module. (define (period-tests!) (run-tests period