[format] converted pass-tests to rackunit
This commit is contained in:
parent
f29609629e
commit
e280ce12a5
|
@ -1,66 +1,42 @@
|
|||
#lang typed/racket/base
|
||||
|
||||
(require trivial/format)
|
||||
|
||||
(module+ test
|
||||
(printf "Testing statically-checked formatting:\n~a\n"
|
||||
(make-string 10 #\=))
|
||||
|
||||
(define-syntax-rule (test-case doc template arg* ...)
|
||||
(require
|
||||
trivial/format
|
||||
typed/rackunit
|
||||
racket/port)
|
||||
|
||||
(define-syntax-rule (test-format: [template arg* ...] expect)
|
||||
(begin
|
||||
(display "TEST ")
|
||||
(displayln doc)
|
||||
(display " [printf] ")
|
||||
(printf: template arg* ...)
|
||||
(newline)
|
||||
(display " [format] ")
|
||||
(display (format: template arg* ...))
|
||||
(newline)
|
||||
(newline)))
|
||||
(check-equal?
|
||||
(format: template arg* ...)
|
||||
expect)
|
||||
(check-equal?
|
||||
(with-output-to-string (lambda () (printf: template arg* ...)))
|
||||
expect)))
|
||||
|
||||
(define H "hello")
|
||||
|
||||
(test-case "without arguments"
|
||||
"success")
|
||||
(test-case "one '~a' arg"
|
||||
"~a" H)
|
||||
(test-case "one '~A' arg"
|
||||
"~A" H)
|
||||
(test-case "one '~b' arg"
|
||||
"~b" 9)
|
||||
(test-case "one '~B' arg"
|
||||
"~B" 9)
|
||||
(test-case "one '~c' arg"
|
||||
"~c" #\Y)
|
||||
(test-case "one '~C' arg"
|
||||
"~C" #\Y)
|
||||
(test-case "one '~e' arg"
|
||||
"~e" H)
|
||||
(test-case "one '~E' arg"
|
||||
"~E" H)
|
||||
(test-case "one '~o' arg"
|
||||
"~o" 9)
|
||||
(test-case "one '~O' arg"
|
||||
"~O" 9)
|
||||
(test-case "one '~s' arg"
|
||||
"~s" H)
|
||||
(test-case "one '~S' arg"
|
||||
"~S" H)
|
||||
(test-case "one '~v' arg"
|
||||
"~v" H)
|
||||
(test-case "one '~V' arg"
|
||||
"~V" H)
|
||||
(test-case "one '~x' arg"
|
||||
"~x" 12)
|
||||
(test-case "one '~X' arg"
|
||||
"~X" 12)
|
||||
(test-case "~<whitespace>"
|
||||
"hello ~ \n world")
|
||||
(test-format: ["success"] "success")
|
||||
(test-format: ["~a" "hi"] "hi")
|
||||
(test-format: ["~A" "hi"] "hi")
|
||||
(test-format: ["~b" 9] "1001")
|
||||
(test-format: ["~B" 9] "1001")
|
||||
(test-format: ["~c" #\Y] "Y")
|
||||
(test-format: ["~C" #\Y] "Y")
|
||||
(test-format: ["~e" "hi"] "\"hi\"")
|
||||
(test-format: ["~E" "hi"] "\"hi\"")
|
||||
(test-format: ["~o" 9] "11")
|
||||
(test-format: ["~O" 9] "11")
|
||||
(test-format: ["~s" "hi"] "\"hi\"")
|
||||
(test-format: ["~S" "hi"] "\"hi\"")
|
||||
(test-format: ["~v" "hi"] "\"hi\"")
|
||||
(test-format: ["~V" "hi"] "\"hi\"")
|
||||
(test-format: ["~x" 12] "c")
|
||||
(test-format: ["~X" 12] "c")
|
||||
(test-format: ["hello ~ \n world"] "hello world")
|
||||
(test-format: ["begin...~n...end"] "begin...\n...end")
|
||||
|
||||
(parameterize ([error-print-width 4])
|
||||
(test-case "two 'display' args, second truncated"
|
||||
"arg1 = ~a, arg2 = ~.a" "hello" "world"))
|
||||
(test-format: ["~a ~.a" "hello" "world"] "hello w..."))
|
||||
|
||||
(test-case "string with newline"
|
||||
"begin... ~n ...end")
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user