F3.2: assert Diag (token,index) for all cli.parse error cases

Extend example 0717 to pin the offending token VIEW and its args index
for every failure the parser's Diag populates: unknown-command,
unknown-group, too-few-args, missing-value, value-eats-flag, and the
missing-required index. Closes the test-coverage gap flagged in review;
cli.sx parser logic unchanged.
This commit is contained in:
agra
2026-06-04 07:38:57 +03:00
parent 17b437ecfb
commit d1e5f10039
2 changed files with 47 additions and 3 deletions

View File

@@ -121,16 +121,49 @@ main :: () -> ! {
report("err-value-eats-flag", raises(a_value_eats, cmds, error.MissingValue));
report("err-missing-req", raises(a_missing_req, cmds, error.MissingRequired));
// ── 8. Diag names the offending token on the error path ─────────
// ── 8. Diag pins the offending (token, index) for EVERY error case
// Each failure records the exact offending token (a VIEW into `args`,
// except a missing-required names the matched spec's flag name) plus
// its `args` index, so a caller can report which token failed. An
// unknown (group, command) PAIR — group wrong OR command wrong — pins
// the COMMAND token at index 1, since the pair as a whole is what
// failed to match; a missing-required uses index -1 (the token is a
// flag name, not an `args` slot).
de : Diag = .{};
_, ue := parse(a_unknown_flag, cmds, @de);
report("diag-flag-tag", ue == error.UnknownFlag);
report("diag-flag-token", de.token == "--nope" and de.index == 4);
report("diag-flag-tag", ue == error.UnknownFlag);
report("diag-flag-token", de.token == "--nope" and de.index == 4);
dc : Diag = .{};
_, ce := parse(a_unknown_cmd, cmds, @dc);
report("diag-cmd-tag", ce == error.UnknownCommand);
report("diag-cmd-token", dc.token == "deploy" and dc.index == 1);
dg : Diag = .{};
_, ge := parse(a_unknown_group, cmds, @dg);
report("diag-group-tag", ge == error.UnknownCommand);
report("diag-group-token", dg.token == "publish" and dg.index == 1);
df : Diag = .{};
_, fe := parse(a_too_few, cmds, @df);
report("diag-too-few-tag", fe == error.UnknownCommand);
report("diag-too-few-token", df.token == "ci" and df.index == 0);
dv : Diag = .{};
_, ve := parse(a_missing_value, cmds, @dv);
report("diag-missing-value-tag", ve == error.MissingValue);
report("diag-missing-value-token", dv.token == "--out" and dv.index == 2);
dz : Diag = .{};
_, ze := parse(a_value_eats, cmds, @dz);
report("diag-value-eats-tag", ze == error.MissingValue);
report("diag-value-eats-token", dz.token == "--out" and dz.index == 2);
dm : Diag = .{};
_, me := parse(a_missing_req, cmds, @dm);
report("diag-req-tag", me == error.MissingRequired);
report("diag-req-token", dm.token == "out");
report("diag-req-index", dm.index == -1);
print("=== DONE ===\n");
return;