29 lines
1.7 KiB
JavaScript
29 lines
1.7 KiB
JavaScript
// [CQW] Fix round 4.5b, part 3 (decision 89).
|
|
// Defect: `tokenize` refused a closing quote that had whitespace or a line
|
|
// break before it, so `"multi line` + line break + `"` (the form the `--stdin`
|
|
// heredoc produces), `--project "my dir "`, `"a "` and `" "` never paired and
|
|
// their quotes stayed literal characters. A same-kind quote that ends a word
|
|
// must close the value, whatever stands before it.
|
|
// This file must load at ce98f62: it imports only `parseArgs` and `tokenize`,
|
|
// which exist there, so its red is an assertion, not a crash.
|
|
import { test } from 'node:test';
|
|
import { strict as assert } from 'node:assert';
|
|
import { parseArgs, tokenize } from '../../lib/parsers/arg-parser.mjs';
|
|
|
|
const values = (text) => tokenize(text).map((t) => t.value);
|
|
|
|
test('[CQW] a quoted value closes at a quote that ends a word, also after whitespace or a line break', () => {
|
|
// Red at the start point: the closing quote has whitespace before it.
|
|
assert.deepEqual(values('"multi line\n" --since HEAD'), ['multi line\n', '--since', 'HEAD']);
|
|
const r = parseArgs('--project "my dir "', 'trekreview');
|
|
assert.equal(r.flags['--project'], 'my dir ');
|
|
assert.deepEqual(r.positional, []);
|
|
assert.deepEqual(values('"a "'), ['a ']);
|
|
assert.deepEqual(values('" "'), [' ']);
|
|
|
|
// Control: a quote that starts a word stops the search; a quote inside a
|
|
// word is skipped; a quote that ends a word after a letter still closes.
|
|
assert.equal(parseArgs('--project "my dir"/x --since "HEAD~1"', 'trekreview').flags['--since'], 'HEAD~1');
|
|
assert.deepEqual(values("'Fix the user's login'"), ["Fix the user's login"]);
|
|
assert.deepEqual(values("'the '90s were great'"), ["'the", '90s were great']);
|
|
});
|