@criogaid/pi-hashline-edit 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -12
- package/README.zh-CN.md +18 -12
- package/package.json +8 -1
- package/src/core/AGENTS.md +3 -1
- package/src/core/apply.ts +110 -117
- package/src/core/character-set.ts +2 -3
- package/src/core/copy-span.ts +15 -0
- package/src/core/errors.ts +24 -9
- package/src/core/lines.ts +71 -17
- package/src/core/ranges.ts +5 -4
- package/src/core/replace-schema.ts +3 -1
- package/src/core/replace.ts +50 -29
- package/src/core/search-analysis.ts +21 -22
- package/src/core/search.ts +15 -32
- package/src/core/types.ts +3 -0
- package/src/index.ts +47 -39
- package/src/pi/AGENTS.md +30 -19
- package/src/pi/action-fusion.ts +284 -211
- package/src/pi/argument-diagnostics.ts +50 -37
- package/src/pi/argument-error.ts +2 -2
- package/src/pi/argument-validation.ts +163 -66
- package/src/pi/budgets.ts +12 -0
- package/src/pi/diagnostic-buffer.ts +12 -11
- package/src/pi/edit-tool.ts +138 -115
- package/src/pi/error-text.ts +10 -2
- package/src/pi/failure-context.ts +24 -37
- package/src/pi/file-commit.ts +131 -164
- package/src/pi/file-read.ts +122 -31
- package/src/pi/fusion-arguments.ts +214 -0
- package/src/pi/fusion-card.ts +102 -60
- package/src/pi/grep-candidates.ts +35 -22
- package/src/pi/grep-output.ts +197 -190
- package/src/pi/grep-render.ts +22 -13
- package/src/pi/grep-reread.ts +7 -6
- package/src/pi/grep-scope.ts +31 -16
- package/src/pi/grep-search.ts +56 -47
- package/src/pi/grep-tool.ts +35 -33
- package/src/pi/grep-worker.ts +3 -4
- package/src/pi/mutation-diff.ts +238 -0
- package/src/pi/mutation-result.ts +102 -79
- package/src/pi/mutation-runner.ts +107 -84
- package/src/pi/native-bash.ts +41 -0
- package/src/pi/path.ts +59 -6
- package/src/pi/read-tool.ts +173 -138
- package/src/pi/regex-worker.ts +14 -8
- package/src/pi/render.ts +101 -54
- package/src/pi/replace-regex.ts +1 -1
- package/src/pi/replace-tool.ts +14 -7
- package/src/pi/report-cause.ts +34 -17
- package/src/pi/report-schema.ts +184 -85
- package/src/pi/report.ts +133 -64
- package/src/pi/rg-process.ts +68 -48
- package/src/pi/schema.ts +4 -0
- package/src/pi/text-stream.ts +81 -87
- package/src/pi/workspace-cwd.js +2 -0
- package/src/pi/workspace.ts +46 -0
- package/src/pi/write-tool.ts +19 -13
- package/src/core/apply.test.ts +0 -644
- package/src/core/case-fold.test.ts +0 -35
- package/src/core/character-set.test.ts +0 -97
- package/src/core/errors.test.ts +0 -39
- package/src/core/hash.test.ts +0 -64
- package/src/core/lines.test.ts +0 -63
- package/src/core/ranges.test.ts +0 -123
- package/src/core/replace.test.ts +0 -187
- package/src/core/search-analysis.test.ts +0 -210
- package/src/core/search-matrix.test.ts +0 -64
- package/src/core/search-matrix.testing.ts +0 -171
- package/src/core/search.test.ts +0 -132
- package/src/core/text.test.ts +0 -52
- package/src/integration/config-registration.test.ts +0 -291
- package/src/integration/fusion-dispatch.test.ts +0 -320
- package/src/integration/grep-errors.test.ts +0 -81
- package/src/integration/grep-flags.test.ts +0 -76
- package/src/integration/grep-js-completeness.test.ts +0 -278
- package/src/integration/grep-line-candidates.test.ts +0 -201
- package/src/integration/grep-matrix.test.ts +0 -118
- package/src/integration/grep-order.test.ts +0 -78
- package/src/integration/grep-path-matrix.test.ts +0 -128
- package/src/integration/grep-prefilter-coverage.test.ts +0 -204
- package/src/integration/grep-process-limits.test.ts +0 -122
- package/src/integration/grep-regex.test.ts +0 -412
- package/src/integration/grep-rg.test.ts +0 -1659
- package/src/integration/grep-scan-budget.test.ts +0 -111
- package/src/integration/grep-translation.test.ts +0 -199
- package/src/integration/large-text.test.ts +0 -70
- package/src/integration/model-budget-lifecycle.test.ts +0 -186
- package/src/integration/mutation-file-types.test.ts +0 -30
- package/src/integration/mutation-file-types.testing.ts +0 -33
- package/src/integration/npm-package.test.ts +0 -19
- package/src/integration/npm-package.testing.ts +0 -243
- package/src/integration/publication-read-changes.test.ts +0 -454
- package/src/integration/read-changes.test.ts +0 -98
- package/src/integration/replace-package.test.ts +0 -22
- package/src/integration/replace-package.testing.ts +0 -36
- package/src/integration/replace-worker-boundary.test.ts +0 -127
- package/src/integration/report-replay.test.ts +0 -91
- package/src/integration/utf8-errors.test.ts +0 -46
- package/src/pi/action-fusion.test.ts +0 -659
- package/src/pi/action-fusion.testing.ts +0 -38
- package/src/pi/anchor-format.test.ts +0 -124
- package/src/pi/argument-error.testing.ts +0 -46
- package/src/pi/argument-format.test.ts +0 -196
- package/src/pi/argument-validation.test.ts +0 -1007
- package/src/pi/codemode.test.ts +0 -101
- package/src/pi/config.test.ts +0 -204
- package/src/pi/diagnostic-buffer.test.ts +0 -115
- package/src/pi/directory-sync.test.ts +0 -57
- package/src/pi/execute.test.ts +0 -1257
- package/src/pi/extension-loading.test.ts +0 -14
- package/src/pi/extension-loading.testing.ts +0 -3
- package/src/pi/failure-context.test.ts +0 -370
- package/src/pi/failure-path.test.ts +0 -289
- package/src/pi/file-commit.test.ts +0 -628
- package/src/pi/file-read.test.ts +0 -29
- package/src/pi/file-snapshot.test.ts +0 -22
- package/src/pi/fusion-card-interaction.test.ts +0 -143
- package/src/pi/fusion-card.test.ts +0 -353
- package/src/pi/grep-candidates.test.ts +0 -26
- package/src/pi/grep-matrix.test.ts +0 -68
- package/src/pi/grep-order.test.ts +0 -447
- package/src/pi/grep-output.testing.ts +0 -24
- package/src/pi/grep-rg.testing.ts +0 -73
- package/src/pi/grep.test.ts +0 -1670
- package/src/pi/model-budgets.test.ts +0 -96
- package/src/pi/mutation-outcome.testing.ts +0 -20
- package/src/pi/mutation-result.test.ts +0 -96
- package/src/pi/output-budgets.test.ts +0 -221
- package/src/pi/pi.test.ts +0 -158
- package/src/pi/read-delegation.test.ts +0 -119
- package/src/pi/read.test.ts +0 -735
- package/src/pi/regex-worker.test.ts +0 -42
- package/src/pi/registration.test.ts +0 -549
- package/src/pi/render.test.ts +0 -841
- package/src/pi/replace.test.ts +0 -634
- package/src/pi/report-failure.testing.ts +0 -27
- package/src/pi/report.test.ts +0 -533
- package/src/pi/result-safety.test.ts +0 -597
- package/src/pi/rg-process.test.ts +0 -133
- package/src/pi/rg-regex.test.ts +0 -40
- package/src/pi/text-stream.test.ts +0 -281
- package/src/pi/tool-call.testing.ts +0 -61
- package/src/pi/tool-factories.testing.ts +0 -59
- package/src/pi/write.test.ts +0 -256
- package/src/testing/extension-loader.testing.ts +0 -24
- package/src/testing/installation.testing.ts +0 -77
- package/src/testing/process.testing.ts +0 -33
- package/src/testing/regex-host.testing.ts +0 -20
- package/src/testing/regex-translation-corpus.ts +0 -267
- package/src/testing/rg-line-listing.fixture.mjs +0 -7
- package/src/testing/run-tests.ts +0 -47
- package/src/testing/session.testing.ts +0 -127
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { test } from "node:test";
|
|
6
|
-
import { rejectsArgument } from "../pi/argument-error.testing.ts";
|
|
7
|
-
const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
|
|
8
|
-
|
|
9
|
-
import { reportOf } from "../pi/report.ts";
|
|
10
|
-
const { grepCounts } = await import("../pi/grep-output.testing.ts");
|
|
11
|
-
import { callTool } from "../pi/tool-call.testing.ts";
|
|
12
|
-
import { unsupportedByHost } from "../testing/regex-host.testing.ts";
|
|
13
|
-
|
|
14
|
-
interface RegexCase {
|
|
15
|
-
readonly name: string;
|
|
16
|
-
readonly patterns: readonly string[];
|
|
17
|
-
readonly source: string;
|
|
18
|
-
readonly ignoreCase: boolean;
|
|
19
|
-
readonly multilineOnly?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Count physical LF lines, even when JS anchors also match beside a standalone CR.
|
|
23
|
-
function jsLines(
|
|
24
|
-
source: string,
|
|
25
|
-
patterns: readonly string[],
|
|
26
|
-
ignoreCase: boolean,
|
|
27
|
-
multiline: boolean,
|
|
28
|
-
) {
|
|
29
|
-
const lines = new Set<number>();
|
|
30
|
-
const flags = `m${ignoreCase ? "i" : ""}`;
|
|
31
|
-
const physical = source.split("\n");
|
|
32
|
-
if (physical.at(-1) === "") physical.pop();
|
|
33
|
-
if (!multiline) {
|
|
34
|
-
physical.forEach((line, index) => {
|
|
35
|
-
if (patterns.some((pattern) => new RegExp(pattern, flags).test(line))) lines.add(index + 1);
|
|
36
|
-
});
|
|
37
|
-
return [...lines].sort((a, b) => a - b);
|
|
38
|
-
}
|
|
39
|
-
const lineAt = (offset: number) => source.slice(0, offset).split("\n").length;
|
|
40
|
-
for (const pattern of patterns) {
|
|
41
|
-
for (const match of source.matchAll(new RegExp(pattern, `${flags}g`))) {
|
|
42
|
-
const start = match.index;
|
|
43
|
-
const end = start + Math.max(match[0].length - 1, 0);
|
|
44
|
-
for (let line = lineAt(start); line <= Math.min(lineAt(end), physical.length); line++)
|
|
45
|
-
lines.add(line);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return [...lines].sort((a, b) => a - b);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const cases: readonly RegexCase[] = [
|
|
52
|
-
{
|
|
53
|
-
name: "standalone CR anchors",
|
|
54
|
-
patterns: ["^solo$"],
|
|
55
|
-
source: "head\rsolo\ntail",
|
|
56
|
-
ignoreCase: false,
|
|
57
|
-
},
|
|
58
|
-
{ name: "standalone CR atom", patterns: ["\\r"], source: "head\rsolo\ntail", ignoreCase: false },
|
|
59
|
-
{
|
|
60
|
-
name: "BMP class excludes CR",
|
|
61
|
-
patterns: ["a[A-Za-z]b"],
|
|
62
|
-
source: "a\rb\naxb\nab",
|
|
63
|
-
ignoreCase: false,
|
|
64
|
-
},
|
|
65
|
-
{ name: "sigma folding", patterns: ["^σ$"], source: "σ\nς\nΣ\ns", ignoreCase: true },
|
|
66
|
-
{ name: "ASCII k excludes Kelvin", patterns: ["^k$"], source: "k\nK\nK", ignoreCase: true },
|
|
67
|
-
{ name: "Kelvin excludes ASCII k", patterns: ["^K$"], source: "k\nK\nK", ignoreCase: true },
|
|
68
|
-
{
|
|
69
|
-
name: "ASCII character sets",
|
|
70
|
-
patterns: ["^\\w+\\d$"],
|
|
71
|
-
source: "abc1\nσ1\n_2\nabc١",
|
|
72
|
-
ignoreCase: false,
|
|
73
|
-
},
|
|
74
|
-
{ name: "lookaround", patterns: ["(?<=a)b(?=c)"], source: "abc\nabd\nzbc", ignoreCase: false },
|
|
75
|
-
{
|
|
76
|
-
name: "backreference",
|
|
77
|
-
patterns: ["^(a+)\\1$"],
|
|
78
|
-
source: "aa\naaaa\naaa\nbb",
|
|
79
|
-
ignoreCase: false,
|
|
80
|
-
},
|
|
81
|
-
{ name: "forward backreference", patterns: ["^\\1(a)$"], source: "a\naa\nb", ignoreCase: false },
|
|
82
|
-
{ name: "unset group", patterns: ["^(a|(b))\\2c$"], source: "ac\nbbc\nabc", ignoreCase: false },
|
|
83
|
-
{
|
|
84
|
-
name: "named backreference",
|
|
85
|
-
patterns: ["^(?<word>a+)\\k<word>$"],
|
|
86
|
-
source: "aa\naaa\naaaa",
|
|
87
|
-
ignoreCase: false,
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: "capture numbers in OR",
|
|
91
|
-
patterns: ["^(a)\\1$", "^(b)\\1$"],
|
|
92
|
-
source: "aa\nbb\nab",
|
|
93
|
-
ignoreCase: false,
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: "modifier groups",
|
|
97
|
-
patterns: ["^(?i:foo)(?-i:BAR)$"],
|
|
98
|
-
source: "FOOBAR\nfooBAR\nFoObar",
|
|
99
|
-
ignoreCase: false,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: "remove global ignoreCase",
|
|
103
|
-
patterns: ["^(?-i:foo)(?i:bar)$"],
|
|
104
|
-
source: "fooBAR\nFOObar\nfoobar",
|
|
105
|
-
ignoreCase: true,
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: "line OR",
|
|
109
|
-
patterns: ["^alpha$", "^beta$"],
|
|
110
|
-
source: "alpha\nbeta\ngamma",
|
|
111
|
-
ignoreCase: false,
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "LF view spans",
|
|
115
|
-
patterns: ["alpha\\nbeta"],
|
|
116
|
-
source: "alpha\nbeta\ngamma",
|
|
117
|
-
ignoreCase: false,
|
|
118
|
-
multilineOnly: true,
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
name: "overlapping OR spans",
|
|
122
|
-
patterns: ["alpha\\nbeta", "beta\\ngamma"],
|
|
123
|
-
source: "alpha\nbeta\ngamma",
|
|
124
|
-
ignoreCase: false,
|
|
125
|
-
multilineOnly: true,
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: "BMP class spans lines",
|
|
129
|
-
patterns: ["alpha[\\w\\s]*gamma"],
|
|
130
|
-
source: "alpha\nbeta\ngamma",
|
|
131
|
-
ignoreCase: false,
|
|
132
|
-
multilineOnly: true,
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
name: "Unicode line separator anchors",
|
|
136
|
-
patterns: ["^solo$"],
|
|
137
|
-
source: "head\u2028solo\u2029tail",
|
|
138
|
-
ignoreCase: false,
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: "standalone CR in whitespace",
|
|
142
|
-
patterns: ["head\\ssolo"],
|
|
143
|
-
source: "head\rsolo\nhead solo",
|
|
144
|
-
ignoreCase: false,
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: "standalone CR in mixed class",
|
|
148
|
-
patterns: ["head[a\\r]solo"],
|
|
149
|
-
source: "head\rsolo\nheadasolo",
|
|
150
|
-
ignoreCase: false,
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: "scoped m removal excludes Unicode line boundaries",
|
|
154
|
-
patterns: ["(?-m:^solo$)"],
|
|
155
|
-
source: "head\u2028solo\u2029tail\nsolo",
|
|
156
|
-
ignoreCase: false,
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: "negated BMP class preserves case folding without splitting surrogate pairs",
|
|
160
|
-
patterns: ["^[^a\\uD800-\\uDFFF]$"],
|
|
161
|
-
source: "a\nA\nb\n😀\né",
|
|
162
|
-
ignoreCase: true,
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: "grouped supplementary literals retain UTF-16 sequence semantics",
|
|
166
|
-
patterns: ["^(?:😀)+$"],
|
|
167
|
-
source: "😀\n😀😀\na",
|
|
168
|
-
ignoreCase: false,
|
|
169
|
-
},
|
|
170
|
-
...(
|
|
171
|
-
[
|
|
172
|
-
["UTF-16 dot width", "^..$", "😀\nab\na\n😀😀", false],
|
|
173
|
-
["negated digit set", "^\\D{2}$", "😀\nab\n12", false],
|
|
174
|
-
["negated word set", "^\\W{2}$", "😀\n!!\nab", false],
|
|
175
|
-
["negated space set", "^\\S{2}$", "😀\nab\n a", false],
|
|
176
|
-
["all code units", "^[\\s\\S]{2}$", "😀\nab\na", false],
|
|
177
|
-
["surrogate class", "[😀]", "😀\n😁\n🥳\na", false],
|
|
178
|
-
["surrogate capture and reference", "^(\\uD83D).\\1.$", "😀😁\n😀😀\n🥳😀", false],
|
|
179
|
-
["ungrouped supplementary quantifier", "^😀+$", "😀\n😀😀\na", false],
|
|
180
|
-
["greedy and lazy dot", "a.*?b", "a😀b\naab\nac", false],
|
|
181
|
-
["scoped dotAll", "(?s:^a.*b$)", "a\nb\na😀b\nx", false],
|
|
182
|
-
["capture reset after alternate repetition", "^(?:(a)|b)+\\1$", "aba\nab\naa\na", false],
|
|
183
|
-
["capture reset after optional repetition", "^(?:(a)?b)+\\1$", "abba\nabb\naba\nb", false],
|
|
184
|
-
["backward capture greediness", "(?<=([ab]+)([bc]+))\\1", "abca\nabcb\na", false],
|
|
185
|
-
["negative unbounded lookbehind", "(?<!a+)b", "ab\nb\ncab\ncb", false],
|
|
186
|
-
["forward reference in lookbehind", "(?<=\\1(a))b", "ab\naab\nb", false],
|
|
187
|
-
["caseless non-ASCII backreference", "^(σ)\\1$", "σς\nΣσ\nσσ\nss", true],
|
|
188
|
-
["case folding does not expand characters", "^(ß)\\1$", "ßß\nßSS\nss", true],
|
|
189
|
-
["legacy quantified lookahead", "(?=a)?b", "b\nab\na", false],
|
|
190
|
-
["negative assertion leaves capture unset", "(?!(a))\\1b", "b\nab\na", false],
|
|
191
|
-
[
|
|
192
|
-
"duplicate names in disjoint alternatives",
|
|
193
|
-
"(?:(?<x>a)|(?<x>b))\\k<x>",
|
|
194
|
-
"aa\nbb\nab",
|
|
195
|
-
false,
|
|
196
|
-
],
|
|
197
|
-
["JS identity escapes are not PCRE syntax", "\\K\\R\\A\\z", "KRAz\nother", false],
|
|
198
|
-
["empty default-engine matches", "(?:)", "\n\na", false],
|
|
199
|
-
["EOF in an empty file", "^$", "", false],
|
|
200
|
-
["EOF after an empty physical line", "^$", "a\n\n", false],
|
|
201
|
-
["consecutive empty lookahead matches", "(?=^$)", "\n\n\na", false],
|
|
202
|
-
] as const
|
|
203
|
-
).map(([name, pattern, source, ignoreCase]) => ({
|
|
204
|
-
name,
|
|
205
|
-
patterns: [pattern],
|
|
206
|
-
source,
|
|
207
|
-
ignoreCase,
|
|
208
|
-
})),
|
|
209
|
-
];
|
|
210
|
-
|
|
211
|
-
test("regex and case modes across line endings → real grep agrees with native V8", async (t) => {
|
|
212
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-js-equivalence-"));
|
|
213
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
214
|
-
const path = join(directory, "fixture.txt");
|
|
215
|
-
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
216
|
-
for (const scenario of cases) {
|
|
217
|
-
for (const separator of ["\n", "\r\n"]) {
|
|
218
|
-
for (const multiline of scenario.multilineOnly ? [true] : [false, true]) {
|
|
219
|
-
await t.test(
|
|
220
|
-
`${scenario.name} ${JSON.stringify(separator)} multiline=${multiline}`,
|
|
221
|
-
{ skip: unsupportedByHost(scenario.patterns) },
|
|
222
|
-
async () => {
|
|
223
|
-
const raw = scenario.source.replaceAll("\n", separator);
|
|
224
|
-
await writeFile(path, raw);
|
|
225
|
-
const expected = jsLines(
|
|
226
|
-
raw.replaceAll("\r\n", "\n"),
|
|
227
|
-
scenario.patterns,
|
|
228
|
-
scenario.ignoreCase,
|
|
229
|
-
multiline,
|
|
230
|
-
);
|
|
231
|
-
const result = await callTool(tool, {
|
|
232
|
-
path,
|
|
233
|
-
pattern: [...scenario.patterns],
|
|
234
|
-
literal: false,
|
|
235
|
-
ignoreCase: scenario.ignoreCase,
|
|
236
|
-
multiline,
|
|
237
|
-
});
|
|
238
|
-
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
239
|
-
const body = result.content[0];
|
|
240
|
-
assert.ok(body.type === "text");
|
|
241
|
-
const actual = [...body.text.matchAll(/^(\d+)#[0-9A-Z]+│/gm)].map((match) =>
|
|
242
|
-
Number(match[1]),
|
|
243
|
-
);
|
|
244
|
-
assert.deepEqual(actual, expected);
|
|
245
|
-
assert.equal(grepCounts(result).matches, expected.length);
|
|
246
|
-
},
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test("malformed UTF-8 → character classes match replacement characters in the lossy view", async (t) => {
|
|
254
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-js-invalid-"));
|
|
255
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
256
|
-
const path = join(directory, "invalid.txt");
|
|
257
|
-
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
258
|
-
await writeFile(
|
|
259
|
-
path,
|
|
260
|
-
Buffer.concat([Buffer.from("a"), Buffer.from([0xff]), Buffer.from("b\naxb\n")]),
|
|
261
|
-
);
|
|
262
|
-
for (const pattern of [
|
|
263
|
-
"a[\\u0001-\\uD7FF\\uE000-\\uFFFF]b",
|
|
264
|
-
"(?=a)a[\\u0001-\\uD7FF\\uE000-\\uFFFF]b",
|
|
265
|
-
]) {
|
|
266
|
-
const result = await callTool(tool, { path, pattern, literal: false, ignoreCase: false });
|
|
267
|
-
assert.equal(result.isError, undefined);
|
|
268
|
-
assert.equal(grepCounts(result).matches, 2);
|
|
269
|
-
const body = result.content[0];
|
|
270
|
-
assert.ok(body.type === "text");
|
|
271
|
-
assert.match(body.text, /2│axb/);
|
|
272
|
-
assert.match(body.text, /1│a�b/);
|
|
273
|
-
assert.doesNotMatch(body.text, /\d+#/);
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
test("backreference regression: a capture spanning mixed line endings → matches the LF view", async () => {
|
|
278
|
-
const dir = await mkdtemp(join(tmpdir(), "hashline-grep-backreference-"));
|
|
279
|
-
try {
|
|
280
|
-
const path = join(dir, "mixed.txt");
|
|
281
|
-
await writeFile(path, "a\r\na\n");
|
|
282
|
-
const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
|
|
283
|
-
const result = await callTool(tool, {
|
|
284
|
-
path,
|
|
285
|
-
pattern: "(a\\n)\\1",
|
|
286
|
-
literal: false,
|
|
287
|
-
multiline: true,
|
|
288
|
-
ignoreCase: false,
|
|
289
|
-
});
|
|
290
|
-
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
291
|
-
assert.equal(grepCounts(result).matches, 2);
|
|
292
|
-
} finally {
|
|
293
|
-
await rm(dir, { recursive: true, force: true });
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
test("backreference regression: ignoreCase with an ASCII capture → does not match the Kelvin sign", async () => {
|
|
298
|
-
const dir = await mkdtemp(join(tmpdir(), "hashline-grep-backreference-"));
|
|
299
|
-
try {
|
|
300
|
-
const path = join(dir, "casefold.txt");
|
|
301
|
-
await writeFile(path, "kK\n");
|
|
302
|
-
const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
|
|
303
|
-
const result = await callTool(tool, {
|
|
304
|
-
path,
|
|
305
|
-
pattern: "(k)\\1",
|
|
306
|
-
literal: false,
|
|
307
|
-
ignoreCase: true,
|
|
308
|
-
});
|
|
309
|
-
assert.equal(result.isError, undefined, JSON.stringify(result));
|
|
310
|
-
assert.equal(grepCounts(result).matches, 0);
|
|
311
|
-
} finally {
|
|
312
|
-
await rm(dir, { recursive: true, force: true });
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
test("zero-maximum quantifiers → real grep matches the active capture", async (t) => {
|
|
317
|
-
const cases = [
|
|
318
|
-
{
|
|
319
|
-
name: "multiline newline repeated zero times → matches aa",
|
|
320
|
-
pattern: "(a\\n{0})\\1",
|
|
321
|
-
source: "aa\n",
|
|
322
|
-
multiline: true,
|
|
323
|
-
ignoreCase: false,
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
name: "caseless non-ASCII text repeated zero times → matches AA",
|
|
327
|
-
pattern: "(aé{0})\\1",
|
|
328
|
-
source: "AA\n",
|
|
329
|
-
multiline: false,
|
|
330
|
-
ignoreCase: true,
|
|
331
|
-
},
|
|
332
|
-
];
|
|
333
|
-
for (const { name, pattern, source, multiline, ignoreCase } of cases) {
|
|
334
|
-
await t.test(name, async () => {
|
|
335
|
-
const dir = await mkdtemp(join(tmpdir(), "hashline-grep-zero-maximum-"));
|
|
336
|
-
try {
|
|
337
|
-
const path = join(dir, "input.txt");
|
|
338
|
-
await writeFile(path, source);
|
|
339
|
-
const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
|
|
340
|
-
const result = await callTool(tool, {
|
|
341
|
-
path,
|
|
342
|
-
pattern,
|
|
343
|
-
literal: false,
|
|
344
|
-
multiline,
|
|
345
|
-
ignoreCase,
|
|
346
|
-
});
|
|
347
|
-
assert.equal(result.isError, undefined, JSON.stringify(result));
|
|
348
|
-
assert.equal(grepCounts(result).matches, 1);
|
|
349
|
-
} finally {
|
|
350
|
-
await rm(dir, { recursive: true, force: true });
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
test("JS syntax boundary → executes constructs requiring JS", async (t) => {
|
|
357
|
-
const dir = await mkdtemp(join(tmpdir(), "hashline-grep-strict-js-"));
|
|
358
|
-
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
359
|
-
const path = join(dir, "input.txt");
|
|
360
|
-
await writeFile(path, "😀\naba\nab\n");
|
|
361
|
-
const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
|
|
362
|
-
for (const pattern of [
|
|
363
|
-
"^..$",
|
|
364
|
-
"^[^a]{2}$",
|
|
365
|
-
"^[😀]$",
|
|
366
|
-
"^(?:(a)|b)+\\1$",
|
|
367
|
-
"(?<=(a)\\1)b",
|
|
368
|
-
"(?<=(a))b\\1",
|
|
369
|
-
]) {
|
|
370
|
-
await t.test(pattern, async () => {
|
|
371
|
-
const result = await callTool(tool, { path, pattern, literal: false, ignoreCase: false });
|
|
372
|
-
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
373
|
-
assert.equal(
|
|
374
|
-
grepCounts(result).matches,
|
|
375
|
-
jsLines("😀\naba\nab\n", [pattern], false, false).length,
|
|
376
|
-
);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
test("zero-width assertions at LF and CRLF boundaries → match only empty physical lines", async (t) => {
|
|
382
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-zero-width-"));
|
|
383
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
384
|
-
const path = join(directory, "fixture.txt");
|
|
385
|
-
await writeFile(path, "a\nb\r\nc\n\nd\r\n\r\nx y\n");
|
|
386
|
-
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
387
|
-
for (const [pattern, multiline] of [
|
|
388
|
-
["^$", false],
|
|
389
|
-
["^ *$", false],
|
|
390
|
-
["(?<![a-z])$", false],
|
|
391
|
-
["^(?![a-z])", false],
|
|
392
|
-
["(?<!\\w)(?!\\w)", false],
|
|
393
|
-
["\\B", false],
|
|
394
|
-
["\\B", true],
|
|
395
|
-
] as const) {
|
|
396
|
-
await t.test(`${pattern} multiline=${multiline}`, async () => {
|
|
397
|
-
const result = await callTool(tool, {
|
|
398
|
-
path,
|
|
399
|
-
pattern,
|
|
400
|
-
literal: false,
|
|
401
|
-
ignoreCase: false,
|
|
402
|
-
multiline,
|
|
403
|
-
});
|
|
404
|
-
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
405
|
-
const body = result.content[0];
|
|
406
|
-
assert.ok(body.type === "text");
|
|
407
|
-
const lines = [...body.text.matchAll(/^(\d+)#[0-9A-Z]+│/gm)].map((match) => Number(match[1]));
|
|
408
|
-
assert.deepEqual(lines, [4, 6]);
|
|
409
|
-
assert.equal(grepCounts(result).matches, 2);
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
});
|