Port ref/hare/ascii/string.ha strlower/strupper as the allocating entry points: byte-wise ASCII case fold, equivalent to Hare's rune fold since case-folding only touches bytes <0x80 and every UTF-8 multibyte byte is >=0x80 (passes through unchanged, length-preserving). nomem arises only from the allocation's `?`. strlower_buf/strupper_buf are deferred: ww has no nomem-value form or capacity-bounded static-append to express Hare's too-small-buffer path (#230); restore the two-tier delegation when those land. Divergence (rule 7): the empty-input fast path returns a nil/0 str because ww's alloc([], 0) routes through nomem, whereas Hare allocs a zero-length buffer and zero-loops; documented at the bypass site. Test vectors mirror Hare's @test (ABC/abc/[[[/こ/empty/aB1z). Adds lib/ascii/asciitest.ww + test/wcc/904_ascii_run.c (registered in the Makefile TESTS list and a build rule). Regenerates the ascii-embedding selfhost combined.ww amalgams (#110 freshness); the wwdump amalgam also reorders the ascii block after strings to satisfy the new import edge.
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
/*
|
|
* 904_ascii_run — execute the lib/ascii @test fixture under the
|
|
* C-side `ww run` driver and assert exit 0.
|
|
*
|
|
* Same thin-wrapper shape as 967_bytes_run / 968_utf8_run:
|
|
* asciitest.ww carries its own `export fn main()` that drives the
|
|
* @test fns and signals which case failed via the exit code.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc = system(cmd);
|
|
if (rc == -1) return -1;
|
|
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[1024];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
|
|
const char *src = "lib/ascii/asciitest.ww";
|
|
char path[1024], cmd[2048];
|
|
snprintf(path, sizeof path, "%s/%s", cwd, src);
|
|
snprintf(cmd, sizeof cmd, "%s/ww run %s", bin, path);
|
|
int rc = runwait(cmd);
|
|
if (rc != 0) {
|
|
fprintf(stderr, "ascii_run FAIL: %s exited %d\n", src, rc);
|
|
return 1;
|
|
}
|
|
printf("ascii_run: %s ok\n", src);
|
|
return 0;
|
|
}
|