diff options
| author | 2026-10-15 09:42:25 +0330 | |
|---|---|---|
| committer | 2026-10-15 09:42:25 +0330 | |
| commit | de4da84ca3159ad0ebcf13729716be5f4d7bbc2a (patch) | |
| tree | 216f00007206fdc15dccd3327884b4c0dad94446 /tests | |
| parent | xref: baseline records the prover's writers of ft_ln (bin, kw_for), xub and x... (diff) | |
std: add std.Io (print, println, nl, put_*, put_f, get_c, eof, read, getline) with test, learn example and docs
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/programs/stdio.expected | 8 | ||||
| -rw-r--r-- | tests/programs/stdio.zc | 18 | ||||
| -rwxr-xr-x | tests/test.sh | 1 |
3 files changed, 27 insertions, 0 deletions
diff --git a/tests/programs/stdio.expected b/tests/programs/stdio.expected new file mode 100644 index 0000000..4a7fd8a --- /dev/null +++ b/tests/programs/stdio.expected @@ -0,0 +1,8 @@ +hi -42 2.500000 +line +bytes 0xff s +8 caught 7 +3:abc +3:lon +7 103 +-1 1 diff --git a/tests/programs/stdio.zc b/tests/programs/stdio.zc new file mode 100644 index 0000000..5a79262 --- /dev/null +++ b/tests/programs/stdio.zc @@ -0,0 +1,18 @@ +include rt, std; + +// std.Io: the writers, a capture of them, and the line reader over program input. +fn main() { + std.Io.print("hi "); std.Io.put_n(-42); std.Io.put_c(32); std.Io.put_f(2.5); std.Io.nl(); + std.Io.println("line"); std.Io.put_bs(b"bytes"); std.Io.put_c(32); std.Io.put_hex(255); + std.Io.put_c(32); std.Io.put_s("s"); std.Io.nl(); + let cap = std.capture.start(); + std.Io.print("caught "); std.Io.put_n(7); + std.capture.end(cap); + std.Io.put_n(std.Text.len(cap)); std.Io.put_c(32); std.Io.println(cap); + char[32] buf; int n = std.Io.getline(buf, 32); + std.Io.put_n(n); std.Io.print(":"); std.Io.println(buf); + n = std.Io.getline(buf, 4); std.Io.put_n(n); std.Io.print(":"); std.Io.println(buf); + n = std.Io.read(buf, 32); std.Io.put_n(n); std.Io.put_c(32); std.Io.put_n(buf[0]); std.Io.nl(); + n = std.Io.getline(buf, 32); std.Io.put_n(n); std.Io.put_c(32); std.Io.put_n(std.Io.eof()); std.Io.nl(); + return 0; +} diff --git a/tests/test.sh b/tests/test.sh index 8bf7a9b..7745a66 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -155,6 +155,7 @@ run(){ # $1 = vm command, $2 = label chk "$($vm < tests/programs/use_std.zc)" "42 -7 1" "$l include and the string helpers" chk "$($vm < tests/programs/stdbuf.zc)" "4 1 266 8" "$l stdlib arena and packed byte buffer" chk "$($vm < tests/programs/stdmore.zc)" "$(printf '5 1 0 0 7 copy me 12 -1 0 1 0 1\n9 mixed 123 9 MIXED 123\n11 [padded line]\n42 3 9 10 12 81 9 10 -1 0\n6 1 2 -1 1 0')" "$l stdlib text, byte-string and num helpers" + chk "$( (cat tests/programs/stdio.zc; printf '`abc\nlonger\nxyz') | $vm)" "$(cat tests/programs/stdio.expected)" "$l std.Io writers, capture, getline and read" chk "$(ZC_FILE=tests/data/hi.txt $vm < examples/cli.zc)" "6 h" "$l reading a file named by the environment" chk "$(ZC_ARG_TEST=ok $vm < tests/programs/args.zc)" "1 <eval> <eval> 1 1" "$l argv and envp from the host, argv[0] is <eval> on stdin" chk "$(ZC_ARG_TEST=ok $vm < tests/programs/capture.zc)" "0 |
