aboutsummaryrefslogtreecommitdiffstats
path: root/format-test.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-01-09 08:40:09 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-01-09 08:40:09 -0800
commit3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927 (patch)
treecef8ca0e77c40a70daaca40af25572437d563105 /format-test.csc
downloadchromatopelma-3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927.tar.zst
Initial commit.
Not sure if everything here will be needed eventually, but we have a working bytecode interpreter. Next I will write the linker, then the core compiler, and finish with the macro expander.
Diffstat (limited to 'format-test.csc')
-rw-r--r--format-test.csc47
1 files changed, 47 insertions, 0 deletions
diff --git a/format-test.csc b/format-test.csc
new file mode 100644
index 0000000..b7b2c99
--- /dev/null
+++ b/format-test.csc
@@ -0,0 +1,47 @@
+(import (scheme base)
+ (only (csc strings) str-quote)
+ (only (csc testing) define-test errorf subtest)
+ (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)))