Files
ww/lib/ascii/ascii_test.ww
Hojun-Cho aadc6618f0 lib: banner purge + WHY-only comment sweep (rule 8)
Every // ---- section banner dies (132 -> 0): names carry the WHAT.
Narration deleted (filename restatements, run-with lines, what-the-
next-line-does); every ref/hare cite, task cite, divergence, ABI/
layout contract, and ownership qualifier kept (borrowed-view lines
restored where the sweep over-cut). Comment-only proven: all 442
walk-workdir .s and 32 import-probe .s byte-identical before/after;
libbyteid 56-roster all-ID.
2026-08-08 21:10:18 +09:00

67 lines
2.2 KiB
Plaintext

// A failing row aborts via the assert/abort builtin (task #5 @test
// conversion).
//
// Vectors mirror Hare's @test fn strcasecmp in ref/hare/ascii/string.ha.
package ascii_test;
import ascii;
// checkfold — one table row: strlower(in) == lo and strupper(in) == up.
fn checkfold(in: str, lo: str, up: str) void = {
match (ascii.strlower(in)) {
case let got: str => { assert(!(got != lo)); };
case nomem => { abort(); };
};
match (ascii.strupper(in)) {
case let got: str => { assert(!(got != up)); };
case nomem => { abort(); };
};
};
// ref/hare/ascii/string.ha:70 case-fold vectors. The こ row pins that a
// UTF-8 multibyte sequence (all bytes >=0x80) passes through unchanged.
@test fn strfold_cases() void = {
checkfold("ABC", "abc", "ABC");
checkfold("abc", "abc", "ABC");
checkfold("[[[", "[[[", "[[[");
checkfold("こ", "こ", "こ");
checkfold("", "", "");
checkfold("aB1z", "ab1z", "AB1Z");
};
// checkbuf — strlower_buf/strupper_buf into an exactly-sized buf.
fn checkbuf(in: str, lo: str, up: str) void = {
let lstore: [16]u8; let lbuf: []u8 = lstore[0:16]; lbuf.len = 0;
match (ascii.strlower_buf(in, lbuf)) {
case let got: str => { assert(!(got != lo)); };
case nomem => { abort(); };
};
let ustore: [16]u8; let ubuf: []u8 = ustore[0:16]; ubuf.len = 0;
match (ascii.strupper_buf(in, ubuf)) {
case let got: str => { assert(!(got != up)); };
case nomem => { abort(); };
};
};
@test fn strfold_buf_cases() void = {
checkbuf("ABC", "abc", "ABC");
checkbuf("aB1z", "ab1z", "AB1Z");
checkbuf("", "", "");
// non-ASCII pins UTF-8 multibyte passthrough through the _buf path
// directly (all bytes >=0x80, untouched by the byte-wise fold).
checkbuf("こ", "こ", "こ");
// cap exactly == s.len must succeed — pins the `<` boundary in the
// buf.cap check (a `<=` off-by-one would wrongly return nomem here).
let exact: [3]u8; let ebuf: []u8 = exact[0:3]; ebuf.len = 0;
match (ascii.strlower_buf("ABC", ebuf)) {
case let got: str => { assert(!(got != "abc")); };
case nomem => { abort(); };
};
let small: [2]u8; let sbuf: []u8 = small[0:2]; sbuf.len = 0;
match (ascii.strlower_buf("ABC", sbuf)) {
case let got: str => { abort(); };
case nomem => void;
};
};