lib/encoding/hex+test: Hare port (encode / decode / sizes)

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.
This commit is contained in:
2026-05-17 07:07:57 +09:00
parent bd4ea9f93e
commit a8561c03a0
4 changed files with 364 additions and 9 deletions

View File

@@ -254,6 +254,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
$(BIN)/test_shlex_run $(BIN)/test_getenv_run $(BIN)/test_dirs_run \
$(BIN)/test_stat_run $(BIN)/test_time_run \
$(BIN)/test_intdiv_signed \
$(BIN)/test_hex_run \
$(BIN)/test_memio_run $(BIN)/test_temp_run $(BIN)/test_getopt_run \
$(BIN)/test_base32_run $(BIN)/test_base64_run \
$(BIN)/test_adler32_run $(BIN)/test_crc16_run \
@@ -593,6 +594,10 @@ $(BIN)/test_intdiv_signed: test/wcc/978_intdiv_signed.c $(BIN)/ww $(BIN)/w6c \
$(BIN)/w6a $(BIN)/w6l $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_hex_run: test/wcc/979_hex_run.c $(BIN)/ww $(BIN)/w6c \
$(BIN)/w6a $(BIN)/w6l $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_memio_run: test/wcc/980_memio_run.c $(BIN)/ww $(BIN)/w6c \
$(BIN)/w6a $(BIN)/w6l $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<