Replaces the 19-line placeholder. Five entrypoints per
ref/hare/encoding/hex/hex.ha + README:13:
- invalid (!void) — mirrors errors::invalid (hex.ha:175 decodestr).
base32's !i32 is a pre-existing in-tree divergence; hex doesn't
carry it forward.
- encodedsize(n) = n*2 — derived from hex.ha:46-55 encode_writer
lowercase 2-chars-per-byte.
- decodedsize(n) = n/2 — inverse; hex.ha:158.
- encode(dst, src) i32 — lowercase output per README:13 + hex.ha:91.
- decode(dst, src) (i32 | invalid) — accepts lower / upper / mixed;
returns invalid on odd length (hex.ha:154) or non-hex char
(hex.ha:161-163).
Deferred (cite-and-defer, same pattern as base32/base64):
- newencoder / newdecoder — Hare's io::handle stream API; ww has no
io::handle integration yet.
- encodestr / decodestr — allocator-returning sum-result; needs
os.alloc-backed memio dynamic, not wired.
- dump — hexdump-with-ASCII view; needs io::handle + fmt::fprintf
into a write sink.
Test: lib/encoding/hex/hextest.ww 13 rows — sizes, encode_basic
(Hare's CAFEBABEDEADF00D verbatim), encode_zero / encode_ff /
encode_empty (nibble corners + sign-extend + table off-by-one),
decode_{lower,upper,mixed} (case acceptance), decode_{empty,
odd_length,bad_char,bad_char_mid} (error paths), roundtrip_all_bytes
(0..255 full nibble+shift family — Class B exerciser).
Driver test/wcc/979_hex_run.c slotted between 978_intdiv_signed and
980_memio_run.
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
/*
|
|
* 979_hex_run — execute the lib/encoding/hex @test fixture under the
|
|
* C-side `ww run` driver and assert exit 0.
|
|
*
|
|
* Same thin-wrapper shape as 983_base32_run / 977_time_run:
|
|
* hextest.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/encoding/hex/hextest.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, "hex_run FAIL: %s exited %d\n", src, rc);
|
|
return 1;
|
|
}
|
|
printf("hex_run: %s ok\n", src);
|
|
return 0;
|
|
}
|