shithub: mc

ref: cf94e8f3c050f869d11a985f7ac4a4d9a477a9e4
dir: /libstd/test/fmt.myr/

View raw version
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 = {
	/* FIXME: make these equivalents tested.
	check("      abcd", "%10s", "abcd")
	check("00000bdcae", "%010s", "bdcae")
	check("abcdefghijkl", "%010s", "abcdefghijkl")
	check("a", "%01s", "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)
}