Files
ww/test/wcc/data/r780_fmt_mods/case.ww
Hojun-Cho d456263f7e test/wcc/data: grow the declarative compiler corpus to 1,224 fixtures
The r-prefixed waves absorb the runtime, reject, and byte-compare rows
of the migrated native carriers; each fixture is one directory with one
case.ww and a //ww:error, //ww:compile, //ww:run, or //ww:run-exit
directive covering both frontends.
2026-08-07 23:21:04 +09:00

76 lines
1.8 KiB
Plaintext

//ww:run
package main;
import os;
import fmt;
import io;
import temp;
fn fresh() i32 = {
let fd: i32 = -1;
let path: str;
match (temp.named(&fd, &path, "/tmp", temp.mode.RDWR, 0o600: i32)) {
case void => void;
case let e: os.oserror => return -1;
};
if (os.remove(path) != 0) { os.close(fd); return -1; };
return fd;
};
fn expect(fd: i32, nw: size, want: str) bool = {
if (os.lseek(fd, 0i64, os.whence.SET) != 0i64) {
os.close(fd);
return false;
};
let buf: [16]u8;
let n: i64 = os.read(fd, &buf[0], 16u64);
let closed: i32 = os.close(fd);
if (closed != 0 || n != want.len: i64 || nw != want.len: size) {
return false;
};
let i: i32 = 0;
for (i < want.len) {
if (buf[i] != want[i]) { return false; };
i += 1;
};
return true;
};
export fn main() i32 = {
let fd: i32 = fresh();
if (fd < 0) { return 1; };
match (fmt.fprintf(fd: io.file, "{:5}", 42i64)) {
case let n: size => { if (!expect(fd, n, " 42")) { return 2; }; };
case io.error => { os.close(fd); return 3; };
};
fd = fresh();
if (fd < 0) { return 4; };
match (fmt.fprintf(fd: io.file, "{:.3}", "hello")) {
case let n: size => { if (!expect(fd, n, "hel")) { return 5; }; };
case io.error => { os.close(fd); return 6; };
};
fd = fresh();
if (fd < 0) { return 7; };
match (fmt.fprintf(fd: io.file, "{:x}", 255i64)) {
case let n: size => { if (!expect(fd, n, "ff")) { return 8; }; };
case io.error => { os.close(fd); return 9; };
};
fd = fresh();
if (fd < 0) { return 10; };
match (fmt.fprintf(fd: io.file, "{:+}", 7i64)) {
case let n: size => { if (!expect(fd, n, "+7")) { return 11; }; };
case io.error => { os.close(fd); return 12; };
};
fd = fresh();
if (fd < 0) { return 13; };
match (fmt.fprintf(fd: io.file, "{:_05}", 42i64)) {
case let n: size => { if (!expect(fd, n, "00042")) { return 14; }; };
case io.error => { os.close(fd); return 15; };
};
return 0;
};