Port ref/hare/strconv/decimal.ha (~202 LOC Hare) → 314 LOC lib/strconv/decimal.ww — decimal struct + 11 fns (trim, decimal_shift, leftshift, leftshift_newdigits, rightshift, round, decimal_round, helpers). 1:1 mechanical Hare-fidelity with 8 documented spelling-divergences. Shared engine for stof (fold-4) + ftos (fold-5). Built atop 5 wwstage cgen prereqs (#131/#133-expanded/#134/#135/#138) that closed gate-blind silent miscompiles surfaced by the port. Test 922_decimal_run + lib/strconv/test/decimaltest.ww (6 @test fns covering all 11 impl fns).
58 lines
1.7 KiB
C
58 lines
1.7 KiB
C
/*
|
|
* 922_decimal_run — execute the lib/strconv/test/decimaltest fixture
|
|
* under the C-side `ww run` driver and assert exit 0.
|
|
*
|
|
* Same thin-wrapper shape as 967_bytes_run / 968_utf8_run / 979_hex_run:
|
|
* decimaltest.ww carries its own `export fn main()` that drives the
|
|
* @test fns and signals which case failed via the exit code (signalled
|
|
* + 10, so cases 1..6 → exit 11..16).
|
|
*
|
|
* The test fixture lives in lib/strconv/test/ (not lib/strconv/) so
|
|
* `import strconv` resolves to the lib/strconv DIRECTORY rather than
|
|
* shadowing on the strconv.ww FILE — same-dir resolution would pull
|
|
* in only strconv.ww and miss decimal.ww + stof_data.ww. From the
|
|
* test/ subdir, the search-path lookup falls through srcd and reaches
|
|
* the libdir's directory hit, expanding the full strconv package.
|
|
*/
|
|
#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/strconv/test/decimaltest.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, "decimal_run FAIL: %s exited %d\n", src, rc);
|
|
return 1;
|
|
}
|
|
printf("decimal_run: %s ok\n", src);
|
|
return 0;
|
|
}
|