-
Notifications
You must be signed in to change notification settings - Fork 1
/
core-test.ss
43 lines (32 loc) · 1.36 KB
/
core-test.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#lang scheme
(require "test-base.ss")
(require net/base64
"core.ss")
; Helpers ----------------------------------------
(define-check (check-parser parser input output)
(check-equal? (parser (make-raw-result (string->bytes/utf-8 (format "OK,~a" input)))) output))
; Tests ------------------------------------------
(define/provide-test-suite core-tests
(test-case "parse-string"
(check-parser parse-string "abc" "abc")
(check-parser parse-string "" "")
(check-exn
exn:fail?
(lambda ()
(parse-string (make-raw-result "BAD")))))
(test-case "parse-string-list"
(check-parser parse-string-list "a,b,c" (list "a" "b" "c"))
(check-parser parse-string-list "a,b," (list "a" "b" ""))
(check-parser parse-string-list "" (list ""))
(check-parser parse-string-list "a\\,b,c" (list "a,b" "c"))
(check-parser parse-string-list "a\\\\b,c" (list "a\\b" "c"))
(check-parser parse-string-list "a\\.b,c" (list "a\\.b" "c")))
(test-case "parse-number"
(check-parser parse-number "1.23" 1.23)
(check-parser parse-number "-1.23" -1.23))
(test-case "parse-boolean"
(check-parser parse-boolean "true" #t)
(check-parser parse-boolean "false" #f))
(test-case "parse-base64"
(check-equal? (parse-base64 (make-raw-result (bytes-append #"OK," (base64-encode #"abcde"))))
#"abcde")))