Step 4 (final) of plan.md (Spor B B3 pipeline run). Adds 4 new tests in a contiguous block at the end of tests/tally.test.mjs, mirroring the existing spawnSync style. All 4 test names contain --regex or -r. Coverage map: - SC #1 (long form, exit 0): test 1 - SC #2 (-r short form): test 2 - SC #4 (invalid exits 2 with /^tally: invalid regex/): test 3 - SC #5 (--json includes flags.regex): test 4 Total: 14 tests, all green, 3.16s wall-clock (under 5s cap). [skip-docs]
This commit is contained in:
parent
c6ff4fa94a
commit
da68c2fcf8
1 changed files with 34 additions and 0 deletions
|
|
@ -91,3 +91,37 @@ test('--help: stdout contains "Usage:", exit 0', () => {
|
|||
assert.match(r.stdout, /Usage:/);
|
||||
assert.match(r.stdout, /--ignore-case/);
|
||||
});
|
||||
|
||||
// --- Tests for --regex / -r mode (added in plan step 4, Spor B B3) ---
|
||||
|
||||
test("--regex 'fo+' counts more matches than literal 'foo' (long form, exit 0)", () => {
|
||||
const literal = run('foo', SAMPLE);
|
||||
const regex = run('--regex', 'fo+', SAMPLE);
|
||||
assert.equal(literal.status, 0);
|
||||
assert.equal(regex.status, 0);
|
||||
assert.ok(Number(regex.stdout) >= Number(literal.stdout),
|
||||
`regex count (${regex.stdout.trim()}) should be >= literal count (${literal.stdout.trim()})`);
|
||||
});
|
||||
|
||||
test("-r short form equals --regex long form (same stdout)", () => {
|
||||
const short = run('-r', 'fo+', SAMPLE);
|
||||
const long = run('--regex', 'fo+', SAMPLE);
|
||||
assert.equal(short.status, 0);
|
||||
assert.equal(long.status, 0);
|
||||
assert.equal(short.stdout, long.stdout);
|
||||
});
|
||||
|
||||
test("--regex '[' exits 2 with stderr 'tally: invalid regex'", () => {
|
||||
const r = run('--regex', '[', SAMPLE);
|
||||
assert.equal(r.status, 2);
|
||||
assert.equal(r.stdout, '');
|
||||
assert.match(r.stderr, /^tally: invalid regex/);
|
||||
});
|
||||
|
||||
test("--json --regex 'fo+' includes flags.regex === true in output", () => {
|
||||
const r = run('--json', '--regex', 'fo+', SAMPLE);
|
||||
assert.equal(r.status, 0);
|
||||
const parsed = JSON.parse(r.stdout);
|
||||
assert.equal(parsed.flags.regex, true);
|
||||
assert.ok(typeof parsed.count === 'number' && parsed.count > 0);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue