diff options
author | rsc <devnull@localhost> | 2004-12-26 23:07:49 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2004-12-26 23:07:49 +0000 |
commit | ae1c9bc4abbd66d522a82fde4cf631c2678f742c (patch) | |
tree | 0d2825ee7c53e18e618d1cb71ab0dd76c76b358c /src/lib9/fmt | |
parent | df121a0027e6dc08abe6fc907c9af2593a263c17 (diff) | |
download | plan9port-ae1c9bc4abbd66d522a82fde4cf631c2678f742c.tar.gz plan9port-ae1c9bc4abbd66d522a82fde4cf631c2678f742c.tar.bz2 plan9port-ae1c9bc4abbd66d522a82fde4cf631c2678f742c.zip |
more tests
Diffstat (limited to 'src/lib9/fmt')
-rw-r--r-- | src/lib9/fmt/test2.c | 9 | ||||
-rw-r--r-- | src/lib9/fmt/test3.c | 52 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/lib9/fmt/test2.c b/src/lib9/fmt/test2.c new file mode 100644 index 00000000..715fcd5b --- /dev/null +++ b/src/lib9/fmt/test2.c @@ -0,0 +1,9 @@ +#include <stdarg.h> +#include <utf.h> +#include <fmt.h> + +int +main(int argc, char **argv) +{ + print("%020.10d\n", 100); +} diff --git a/src/lib9/fmt/test3.c b/src/lib9/fmt/test3.c new file mode 100644 index 00000000..7cda8dcb --- /dev/null +++ b/src/lib9/fmt/test3.c @@ -0,0 +1,52 @@ +#include <u.h> +#include <libc.h> +#include <stdio.h> + +void +test(char *fmt, ...) +{ + va_list arg; + char fmtbuf[100], stdbuf[100]; + + va_start(arg, fmt); + vsnprint(fmtbuf, sizeof fmtbuf, fmt, arg); + va_end(arg); + + va_start(arg, fmt); + vsnprint(stdbuf, sizeof stdbuf, fmt, arg); + va_end(arg); + + if(strcmp(fmtbuf, stdbuf) != 0) + print("fmt %s: fmt=\"%s\" std=\"%s\"\n", fmt, fmtbuf, stdbuf); + + print("fmt %s: %s\n", fmt, fmtbuf); +} + + +int +main(int argc, char *argv[]) +{ + test("%f", 3.14159); + test("%f", 3.14159e10); + test("%f", 3.14159e-10); + + test("%e", 3.14159); + test("%e", 3.14159e10); + test("%e", 3.14159e-10); + + test("%g", 3.14159); + test("%g", 3.14159e10); + test("%g", 3.14159e-10); + + test("%g", 2e25); + test("%.18g", 2e25); + + test("%2.18g", 1.0); + test("%2.18f", 1.0); + test("%f", 3.1415927/4); + + test("%20.10d", 12345); + test("%0.10d", 12345); + + return 0; +} |