summaryrefslogtreecommitdiff
path: root/lib/std/test/fmt.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/test/fmt.myr')
-rw-r--r--lib/std/test/fmt.myr34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/std/test/fmt.myr b/lib/std/test/fmt.myr
new file mode 100644
index 0000000..8de3890
--- /dev/null
+++ b/lib/std/test/fmt.myr
@@ -0,0 +1,34 @@
+use std
+
+const check = {expected, fmt, args : ...
+ var buf : byte[2048]
+ var sl, ap
+
+ ap = std.vastart(&args)
+ sl = std.bfmtv(buf[:], fmt, &ap)
+ if !std.sleq(expected, sl)
+ std.fatal("mismatched fmt: got \"{}\", expected \"{}\"\n", sl, expected)
+ ;;
+}
+
+const main = {
+ check(" abcd", "{w=10}", "abcd")
+ check("00000bdcae", "{p=0,w=10}", "bdcae")
+ check("abcdefghijkl", "{p=0,w=10}", "abcdefghijkl")
+ check("a", "{w=0,p=1}", "a")
+ check(" 10", "{w=10}", 10)
+ check("0000000010", "{p=0,w=10}", 10)
+ check("4294967295", "{p=0,w=10}", -1 castto(uint))
+ check("-000000001", "{p=0,w=10}", -1)
+ check("xxxxxxxx-1", "{p=x,w=10}", -1)
+ check(" -1", "{w=10}", -1)
+ check("100000" , "{3}", 100000)
+ check("foobarbaz", "{}bar{}", "foo", "baz")
+ check("{}barbaz", "{{}}bar{}", "baz")
+ check("{barbaz}", "{{bar{}}}", "baz")
+ check("abcd", "{}", "abcd")
+ check("123", "{}", 123)
+ check("7b", "{x}", 123)
+ check("0x7b", "0x{x}", 123)
+}
+