aboutsummaryrefslogtreecommitdiffstats
path: root/format-test.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-01-09 16:20:43 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-01-09 16:20:43 -0800
commitf06966df463bdba5912b999bcb6ab0badb83a561 (patch)
tree325be54ab153da135db02498feafcea9cc3ea1aa /format-test.csc
parentAdd some magic to detect symbols. (diff)
downloadchromatopelma-f06966df463bdba5912b999bcb6ab0badb83a561.tar.zst
Redo the testing framework.
We can lean more on the power of scheme to make the testing framework a little less verbose.
Diffstat (limited to 'format-test.csc')
-rw-r--r--format-test.csc61
1 files changed, 19 insertions, 42 deletions
diff --git a/format-test.csc b/format-test.csc
index b7b2c99..6efaa87 100644
--- a/format-test.csc
+++ b/format-test.csc
@@ -1,47 +1,24 @@
(import (scheme base)
(only (csc strings) str-quote)
- (only (csc testing) define-test errorf subtest)
+ (only (csc testing) assert-equal test)
(csc format))
-(define-test (test-vsprintf t)
- (define-record-type <test-case>
- (test-case name fmt args want)
- test-case?
- (name name)
- (fmt fmt)
- (args args)
- (want want))
- (let ((tests (list
- (test-case
- "single-string"
- "test-string"
- '()
- "test-string")
- (test-case
- "list"
- "{}"
- '((1 2 3))
- "(1 2 3)")
- (test-case
- "complex"
- "this {} is {} a {} test"
- '((1 2 3) 1 "bbb")
- "this (1 2 3) is 1 a bbb test")
- (test-case
- "escape open"
- "{{"
- '()
- "{")
- (test-case
- "escape close"
- "}}"
- '()
- "}"))))
- (for-each
- (lambda (tc)
- (subtest t (name tc)
- (let ((got (vsprintf (fmt tc) (args tc))))
- (unless (equal? got (want tc))
- (errorf t "(vsprintf {} {}) = {}, want {}." (str-quote fmt) (args tc) got (want tc))))))
- tests)))
+(test sprintf-single-string
+ (assert-equal "test-string" (sprintf "test-string")))
+
+
+(test sprintf-list
+ (assert-equal "(1 2 3)" (sprintf "{}" '(1 2 3))))
+
+
+(test sprintf-complex
+ (assert-equal "this (1 2 3) is 1 a bbb test" (sprintf "this {} is {} a {} test" '(1 2 3) 1 "bbb")))
+
+
+(test sprintf-escape-open
+ (assert-equal "{" (sprintf "{{")))
+
+
+(test sprintf-escape-close
+ (assert-equal "}" (sprintf "}}")))