Files
ww/test/wcc/data/r791_io_handle/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

117 lines
3.4 KiB
Plaintext

//ww:run
package main;
import io;
import memio;
import os;
import temp;
fn myseek(s: io.stream, off: io.off, w: io.whence) (io.off | io.error) = {
return off + 100: io.off;
};
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;
};
export fn main() i32 = {
let fd: i32 = fresh();
if (fd < 0) { return 1; };
let h: io.file = fd;
let data: [3]u8;
data[0] = 65u8; data[1] = 66u8; data[2] = 67u8;
match (io.write(h, data[0:3])) {
case let n: size => { if (n != 3: size) { io.close(h); return 2; }; };
case let e: io.error => { io.close(h); return 3; };
};
match (io.seek(h, 0: io.off, io.whence.SET)) {
case let o: io.off => { if (o != 0: io.off) { io.close(h); return 4; }; };
case let e: io.error => { io.close(h); return 5; };
};
let rb: [3]u8;
match (io.read(h, rb[0:3])) {
case let n: size => { if (n != 3: size) { io.close(h); return 6; }; };
case let z: io.eof => { io.close(h); return 7; };
case let e: io.error => { io.close(h); return 8; };
};
if (rb[0] != 65u8 || rb[1] != 66u8 || rb[2] != 67u8) { io.close(h); return 9; };
match (io.seek(h, 0: io.off, io.whence.END)) {
case let o: io.off => { if (o != 3: io.off) { io.close(h); return 10; }; };
case let e: io.error => { io.close(h); return 11; };
};
match (io.tell(h)) {
case let o: io.off => { if (o != 3: io.off) { io.close(h); return 12; }; };
case let e: io.error => { io.close(h); return 13; };
};
match (io.close(h)) {
case void => void;
case let e: io.error => return 14;
};
let sbuf: [8]u8;
let st: memio.stream = memio.fixed(sbuf[0:8]);
let s: io.stream = &st.vt;
let sdata: [3]u8;
sdata[0] = 88u8; sdata[1] = 89u8; sdata[2] = 90u8;
match (io.write(s, sdata[0:3])) {
case let n: size => { if (n != 3: size) { return 15; }; };
case let e: io.error => return 16;
};
if (sbuf[0] != 88u8 || sbuf[1] != 89u8 || sbuf[2] != 90u8) { return 17; };
let st2: memio.stream = memio.fixed(sbuf[0:8]);
let s2: io.stream = &st2.vt;
let srb: [3]u8;
match (io.read(s2, srb[0:3])) {
case let n: size => { if (n != 3: size) { return 18; }; };
case let z: io.eof => return 19;
case let e: io.error => return 20;
};
if (srb[0] != 88u8 || srb[1] != 89u8 || srb[2] != 90u8) { return 21; };
let emptyvt: io.vtable;
let noseek: io.stream = &emptyvt;
match (io.seek(noseek, 0: io.off, io.whence.SET)) {
case let o: io.off => return 22;
case let e: io.error => void;
};
let seekvt: io.vtable;
seekvt.seeker = (&myseek): *io.seeker;
let seeker: io.stream = &seekvt;
match (io.seek(seeker, 5: io.off, io.whence.SET)) {
case let o: io.off => { if (o != 105: io.off) { return 23; }; };
case let e: io.error => return 24;
};
match (io.tell(seeker)) {
case let o: io.off => { if (o != 100: io.off) { return 25; }; };
case let e: io.error => return 26;
};
let bad: io.file = -1i32;
match (io.write(bad, data[0:3])) {
case let n: size => return 27;
case let e: io.error => void;
};
match (io.read(bad, data[0:3])) {
case let n: size => return 28;
case let z: io.eof => return 29;
case let e: io.error => void;
};
match (io.seek(bad, 0: io.off, io.whence.SET)) {
case let o: io.off => return 30;
case let e: io.error => void;
};
match (io.close(bad)) {
case void => return 31;
case let e: io.error => void;
};
return 0;
};