@feigi/fleet-ctl 3.23.36 → 3.23.38
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/package.json +1 -1
- package/scripts/cell-readout.mjs +38 -11
- package/scripts/main-checkout.mjs +1 -1
- package/scripts/member-write-guard.mjs +1 -1
- package/scripts/repo-root.mjs +1 -1
- package/skills/run-team/references/reaping.md +1 -1
- package/scripts/agent-test-dir-prose.test.mjs +0 -59
- package/scripts/agent-test.test.mjs +0 -1640
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
- package/scripts/ambient-git-vars-prose.test.mjs +0 -192
- package/scripts/ancestry-check-position-prose.test.mjs +0 -175
- package/scripts/apply-ruleset.test.mjs +0 -421
- package/scripts/arg-header-probes-prose.test.mjs +0 -394
- package/scripts/arg.test.mjs +0 -1354
- package/scripts/board-cli.test.mjs +0 -710
- package/scripts/board-identity.test.mjs +0 -429
- package/scripts/board-liveness-banner.test.mjs +0 -119
- package/scripts/board-prev-shape.test.mjs +0 -228
- package/scripts/board-tryparse-null.test.mjs +0 -119
- package/scripts/board.test.mjs +0 -3121
- package/scripts/brief-after-cut-prose.test.mjs +0 -53
- package/scripts/candidates-exit3-prose.test.mjs +0 -302
- package/scripts/candidates.test.mjs +0 -2312
- package/scripts/caveat-unification-prose.test.mjs +0 -98
- package/scripts/cell-readout.test.mjs +0 -615
- package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
- package/scripts/ci-completes-premise-prose.test.mjs +0 -257
- package/scripts/ci-state-prose.test.mjs +0 -113
- package/scripts/ci-state.test.mjs +0 -1933
- package/scripts/ci-vacuous-green.test.mjs +0 -368
- package/scripts/citation-sweep-prose.test.mjs +0 -1712
- package/scripts/claim-lifecycle.test.mjs +0 -187
- package/scripts/claim-ticket.test.mjs +0 -1122
- package/scripts/closing-keyword-prose.test.mjs +0 -193
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
- package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
- package/scripts/compute-board.test.mjs +0 -1214
- package/scripts/compute-spend.test.mjs +0 -517
- package/scripts/consumer-technology-prose.test.mjs +0 -126
- package/scripts/cross-repo-citation-prose.test.mjs +0 -155
- package/scripts/cwd-isolation-pins.mjs +0 -83
- package/scripts/dedupe-guard-prose.test.mjs +0 -243
- package/scripts/delete-merged-branch.test.mjs +0 -576
- package/scripts/derive-testcmd.test.mjs +0 -595
- package/scripts/diff-stats.test.mjs +0 -404
- package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
- package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
- package/scripts/dispositions-check.test.mjs +0 -936
- package/scripts/dispositions-gate-prose.test.mjs +0 -129
- package/scripts/drop-merged-label.test.mjs +0 -479
- package/scripts/exec-stub.mjs +0 -93
- package/scripts/exec-stub.test.mjs +0 -69
- package/scripts/expected-jobs-prose.test.mjs +0 -80
- package/scripts/fan-out-authorization-prose.test.mjs +0 -80
- package/scripts/filing-bar-seat-prose.test.mjs +0 -242
- package/scripts/filing-claim-bar-prose.test.mjs +0 -166
- package/scripts/finisher-died-prose.test.mjs +0 -31
- package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
- package/scripts/finisher-halt-prose.test.mjs +0 -106
- package/scripts/finisher-name-prose.test.mjs +0 -134
- package/scripts/finisher-own-tree-prose.test.mjs +0 -299
- package/scripts/finisher-pin-race-prose.test.mjs +0 -339
- package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
- package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
- package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
- package/scripts/fleet-bootstrap.test.mjs +0 -75
- package/scripts/fleet-heartbeat.test.mjs +0 -450
- package/scripts/fleet-provenance.test.mjs +0 -138
- package/scripts/fleet-run.test.mjs +0 -90
- package/scripts/fleet-state.test.mjs +0 -460
- package/scripts/fleet-tick-prose.test.mjs +0 -300
- package/scripts/fleet-tick.test.mjs +0 -2444
- package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
- package/scripts/frontmatter-check.test.mjs +0 -436
- package/scripts/git-env.test.mjs +0 -149
- package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
- package/scripts/gone-walk.test.mjs +0 -213
- package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
- package/scripts/head-moved-after-label-prose.test.mjs +0 -233
- package/scripts/immutable-body-claim-prose.test.mjs +0 -204
- package/scripts/implementer-model-tier.test.mjs +0 -235
- package/scripts/inflight-citation-prose.test.mjs +0 -144
- package/scripts/inflight-exit2-prose.test.mjs +0 -81
- package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
- package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
- package/scripts/inflight.test.mjs +0 -2882
- package/scripts/injection-control-prose.test.mjs +0 -404
- package/scripts/install-root-audit.test.mjs +0 -464
- package/scripts/instrument-check-prose.test.mjs +0 -235
- package/scripts/instruments.test.mjs +0 -787
- package/scripts/is-cli.test.mjs +0 -99
- package/scripts/issue-tracker-prose.test.mjs +0 -71
- package/scripts/json.test.mjs +0 -364
- package/scripts/ledger-dispatch.test.mjs +0 -927
- package/scripts/ledger-grammar.test.mjs +0 -227
- package/scripts/ledger-read-require-file.test.mjs +0 -197
- package/scripts/ledger-rotate.test.mjs +0 -142
- package/scripts/ledger.test.mjs +0 -3436
- package/scripts/line-distance-prose.test.mjs +0 -245
- package/scripts/liveness-rationale-prose.test.mjs +0 -83
- package/scripts/locale-pin-prose.test.mjs +0 -189
- package/scripts/main-checkout.test.mjs +0 -332
- package/scripts/member-outcome-prose.test.mjs +0 -167
- package/scripts/member-outcomes-header.test.mjs +0 -129
- package/scripts/member-outcomes-prose.test.mjs +0 -63
- package/scripts/member-outcomes.test.mjs +0 -638
- package/scripts/member-prompt-prose.test.mjs +0 -165
- package/scripts/member-record.test.mjs +0 -541
- package/scripts/member-write-guard.test.mjs +0 -214
- package/scripts/merge-commit-probe-prose.test.mjs +0 -122
- package/scripts/merge-gate.test.mjs +0 -613
- package/scripts/muted-git-guard-sweep.test.mjs +0 -493
- package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
- package/scripts/net-watchdog-prose.test.mjs +0 -79
- package/scripts/net.test.mjs +0 -211
- package/scripts/no-ci-gate-prose.test.mjs +0 -108
- package/scripts/no-undo-audit.test.mjs +0 -3961
- package/scripts/no-wave.test.mjs +0 -138
- package/scripts/node-floor-sweep.test.mjs +0 -611
- package/scripts/pointer-target-prose.test.mjs +0 -186
- package/scripts/pr-cost.test.mjs +0 -521
- package/scripts/pr-overlap.test.mjs +0 -692
- package/scripts/printf-die-sweep.test.mjs +0 -384
- package/scripts/prompt-renderer.mjs +0 -40
- package/scripts/prompt-renderer.test.mjs +0 -68
- package/scripts/prose-pin.mjs +0 -807
- package/scripts/prose-pin.test.mjs +0 -1034
- package/scripts/prove-merge.test.mjs +0 -995
- package/scripts/pull-table-relabel-prose.test.mjs +0 -60
- package/scripts/quiet-payload-prose.test.mjs +0 -222
- package/scripts/reap-cherry-check-prose.test.mjs +0 -80
- package/scripts/reap.test.mjs +0 -4432
- package/scripts/reaping-prose.test.mjs +0 -239
- package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
- package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
- package/scripts/recipe-derivation-prose.test.mjs +0 -112
- package/scripts/recipe-prove.test.mjs +0 -1042
- package/scripts/refuter-scratch-prose.test.mjs +0 -135
- package/scripts/release-label-required-prose.test.mjs +0 -71
- package/scripts/release-label-split-prose.test.mjs +0 -184
- package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
- package/scripts/release-ticket.test.mjs +0 -5099
- package/scripts/renovate-release-contract.test.mjs +0 -379
- package/scripts/repo-root.test.mjs +0 -873
- package/scripts/reporter-output-rule-prose.test.mjs +0 -208
- package/scripts/review-agent-report-only.test.mjs +0 -49
- package/scripts/review-core-booking.test.mjs +0 -35
- package/scripts/review-core-cwd-isolation.test.mjs +0 -374
- package/scripts/review-core-reads.test.mjs +0 -478
- package/scripts/review-core-refuter-scratch.test.mjs +0 -148
- package/scripts/review-core-scratch-refusal.test.mjs +0 -64
- package/scripts/review-core-shared-test-run.test.mjs +0 -275
- package/scripts/review-core-snapshot-path.test.mjs +0 -830
- package/scripts/review-core-specialist-scratch.test.mjs +0 -191
- package/scripts/review-core-testcmd.test.mjs +0 -335
- package/scripts/review-core-unrun.test.mjs +0 -566
- package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
- package/scripts/review-eval-resolver-path.test.mjs +0 -55
- package/scripts/review-host-fixture.mjs +0 -89
- package/scripts/review-in-run-retry.test.mjs +0 -211
- package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
- package/scripts/review-path-default.test.mjs +0 -796
- package/scripts/review-runner-spawns.test.mjs +0 -95
- package/scripts/review-runner.test.mjs +0 -166
- package/scripts/review-tier-audit.test.mjs +0 -140
- package/scripts/run-artifact-pr-prose.test.mjs +0 -341
- package/scripts/run-merge-bot-prose.test.mjs +0 -1413
- package/scripts/run-team-local-hook.test.mjs +0 -442
- package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
- package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
- package/scripts/section-between-guard-prose.test.mjs +0 -379
- package/scripts/select-dimensions.test.mjs +0 -674
- package/scripts/shared-refusal.test.mjs +0 -388
- package/scripts/shell-traps-prose.test.mjs +0 -504
- package/scripts/shortlist.test.mjs +0 -380
- package/scripts/slow-transport.mjs +0 -72
- package/scripts/snapshot-repo.test.mjs +0 -1006
- package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
- package/scripts/spend-view.test.mjs +0 -312
- package/scripts/staleness-qualifier-prose.test.mjs +0 -251
- package/scripts/staleness-verdict-prose.test.mjs +0 -142
- package/scripts/staleness.test.mjs +0 -893
- package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
- package/scripts/stash-prohibition-prose.test.mjs +0 -313
- package/scripts/strip-comments.mjs +0 -44
- package/scripts/temp-dir.mjs +0 -47
- package/scripts/ticket-router.test.mjs +0 -981
- package/scripts/tier-check.test.mjs +0 -828
- package/scripts/tier-outcomes-header.test.mjs +0 -518
- package/scripts/tier-outcomes.test.mjs +0 -572
- package/scripts/tier-roles.test.mjs +0 -535
- package/scripts/tracker-block-copy-prose.test.mjs +0 -288
- package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
- package/scripts/unattended-git-sweep.test.mjs +0 -142
- package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
- package/scripts/verify-sha.test.mjs +0 -692
- package/scripts/watcher-degraded-block.test.mjs +0 -369
- package/scripts/watcher-key-prose.test.mjs +0 -106
- package/scripts/within-run-pair-prose.test.mjs +0 -212
- package/scripts/worktree-audit.test.mjs +0 -1408
- package/scripts/worktree-head-prose.test.mjs +0 -276
- package/scripts/worktree-listing-sweep.test.mjs +0 -217
- package/scripts/worktree-model-prose.test.mjs +0 -216
- package/scripts/worktree-porcelain.mjs +0 -35
- package/scripts/worktree-porcelain.test.mjs +0 -102
|
@@ -1,1034 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { anchorAt, between, betweenPhrases, bullet, paragraph, phrase, quoteBlock, quoteBlocks, runAbove, sentences, stripSlashGutter, logicalLines } from "./prose-pin.mjs";
|
|
4
|
-
|
|
5
|
-
// The 14 consumer files exercise only between()'s HAPPY path: every one of them
|
|
6
|
-
// slices a document that still holds both anchors. Measured on this PR: deleting
|
|
7
|
-
// BOTH `assert.notEqual` guards left the full suite at 1035 pass / 0 fail, exit
|
|
8
|
-
// 0 — byte-identical to baseline. The guards are the entire reason this module
|
|
9
|
-
// was extracted rather than left inline, and nothing was pinning them.
|
|
10
|
-
//
|
|
11
|
-
// Fixtures here are short literal strings on purpose. Pinning the guards against
|
|
12
|
-
// a real document would re-couple this file to whatever review-core.mjs or a SKILL.md
|
|
13
|
-
// happens to say today, which is the rot the name-based citations elsewhere in
|
|
14
|
-
// this repo exist to avoid.
|
|
15
|
-
|
|
16
|
-
test("between returns the slice bounded by both anchors, start inclusive, end exclusive", () => {
|
|
17
|
-
assert.equal(between("xxSTARTmiddleENDyy", "START", "END", "the fixture"), "STARTmiddle");
|
|
18
|
-
// The start anchor is KEPT, the end anchor dropped — callers that need it
|
|
19
|
-
// stripped do their own `.slice(from.length)`.
|
|
20
|
-
assert.equal(between("aXbXc", "X", "c", "the fixture"), "XbX");
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("between throws when the text no longer contains the start anchor", () => {
|
|
24
|
-
assert.throws(
|
|
25
|
-
() => between("no anchors here", "START", "END", "the fixture"),
|
|
26
|
-
/the fixture no longer contains "START" — update this test/,
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// The both-ends contract, stated in prose-pin.mjs's own comment and unverified
|
|
31
|
-
// until now: the end anchor is searched from `at + from.length`, never from 0.
|
|
32
|
-
// An unbounded `text.indexOf(to)` finds the EARLIER occurrence, returns
|
|
33
|
-
// `text.slice(at, 0)` === "" and throws nothing — the false green the module
|
|
34
|
-
// exists to kill. Both this test and the one above red if either guard is
|
|
35
|
-
// deleted; this one ALSO reds if the end search loses its offset.
|
|
36
|
-
test("between throws when the end anchor exists only BEFORE the start anchor", () => {
|
|
37
|
-
assert.throws(
|
|
38
|
-
() => between("ENDzzSTARTzz", "START", "END", "the fixture"),
|
|
39
|
-
/the fixture no longer contains "END" after "START" — update this test/,
|
|
40
|
-
);
|
|
41
|
-
// And the same when the end anchor is absent outright.
|
|
42
|
-
assert.throws(() => between("zzSTARTzz", "START", "END", "the fixture"), /no longer contains "END" after "START"/);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// #1492. The anchor-pair primitive's emphasis-tolerant mode, mirroring the one
|
|
46
|
-
// `anchorAt` and `quoteBlock` already carry. Every move below is
|
|
47
|
-
// meaning-preserving in the rendered document, and every one of them reds a
|
|
48
|
-
// literal `indexOf` anchor — the defect class this option closes. The anchor is
|
|
49
|
-
// typed WITH `**` here on purpose: that is how this population writes them, and
|
|
50
|
-
// it is the direction `anchorAt`'s own tolerant mode does not cover, since it
|
|
51
|
-
// strips only the document.
|
|
52
|
-
//
|
|
53
|
-
// THE CLASS, enumerated. `**` emphasis may, meaning-preservingly: vanish from
|
|
54
|
-
// the anchored words, appear on them, narrow onto fewer of them, widen past
|
|
55
|
-
// them, or move to a different word boundary inside them. All five are covered
|
|
56
|
-
// below. Deliberately LEFT, and out of this option's name: single-asterisk
|
|
57
|
-
// `*italic*` and `_underscore_` emphasis, and backtick code spans — the
|
|
58
|
-
// acceptance criterion is to reuse `unemphasized`, which is this directory's
|
|
59
|
-
// one definition of an emphasis marker and is `**`-only; a second stripper
|
|
60
|
-
// here would be the duplicate that criterion forbids. Also left: a lone `*`
|
|
61
|
-
// whose pairing differs between the anchor and the document, since `**` pairs
|
|
62
|
-
// globally in the document and locally in the anchor. No anchor in this repo
|
|
63
|
-
// carries one.
|
|
64
|
-
//
|
|
65
|
-
// Mutation-tested 2026-09-18 against a scratch copy of `prose-pin.mjs` under
|
|
66
|
-
// `/tmp/fleet-scratch/impl-1492/` (never the real module), each substitution
|
|
67
|
-
// asserted to have applied before the run was believed — two of the first
|
|
68
|
-
// patterns matched `anchorAt`/`quoteBlock` as well and were reported UNAPPLIED
|
|
69
|
-
// rather than silently passing as survivors. 11 mutations, 0 survivors. Reds
|
|
70
|
-
// by test NAME, not count, so per-pin discrimination is visible:
|
|
71
|
-
// (M1) tolerance ignored, raw document searched — reds 9
|
|
72
|
-
// (M2) start-anchor uniqueness guard deleted — reds the ambiguity pin alone
|
|
73
|
-
// (M3) [superseded by #1613] this session predates the END-anchor guard;
|
|
74
|
-
// symmetrizing it onto the END anchor reded both END pins below at
|
|
75
|
-
// the time and is now the SHIPPED behavior — see `between`'s own doc
|
|
76
|
-
// comment and the end-anchor ambiguity/empty-anchor pins added below
|
|
77
|
-
// (M4) end anchor searched from 0 — reds the both-ends pin, old and new
|
|
78
|
-
// (M5) `rawOffset` dropped, stripped offsets cut raw text — reds 6
|
|
79
|
-
// (M6) tolerant match routed through `phrase()` — reds the whitespace pin
|
|
80
|
-
// alone, and reds NOTHING until that pin covered the start anchor too
|
|
81
|
-
// (M7a/b) document stripped but the anchor left literal — reds 7 / 3
|
|
82
|
-
// (M8) tolerance on by default — reds the pre-existing literal `between`
|
|
83
|
-
// pin, which is the off-by-default criterion holding without an edit
|
|
84
|
-
// (M9) `occurrenceCount` stops at the first hit — reds the ambiguity pin
|
|
85
|
-
// (M10) tolerant slice returned emphasis-stripped — reds 5
|
|
86
|
-
//
|
|
87
|
-
// Each row states the WHOLE slice it expects, byte for byte, rather than
|
|
88
|
-
// matching a phrase inside it. Two contracts ride on that: the bounds moved to
|
|
89
|
-
// the right places, and the returned bytes still carry whatever `**` the
|
|
90
|
-
// document has — a tolerant anchor locates, it never rewrites what the caller
|
|
91
|
-
// gets back. A `phrase()` match inside the slice would see neither, and would
|
|
92
|
-
// pass against a slice that had silently swallowed `pad`.
|
|
93
|
-
const MOVES = [
|
|
94
|
-
["emphasis removed", "pad\n\nstart here — the rule.\n\nEND", "start here — the rule.\n\n"],
|
|
95
|
-
["emphasis narrowed to one word", "pad\n\n**start** here — the rule.\n\nEND", "**start** here — the rule.\n\n"],
|
|
96
|
-
["emphasis widened past the anchor", "pad\n\n**start here — the** rule.\n\nEND", "**start here — the** rule.\n\n"],
|
|
97
|
-
["emphasis moved to another word boundary", "pad\n\nstart **here** — the rule.\n\nEND", "start **here** — the rule.\n\n"],
|
|
98
|
-
["emphasis unchanged", "pad\n\n**start here** — the rule.\n\nEND", "**start here** — the rule.\n\n"],
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
for (const [move, doc, expected] of MOVES) {
|
|
102
|
-
test(`between with emphasisTolerant still finds its anchor when ${move}`, () => {
|
|
103
|
-
assert.equal(between(doc, "**start here**", "END", "the fixture", { emphasisTolerant: true }), expected);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// The over-widening case, and the reason the tolerant mode needs a guard the
|
|
108
|
-
// literal one does not. Stripping `**` can only ADD matches, so a tolerant
|
|
109
|
-
// START anchor can land EARLIER than the literal one did — here on a decoy
|
|
110
|
-
// stating the rule in plain text ABOVE the real, emphasized one. Taking the
|
|
111
|
-
// first hit slices from the decoy and pulls in everything between, which no
|
|
112
|
-
// assertion inside the slice can see: the pinned words are all still there,
|
|
113
|
-
// just sourced from the wrong copy. A green pin over the wrong region is worse
|
|
114
|
-
// than the red it replaces, so it throws.
|
|
115
|
-
//
|
|
116
|
-
// The literal call on the SAME fixture is asserted alongside it, and that
|
|
117
|
-
// pairing is what makes this a widening test rather than a duplicate-anchor
|
|
118
|
-
// test: the exact-match anchor resolves to ONE place and returns the narrow,
|
|
119
|
-
// correct slice, so the region the tolerant mode refuses to guess at is
|
|
120
|
-
// demonstrably real and demonstrably wider.
|
|
121
|
-
const TWO_STATES = "decoy: the RULE — and then it drifts.\n\n**never slice me**\n\nreal: the **RULE** — and then it holds.\n\nEND";
|
|
122
|
-
|
|
123
|
-
test("between throws on an ambiguous tolerant start anchor rather than slicing from the wrong occurrence", () => {
|
|
124
|
-
assert.throws(
|
|
125
|
-
() => between(TWO_STATES, "the **RULE** —", "END", "the fixture", { emphasisTolerant: true }),
|
|
126
|
-
/the fixture: emphasis-tolerant slice anchor "the \*\*RULE\*\* —" occurs 2 times once `\*\*` is ignored/,
|
|
127
|
-
);
|
|
128
|
-
// Exact-match, same fixture, same anchors: one hit, and the slice the
|
|
129
|
-
// tolerant mode declined to widen past.
|
|
130
|
-
assert.equal(between(TWO_STATES, "the **RULE** —", "END", "the fixture"), "the **RULE** — and then it holds.\n\n");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// The END anchor now gets the SAME guard, symmetric with the START — added
|
|
134
|
-
// by #1613 after review found the asymmetry could silently narrow OR widen a
|
|
135
|
-
// tolerant slice (see `between`'s own doc comment). Here the end anchor's
|
|
136
|
-
// text appears twice AFTER the start in two different emphasis states, which
|
|
137
|
-
// is exactly the shape the START guard refuses; the END guard now refuses it
|
|
138
|
-
// too, rather than resolving to the first and silently dropping whatever sat
|
|
139
|
-
// between the two.
|
|
140
|
-
//
|
|
141
|
-
// The literal call on the SAME fixture is asserted alongside it: literal
|
|
142
|
-
// mode never gets this guard (see `between`'s own doc comment for why) and
|
|
143
|
-
// still resolves to the first occurrence — proving the guard is scoped to
|
|
144
|
-
// `emphasisTolerant` and did not regress the literal path.
|
|
145
|
-
const REPEATED_END = "HEAD one\n\nthe STOP mark, plain.\n\nmiddle\n\nthe **STOP** mark, bold.\n\nEND";
|
|
146
|
-
|
|
147
|
-
test("between throws on an ambiguous tolerant end anchor rather than stopping at the first occurrence", () => {
|
|
148
|
-
assert.throws(
|
|
149
|
-
() => between(REPEATED_END, "HEAD one", "the **STOP** mark", "the fixture", { emphasisTolerant: true }),
|
|
150
|
-
/the fixture: emphasis-tolerant slice end anchor "the \*\*STOP\*\* mark" occurs 2 times after the start once `\*\*` is ignored/,
|
|
151
|
-
);
|
|
152
|
-
assert.equal(between(REPEATED_END, "HEAD one", "the **STOP** mark", "the fixture"), "HEAD one\n\nthe STOP mark, plain.\n\nmiddle\n\n");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// `occurrenceCount`'s own contract, unverified until now: cursor-bounded
|
|
156
|
-
// (`i = hit + 1`) rather than chained off the previous hit's length, so an
|
|
157
|
-
// anchor that strips to "" under `emphasisTolerant` terminates instead of
|
|
158
|
-
// spinning forever on `indexOf("", i)`'s clamped return. Confirmed by
|
|
159
|
-
// reverting to the chained form (`i = hit + needle.length`): every other
|
|
160
|
-
// test in this file still passes, and only this fixture hangs, because
|
|
161
|
-
// `needle.length` is 0 and the cursor never advances.
|
|
162
|
-
test("between throws rather than hanging when a tolerant anchor strips to empty", () => {
|
|
163
|
-
assert.throws(
|
|
164
|
-
() => between("pad\n\n**start here**\n\nEND", "**", "END", "the fixture", { emphasisTolerant: true }),
|
|
165
|
-
/the fixture: emphasis-tolerant slice anchor "\*\*" occurs \d+ times once `\*\*` is ignored/,
|
|
166
|
-
);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// `between`'s both-ends contract has to survive the new search view: the end
|
|
170
|
-
// anchor is still searched from `at + start.length`, measured in the STRIPPED
|
|
171
|
-
// document, never from 0. A tolerant search that lost that offset finds the
|
|
172
|
-
// copy above the start anchor and returns "", the false green this module
|
|
173
|
-
// exists to kill — and the throw below is the same guard one document later.
|
|
174
|
-
// The message names the anchor as the caller TYPED it, `**` and all, so it can
|
|
175
|
-
// be grepped for.
|
|
176
|
-
test("between's tolerant END anchor is still searched only after the start anchor", () => {
|
|
177
|
-
assert.equal(
|
|
178
|
-
between("**EDGE** early\n\nHEAD\n\nbody here\n\nEDGE late", "HEAD", "**EDGE**", "the fixture", { emphasisTolerant: true }),
|
|
179
|
-
"HEAD\n\nbody here\n\n",
|
|
180
|
-
);
|
|
181
|
-
assert.throws(
|
|
182
|
-
() => between("**EDGE** early\n\nHEAD\n\nbody here", "HEAD", "**EDGE**", "the fixture", { emphasisTolerant: true }),
|
|
183
|
-
/the fixture no longer contains "\*\*EDGE\*\*" after "HEAD" — update this test/,
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// Emphasis tolerance and WHITESPACE tolerance are separate axes, and this pin
|
|
188
|
-
// is the one that keeps them separate. The obvious implementation mirrors
|
|
189
|
-
// `anchorAt` and runs the stripped anchor through `phrase()`; `phrase()` is
|
|
190
|
-
// `s.trim().split(/\s+/)`, so it discards the leading newline — and this
|
|
191
|
-
// family's anchors carry load-bearing ones, e.g.
|
|
192
|
-
// `fix-applier-correction-rules-prose.test.mjs`'s `PROMPT_END`,
|
|
193
|
-
// `"\n**Put the standing CI facts"`: the leading `\n` ties it to the line
|
|
194
|
-
// where that phrase starts, not to any earlier occurrence of the same words
|
|
195
|
-
// mid-line. `phrase()`'s `.trim()` would strip that newline before matching.
|
|
196
|
-
//
|
|
197
|
-
// Both fixtures reproduce that shape: the anchor's word appears inline earlier
|
|
198
|
-
// and at a line start later, and only the line-start one is the bound. Route
|
|
199
|
-
// either anchor through `phrase()` and it binds the inline copy instead —
|
|
200
|
-
// widening the slice at the start bound, cutting it short at the end bound.
|
|
201
|
-
// Both anchors are pinned because either one alone leaves the other free to
|
|
202
|
-
// pick up `phrase()` on the next edit.
|
|
203
|
-
test("between's tolerant mode leaves whitespace literal at both anchors, so a leading newline still bounds the slice", () => {
|
|
204
|
-
assert.equal(between("HEAD one **Put** two\n**Put the rest", "HEAD", "\n**Put", "the fixture", { emphasisTolerant: true }), "HEAD one **Put** two");
|
|
205
|
-
assert.equal(between("pad **HEAD** inline\nHEAD at line start\n\nEND", "\n**HEAD**", "END", "the fixture", { emphasisTolerant: true }), "\nHEAD at line start\n\n");
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
// #491: a sibling item inserted between the anchors is the hole `bullet`
|
|
209
|
-
// closes, whatever marker it opens with — the #747 clamp this replaced looked
|
|
210
|
-
// only for `- **`, so a plain `- ` or numbered sibling still joined the slice.
|
|
211
|
-
test("bullet ends the item at the next sibling, whatever its marker, and never past the end anchor", () => {
|
|
212
|
-
const list = (sibling) => `intro\n- **Edge A** first line\n wraps here.\n${sibling} carries the words\n- **Edge B** more\n\nEND`;
|
|
213
|
-
for (const sibling of ["- **Inserted**", "- inserted", "* inserted", "+ inserted", "3. inserted", "3) inserted"]) {
|
|
214
|
-
assert.equal(bullet(list(sibling), "- **Edge A**", "END", "the fixture"), "- **Edge A** first line\n wraps here.", sibling);
|
|
215
|
-
}
|
|
216
|
-
// No sibling before the end anchor: the end anchor bounds it, exclusive.
|
|
217
|
-
assert.equal(bullet("- **Edge A** only item\nEND tail", "- **Edge A**", "END", "the fixture"), "- **Edge A** only item\n");
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// The half a clamp can wrongly REFUSE: an item's own nested list, and its own
|
|
221
|
-
// wrapped lines, belong to it. A clamp at any `\n- ` or at any list marker
|
|
222
|
-
// regardless of indent cuts the item at its first child and drops the rest.
|
|
223
|
-
test("bullet keeps the item's own deeper-indented children and continuation lines", () => {
|
|
224
|
-
const text = "- **Edge A** lead\n continues\n - child one\n - grandchild\n 1. numbered child\n tail line\n- **Edge B**\nEND";
|
|
225
|
-
assert.equal(
|
|
226
|
-
bullet(text, "- **Edge A**", "END", "the fixture"),
|
|
227
|
-
"- **Edge A** lead\n continues\n - child one\n - grandchild\n 1. numbered child\n tail line",
|
|
228
|
-
);
|
|
229
|
-
// An indented item's siblings are at ITS indent: a shallower marker ends it
|
|
230
|
-
// too, a same-indent one ends it, a deeper one is its child.
|
|
231
|
-
const nested = "1. step\n - **Item** body\n - child\n - sibling\n2. next step\nEND";
|
|
232
|
-
assert.equal(bullet(nested, "- **Item**", "END", "the fixture"), "- **Item** body\n - child");
|
|
233
|
-
assert.equal(bullet("1. step\n - **Item** body\n2. next\nEND", "- **Item**", "END", "the fixture"), "- **Item** body");
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
test("bullet throws rather than widening when either anchor is gone", () => {
|
|
237
|
-
assert.throws(() => bullet("- a\n- b\nEND", "- **Edge A**", "END", "the fixture"), /the fixture no longer contains "- \*\*Edge A\*\*" — update this test/);
|
|
238
|
-
assert.throws(() => bullet("- **Edge A**\n- b\n", "- **Edge A**", "END", "the fixture"), /no longer contains "END" after "- \*\*Edge A\*\*"/);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// #2077: a restatement need not be a list item to escape the item. A paragraph
|
|
242
|
-
// after a blank line, or a heading, quote, fence or rule, written shallower than
|
|
243
|
-
// the item's content ends the item in markdown, so it ends the slice too —
|
|
244
|
-
// otherwise the claim gutted from the item and restated there stays green.
|
|
245
|
-
test("bullet ends the item at a shallower non-list block, not only at a sibling marker", () => {
|
|
246
|
-
const after = (block) => `intro\n- **Edge A** first line\n wraps here.\n${block}\nrestates the words\n\nEND`;
|
|
247
|
-
for (const block of ["\nPlain paragraph", "\n### Some other section", "### Some other section", "> quoted", "```", "~~~", "---", "***", " ## one-space heading"]) {
|
|
248
|
-
assert.equal(bullet(after(block), "- **Edge A**", "END", "the fixture"), "- **Edge A** first line\n wraps here.", block);
|
|
249
|
-
}
|
|
250
|
-
// Shallower than the CONTENT column is outside the item, even when deeper
|
|
251
|
-
// than its marker: one space under a `- ` item is not its paragraph.
|
|
252
|
-
assert.equal(bullet("- **Edge A** body\n\n Para at column one\nEND", "- **Edge A**", "END", "the fixture"), "- **Edge A** body");
|
|
253
|
-
// A nested item's paragraph-level peer belongs to the PARENT item.
|
|
254
|
-
assert.equal(bullet("1. step\n - **Item** body\n\n parent's paragraph\nEND", "- **Item**", "END", "the fixture"), "- **Item** body");
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
// The half the new bound can wrongly REFUSE: blocks written at the item's
|
|
258
|
-
// content column are the item's own, and a shallower plain line with no blank
|
|
259
|
-
// before it is a lazy continuation of the item's paragraph, which markdown
|
|
260
|
-
// renders inside the item.
|
|
261
|
-
test("bullet keeps the item's own paragraphs, blocks and lazy continuation lines", () => {
|
|
262
|
-
const own = "- **Edge A** body\nlazy continuation\n\n second paragraph\nlazy again\n\n > own quote\n ### own heading\n ```\n code\n\n more code\n ```\n- sibling\nEND";
|
|
263
|
-
assert.equal(
|
|
264
|
-
bullet(own, "- **Edge A**", "END", "the fixture"),
|
|
265
|
-
"- **Edge A** body\nlazy continuation\n\n second paragraph\nlazy again\n\n > own quote\n ### own heading\n ```\n code\n\n more code\n ```",
|
|
266
|
-
);
|
|
267
|
-
// The content column follows the marker's width and the gap after it — and
|
|
268
|
-
// a gap over 4 counts as 1, the rest being an indented code block.
|
|
269
|
-
assert.equal(bullet("10. **Item** body\n\n own paragraph\n11. next\nEND", "**Item**", "END", "the fixture"), "**Item** body\n\n own paragraph");
|
|
270
|
-
assert.equal(bullet("- **Item** code\n\n own paragraph\n- next\nEND", "**Item**", "END", "the fixture"), "**Item** code\n\n own paragraph");
|
|
271
|
-
// A tab-indented child of a space-indented item is still its child.
|
|
272
|
-
assert.equal(bullet("- **Edge A** body\n\t- tab child\n- sibling\nEND", "- **Edge A**", "END", "the fixture"), "- **Edge A** body\n\t- tab child");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
// #2077: the item line is the one `from`'s first non-whitespace character sits
|
|
276
|
-
// on, and the walk starts after `from`'s trailing whitespace. Read off `from`'s
|
|
277
|
-
// first CHARACTER, a leading-`\n` anchor measures the previous line; started at
|
|
278
|
-
// `from.length`, a trailing-`\n` anchor has already eaten the newline the next
|
|
279
|
-
// line's check needs. Each probe widened or narrowed the slice silently.
|
|
280
|
-
test("bullet measures the item from the anchor's text, not its surrounding newlines", () => {
|
|
281
|
-
assert.equal(bullet("- parent\n - **A** body\n - sibling\n- next\nEND", "\n - **A**", "END", "the fixture"), "\n - **A** body");
|
|
282
|
-
assert.equal(bullet("intro\n indented prose\n- **A** body\n - child\n- sib\nEND", "\n- **A**", "END", "the fixture"), "\n- **A** body\n - child");
|
|
283
|
-
assert.equal(bullet("- **A** body\n- sib\nEND", "- **A** body\n", "END", "the fixture"), "- **A** body\n");
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// #2077: indent is compared in visual columns, a tab advancing to the next
|
|
287
|
-
// multiple of 4 (CommonMark's tab stop). Counted in characters, a one-tab item
|
|
288
|
-
// read a two-space sibling as its own deeper child and kept it. The items sit
|
|
289
|
-
// under a parent item so CommonMark reads them as a list: after a plain `intro`
|
|
290
|
-
// line the tab item is continuation text of that paragraph, and after a blank
|
|
291
|
-
// line it is indented code.
|
|
292
|
-
test("bullet compares tab and space indentation by column, not by character count", () => {
|
|
293
|
-
assert.equal(bullet("- parent\n\t- **A** body\n - two-space sibling\n\t- **B**\nEND", "- **A**", "END", "the fixture"), "- **A** body");
|
|
294
|
-
// The tab puts this item's text at column 6; four spaces is 3 characters
|
|
295
|
-
// deeper than the tab by count, and still a sibling by column.
|
|
296
|
-
assert.equal(bullet("- parent\n\t- **A** body\n - four-space sibling\nEND", "- **A**", "END", "the fixture"), "- **A** body");
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// #2091 (hand-dispatched review, correctness): a marker with nothing after
|
|
300
|
-
// it on its own line — content on the next, indented line — is still a
|
|
301
|
-
// separate list item in CommonMark, not a lazy continuation of the item
|
|
302
|
-
// above it. `[ \t]` alone missed this shape; `(?:[ \t]|$)` catches the
|
|
303
|
-
// marker whether or not anything follows it on the same line.
|
|
304
|
-
test("bullet ends the item at a bare-marker sibling, with nothing after the marker on its own line", () => {
|
|
305
|
-
assert.equal(bullet("- **A** body\n-\n restated claim\nEND", "- **A**", "END", "the fixture"), "- **A** body");
|
|
306
|
-
assert.equal(bullet("- **A** body\n2.\n restated claim\nEND", "- **A**", "END", "the fixture"), "- **A** body");
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// #2091 (hand-dispatched review, correctness): a thematic break may space its
|
|
310
|
-
// repeated character out (CommonMark), not only run it together. `-`-spaced
|
|
311
|
-
// forms already end the item via ITEM_MARKER; `_`/`*` have no such fallback.
|
|
312
|
-
test("bullet ends the item at a spaced thematic break, not only a run-together one", () => {
|
|
313
|
-
assert.equal(bullet("- **A** body\n_ _ _\nafter\nEND", "- **A**", "END", "the fixture"), "- **A** body");
|
|
314
|
-
assert.equal(bullet("- **A** body\n* * *\nafter\nEND", "- **A**", "END", "the fixture"), "- **A** body");
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
// #2100: a line 4+ columns past the item's marker, with no blank line before
|
|
318
|
-
// it, cannot open a heading, quote, fence, break or list item there — it is
|
|
319
|
-
// lazy continuation of the item's paragraph. Reachable only when the content
|
|
320
|
-
// column is past marker column + 4 (a `100.` marker, or a 4-space gap). Every
|
|
321
|
-
// expected slice here was checked against the `commonmark` npm package (0.31).
|
|
322
|
-
test("bullet keeps a marker or interrupt line 4+ columns past the item's marker as lazy continuation", () => {
|
|
323
|
-
for (const [text, expected] of [
|
|
324
|
-
["100. **Item** body\n # x\nEND", "**Item** body\n # x\n"],
|
|
325
|
-
["- **Item** body\n # x\nEND", "**Item** body\n # x\n"],
|
|
326
|
-
["100. **Item** body\n ```x\nEND", "**Item** body\n ```x\n"],
|
|
327
|
-
["100. **Item** body\n > x\nEND", "**Item** body\n > x\n"],
|
|
328
|
-
["1. a\n 100. **Item** body\n # x\nEND", "**Item** body\n # x\n"],
|
|
329
|
-
["1. a\n\n 100. **Item** body\n # x\nEND", "**Item** body\n # x\n"],
|
|
330
|
-
["100. **Item** body\n - x\nEND", "**Item** body\n - x\n"],
|
|
331
|
-
["100. **Item** body\n\t# x\nEND", "**Item** body\n\t# x\n"],
|
|
332
|
-
]) {
|
|
333
|
-
assert.equal(bullet(text, "**Item**", "END", "the fixture"), expected, text);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// The half the #2100 cap must not wrongly KEEP: short of marker column + 4 the
|
|
338
|
-
// line still ends the item, and a blank line before it ends the item at any
|
|
339
|
-
// depth. Same commonmark check.
|
|
340
|
-
test("bullet still ends the item at a marker or interrupt line short of its marker column + 4, or after a blank line", () => {
|
|
341
|
-
for (const text of [
|
|
342
|
-
"100. **Item** body\n # x\nEND",
|
|
343
|
-
"1. a\n - b\n - **Item** body\n # x\nEND",
|
|
344
|
-
"1. a\n\n 100. **Item** body\n # x\nEND",
|
|
345
|
-
"100. **Item** body\n\n # x\nEND",
|
|
346
|
-
]) {
|
|
347
|
-
assert.equal(bullet(text, "**Item**", "END", "the fixture"), "**Item** body", text);
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
// A list-item anchor is a start anchor, never a "nearest" bound, so a second
|
|
352
|
-
// copy means the item would be read off whichever comes first.
|
|
353
|
-
test("bullet throws when the item anchor occurs more than once", () => {
|
|
354
|
-
assert.throws(() => bullet("- **A** one\n- **A** two\nEND", "- **A**", "END", "the fixture"), /the fixture: list-item anchor "- \*\*A\*\*" occurs 2 times/);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
// `\s+` between words, never a literal space: the prose these match against is
|
|
358
|
-
// hard-wrapped, so any inter-word space in the source may be a newline plus
|
|
359
|
-
// indent. Replacing the join with " " passes a single-line fixture and fails
|
|
360
|
-
// this one.
|
|
361
|
-
test("phrase matches a hard-wrapped phrase across a newline and indent", () => {
|
|
362
|
-
assert.match("a paragraph that refuses\n rather than passing, wrapped", phrase("refuses rather than passing"));
|
|
363
|
-
assert.match("tab-indented:\trefuses\n\t\trather than\n\tpassing", phrase(" refuses rather than passing "));
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
// Escaping is what keeps an anchor a LITERAL. Each negative assertion below is
|
|
367
|
-
// the whole point: unescaped, `(b)` is a capture group that matches "a b c",
|
|
368
|
-
// `.` matches any character, and `$` is an end-of-input anchor that matches
|
|
369
|
-
// nothing after it. Drop the escape and the regex silently matches text the
|
|
370
|
-
// anchor does not appear in — a pin that passes against the wrong prose.
|
|
371
|
-
test("phrase escapes regex metacharacters taken from its input", () => {
|
|
372
|
-
assert.match("call exit (2) now", phrase("exit (2)"));
|
|
373
|
-
assert.doesNotMatch("call exit 2 now", phrase("exit (2)"));
|
|
374
|
-
|
|
375
|
-
assert.match("pinned at v1.2 today", phrase("v1.2"));
|
|
376
|
-
assert.doesNotMatch("pinned at v1x2 today", phrase("v1.2"));
|
|
377
|
-
|
|
378
|
-
assert.match("costs $5 per run", phrase("costs $5"));
|
|
379
|
-
assert.doesNotMatch("costs 5 per run", phrase("costs $5"));
|
|
380
|
-
|
|
381
|
-
// `*` and `+` are quantifiers, and a leading one is a SyntaxError rather than
|
|
382
|
-
// a wrong match — so an unescaped anchor starting with either throws at
|
|
383
|
-
// construction instead of failing an assertion.
|
|
384
|
-
assert.doesNotThrow(() => phrase("*.mjs"));
|
|
385
|
-
assert.match("run node --test *.mjs here", phrase("*.mjs"));
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
// #1940: the shared sentence bound, at both of the ends the first-period
|
|
389
|
-
// `[^.]*` scan it replaced got wrong — it ran on past `?` and `!`, and it
|
|
390
|
-
// stopped at every period, a word's or an abbreviation's included. The
|
|
391
|
-
// closing marks are the case that scan happened to get right and a bare
|
|
392
|
-
// `[.!?]\s` split does not: a bold lead-in sentence, a shape run-team's
|
|
393
|
-
// SKILL.md uses throughout, would otherwise join the sentence after it.
|
|
394
|
-
test("sentences ends a sentence at `?` and `!`, and at a terminator behind closing marks", () => {
|
|
395
|
-
assert.deepEqual(sentences("Why pin now? It is late! Pin it."), ["Why pin now?", "It is late!", "Pin it."]);
|
|
396
|
-
assert.deepEqual(
|
|
397
|
-
sentences('**Pin first.** Then read. (Both run.) Next. "Say it." After. _Done._ End'),
|
|
398
|
-
["**Pin first.**", "Then read.", "(Both run.)", "Next.", '"Say it."', "After.", "_Done._", "End"],
|
|
399
|
-
);
|
|
400
|
-
// A hard wrap is whitespace like any other, so a rewrap moves no end.
|
|
401
|
-
assert.deepEqual(sentences("Pin it.\n Then\n read."), ["Pin it.", "Then\n read."]);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
test("sentences does not end one at an abbreviation, closing marks or not, nor at a period inside a word", () => {
|
|
405
|
-
for (const s of [
|
|
406
|
-
"Pin it, e.g. now, then read.",
|
|
407
|
-
"Pin it early (e.g.) and then read.",
|
|
408
|
-
"Pin it, i.e. first, cf. the rule, viz. step 0, vs. later.",
|
|
409
|
-
"Run instruments.sh at v1.2 first.",
|
|
410
|
-
]) {
|
|
411
|
-
assert.deepEqual(sentences(s), [s]);
|
|
412
|
-
}
|
|
413
|
-
// "etc." is deliberately off the list: it ends a sentence as often as not.
|
|
414
|
-
assert.deepEqual(sentences("Pin, read, etc. Then go."), ["Pin, read, etc.", "Then go."]);
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
// #1899: the abbreviations are matched lowercase only. Folded case, a sentence
|
|
418
|
-
// really ending in a word that shares their letters — a proper noun "Vs." —
|
|
419
|
-
// was read as the abbreviation and joined to the next, two real sentences one.
|
|
420
|
-
test("sentences ends one at a capitalized abbreviation lookalike, and still skips the lowercase abbreviation", () => {
|
|
421
|
-
for (const word of ["Vs.", "VS.", "E.g.", "E.G.", "I.e.", "Cf.", "CF.", "Viz.", "VIZ."]) {
|
|
422
|
-
assert.deepEqual(sentences(`Pin it for the ${word} Then read.`), [`Pin it for the ${word}`, "Then read."], word);
|
|
423
|
-
}
|
|
424
|
-
// The accept side, in the same fixture shape: lowercase stays one sentence.
|
|
425
|
-
for (const abbr of ["vs.", "e.g.", "i.e.", "cf.", "viz."]) {
|
|
426
|
-
const s = `Pin it for the ${abbr} Then read.`;
|
|
427
|
-
assert.deepEqual(sentences(s), [s], abbr);
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
// #2053: the guard before the abbreviation was a `\b`, which reads `_` as a
|
|
432
|
-
// word character, so an italic abbreviation ended its own sentence
|
|
433
|
-
// mid-abbreviation. Only a letter or digit glued on disqualifies one — the
|
|
434
|
-
// guard citation-sweep's SENTENCE_END and jsonCountFault's re-split carry.
|
|
435
|
-
test("sentences does not end one at an italic abbreviation, and still ends one at a word merely ending in its letters", () => {
|
|
436
|
-
for (const abbr of ["e.g.", "i.e.", "cf.", "viz.", "vs."]) {
|
|
437
|
-
const s = `Pin it, _${abbr}_ now, then read.`;
|
|
438
|
-
assert.deepEqual(sentences(s), [s], abbr);
|
|
439
|
-
}
|
|
440
|
-
for (const word of ["Xvs.", "26vs.", "gcf.", "Xe.g."]) {
|
|
441
|
-
assert.deepEqual(sentences(`Pin it for the ${word} Then read.`), [`Pin it for the ${word}`, "Then read."], word);
|
|
442
|
-
}
|
|
443
|
-
// The disclosed cost, in the same fixture shape as #1899's own accepted
|
|
444
|
-
// one above: a bare snake_case word ending in the abbreviation's letters —
|
|
445
|
-
// no italic markup, just an underscore glued on — now joins too. Locked in
|
|
446
|
-
// here so a future narrowing or widening of the guard cannot drift this
|
|
447
|
-
// cost silently.
|
|
448
|
-
for (const abbr of ["e.g.", "i.e.", "cf.", "viz.", "vs."]) {
|
|
449
|
-
const s = `Pin it for the snake_${abbr} Then read.`;
|
|
450
|
-
assert.deepEqual(sentences(s), [s], abbr);
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
// #1987: a footnote-style marker between a terminator and the whitespace
|
|
455
|
-
// after it — `.[1]`, `![note]`, `.[^1]`, a run of them — ended no sentence,
|
|
456
|
-
// so two real ones merged and a pin scoped to the first could borrow a word
|
|
457
|
-
// from the second. The marker stays with the sentence it annotates, a closing
|
|
458
|
-
// mark after it still counts, and whatever closes the word before the
|
|
459
|
-
// terminator — a letter in any script, a digit, a code span, a paren, a curly
|
|
460
|
-
// quote — lets it end one, whatever closed it. It still counts with combining
|
|
461
|
-
// marks on it (#2041): an NFD "é" is `e` + U+0301 and Devanagari "हिंदी" ends
|
|
462
|
-
// in the vowel sign U+0940, so the word's last code point is a mark, not a
|
|
463
|
-
// letter, and before the fix both merged.
|
|
464
|
-
test("sentences ends a sentence behind a footnote-style bracket marker", () => {
|
|
465
|
-
assert.deepEqual(
|
|
466
|
-
sentences("Pass `--quiet`; ci-state.mjs drops `jobs`.[1] Elsewhere, `missing` is unaffected."),
|
|
467
|
-
["Pass `--quiet`; ci-state.mjs drops `jobs`.[1]", "Elsewhere, `missing` is unaffected."],
|
|
468
|
-
);
|
|
469
|
-
for (const end of [
|
|
470
|
-
"late![note]",
|
|
471
|
-
"late?[^1]",
|
|
472
|
-
"late.[1][2]",
|
|
473
|
-
"late.[1])",
|
|
474
|
-
"late.[12]\u201d",
|
|
475
|
-
"late.[1]",
|
|
476
|
-
"(late).[1]",
|
|
477
|
-
"\u201clate\u201d.[1]",
|
|
478
|
-
"\u2018late\u2019.[1]",
|
|
479
|
-
"at 12.[1]",
|
|
480
|
-
"at the caf\u00e9.[1]",
|
|
481
|
-
"at the cafe\u0301.[1]",
|
|
482
|
-
"\u092f\u0939 \u0939\u093f\u0902\u0926\u0940.[1]",
|
|
483
|
-
"v\u1ec7.[1]",
|
|
484
|
-
"ve\u0323\u0302.[1]",
|
|
485
|
-
"at 1\u20e3.[1]",
|
|
486
|
-
]) {
|
|
487
|
-
assert.deepEqual(sentences(`Pin it ${end}\nThen read.`), [`Pin it ${end}`, "Then read."], end);
|
|
488
|
-
}
|
|
489
|
-
// #2041's own repros, verbatim.
|
|
490
|
-
assert.deepEqual(sentences("At the cafe\u0301.[1] Then read."), ["At the cafe\u0301.[1]", "Then read."]);
|
|
491
|
-
assert.deepEqual(
|
|
492
|
-
sentences("\u092f\u0939 \u0939\u093f\u0902\u0926\u0940.[1] Then read."),
|
|
493
|
-
["\u092f\u0939 \u0939\u093f\u0902\u0926\u0940.[1]", "Then read."],
|
|
494
|
-
);
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
// The accept side of #1987: a bracket only ends a sentence as a marker — one
|
|
498
|
-
// that holds something and no whitespace, straight behind a terminator that
|
|
499
|
-
// closes a word, with whitespace after it. Code quoted in prose carries the
|
|
500
|
-
// other shapes: a jq path or filter, an optional-chained index, a glob, an
|
|
501
|
-
// array index mid-sentence; and a link after a period is no marker either.
|
|
502
|
-
test("sentences does not end one at a bracket that is code, a link or an index, nor at an abbreviation's marker", () => {
|
|
503
|
-
for (const s of [
|
|
504
|
-
"Read `.[].number` from each, then stop.",
|
|
505
|
-
"Read `gh api -q '.[] | .name'` first, then stop.",
|
|
506
|
-
"Read `'.[0] | .x'` first, then stop.",
|
|
507
|
-
"Read `.jobs.[] | .name` first, then stop.",
|
|
508
|
-
"Read `.jobs.[0, 1] | .name` first, then stop.",
|
|
509
|
-
'Read `jq ".[0] | .x"` first, then stop.',
|
|
510
|
-
"Read `m?.[1] || null` first, then stop.",
|
|
511
|
-
"Read `git tag --list 'v[0-9]*.[0-9]*' | sort` first, then stop.",
|
|
512
|
-
"Read `jobs[1] and more` first, then stop.",
|
|
513
|
-
"Read it.[the docs](https://example.com) first, then stop.",
|
|
514
|
-
"Read it.[1]: first, then stop.",
|
|
515
|
-
"Read it, e.g.[1] first, then stop.",
|
|
516
|
-
// #2041: a combining mark only counts atop one of the bases above — one
|
|
517
|
-
// with no accepted base under it, straight after a space or another
|
|
518
|
-
// rejected character, closes no word, however many marks pile onto it.
|
|
519
|
-
"Read it \u0301.[1] first, then stop.",
|
|
520
|
-
"Read it,\u0301\u0302.[1] first, then stop.",
|
|
521
|
-
]) {
|
|
522
|
-
assert.deepEqual(sentences(s), [s], s);
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
// #1346/#1361/#1619: the `.mjs`-header-comment gutter shape, exercised by
|
|
527
|
-
// candidates-exit3-prose.test.mjs and review-core-unrun.test.mjs against a
|
|
528
|
-
// real header, but pinned here as its own dedicated guard: a guard with no
|
|
529
|
-
// dedicated test is a guard nobody is pinning.
|
|
530
|
-
test("stripSlashGutter strips a leading `// ` and leaves everything else untouched", () => {
|
|
531
|
-
assert.equal(stripSlashGutter("// dispatch it"), "dispatch it");
|
|
532
|
-
assert.equal(stripSlashGutter(" //no space after slash"), "no space after slash");
|
|
533
|
-
// A trailing comment is not a whole-line gutter — stripping mid-line
|
|
534
|
-
// would turn code-with-a-note into a false comment line.
|
|
535
|
-
assert.equal(stripSlashGutter('const x = 1; // not a comment line'), 'const x = 1; // not a comment line');
|
|
536
|
-
assert.equal(stripSlashGutter("plain code\nmore code"), "plain code\nmore code");
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
// `paragraph`'s two halves are its bound and its anchor, and each has its own
|
|
540
|
-
// false green. The bound: without the blank-line cut the slice runs to the end
|
|
541
|
-
// of the document and a decoy copy of the wording anywhere below satisfies the
|
|
542
|
-
// pin. The anchor: routed through `phrase()` rather than a literal `indexOf`,
|
|
543
|
-
// so a rewrap that the pinned clause survives does not red the pin — the
|
|
544
|
-
// false POSITIVE that a literal anchor introduces. Two throws keep the anchor
|
|
545
|
-
// honest: a moved one never widens the slice back to the whole file, and a
|
|
546
|
-
// duplicated one never binds the pin to the wrong copy.
|
|
547
|
-
test("paragraph cuts at the blank line, so a decoy below the rule cannot satisfy a pin", () => {
|
|
548
|
-
const doc = "intro\n\nTHE RULE says do X.\nstill the rule.\n\nlater prose.\n\na stray copy says do X.\n";
|
|
549
|
-
assert.equal(paragraph(doc, "THE RULE", "the fixture"), "THE RULE says do X.\nstill the rule.");
|
|
550
|
-
// The decoy is real: unbounded, the whole document contains the wording twice.
|
|
551
|
-
assert.doesNotMatch(paragraph("THE RULE says do Y.\n\na stray copy says do X.\n", "THE RULE", "the fixture"), phrase("do X"));
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
// The decoy above sits below a CLEAN blank line, so it passes both before and
|
|
555
|
-
// after the bound moved off the literal `\n\n` — it cannot see that
|
|
556
|
-
// regression. This one can: an editor keeping a list item's indent writes a
|
|
557
|
-
// blank line carrying whitespace, which `indexOf("\n\n")` does not find, and
|
|
558
|
-
// the slice then runs past the paragraph onto the decoy.
|
|
559
|
-
test("paragraph cuts at a blank line that carries whitespace", () => {
|
|
560
|
-
assert.doesNotMatch(paragraph("THE RULE says do Y.\n \na stray copy says do X.\n", "THE RULE", "the fixture"), phrase("do X"));
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
// The bound's mirror image: an anchor matching twice binds the pin to
|
|
564
|
-
// whichever copy comes first, so the real rule below can be gutted with the
|
|
565
|
-
// suite green.
|
|
566
|
-
test("paragraph throws when its anchor matches twice, rather than binding the wrong copy", () => {
|
|
567
|
-
assert.throws(
|
|
568
|
-
() => paragraph("THE RULE says do X.\n\nprose.\n\nTHE RULE says do X.\n", "THE RULE", "the fixture"),
|
|
569
|
-
/the fixture: slice anchor "THE RULE" occurs 2 times — a pin would bind the wrong copy; narrow the anchor/,
|
|
570
|
-
);
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
test("paragraph anchors reflow-safely — a hard-wrapped anchor still matches", () => {
|
|
574
|
-
const doc = "**a long anchor\n spanning a wrap** and the rule.\n\nnext.\n";
|
|
575
|
-
assert.match(paragraph(doc, "**a long anchor spanning a wrap**", "the fixture"), phrase("and the rule"));
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
test("paragraph throws when its anchor moved, rather than widening to the whole file", () => {
|
|
579
|
-
assert.throws(
|
|
580
|
-
() => paragraph("no anchor here\n\nGONE\n", "MISSING ANCHOR", "the fixture"),
|
|
581
|
-
/the fixture: slice anchor "MISSING ANCHOR" moved — re-anchor this test, never widen it to the whole file/,
|
|
582
|
-
);
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
// A document with no blank line at all is one paragraph, not a failure.
|
|
586
|
-
test("paragraph returns the remainder when the rule's block ends the document", () => {
|
|
587
|
-
assert.equal(paragraph("x\n\nTHE RULE ends here.", "THE RULE", "the fixture"), "THE RULE ends here.");
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
// `betweenPhrases`'s two halves are `paragraph`'s bound (an `anchorAt` start)
|
|
591
|
-
// and a phrase end instead of a blank line — so it has `paragraph`'s anchor
|
|
592
|
-
// false green (a moved or duplicated `from`) plus a matching pair on `to`:
|
|
593
|
-
// unbounded, a `to` reworded away and restated later silently widens the
|
|
594
|
-
// slice into whatever follows; duplicated inside `bound`, the slice binds
|
|
595
|
-
// the wrong copy. Extracted (#1611) from `finisher-dispatch-premise-prose
|
|
596
|
-
// .test.mjs`'s hand-rolled `dispatchPremise`.
|
|
597
|
-
test("betweenPhrases returns the slice bounded by a phrase start and a phrase end, from inclusive, to exclusive", () => {
|
|
598
|
-
const doc = "intro\nSTART here.\nmiddle text spans\n two lines.\nCUT it here.\nmore after.\n";
|
|
599
|
-
assert.equal(betweenPhrases(doc, "START here", "CUT it", "the fixture"), "START here.\nmiddle text spans\n two lines.\n");
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
test("betweenPhrases throws when the from anchor moved, rather than widening to the whole file", () => {
|
|
603
|
-
assert.throws(
|
|
604
|
-
() => betweenPhrases("no anchors here", "START here", "CUT it", "the fixture"),
|
|
605
|
-
/the fixture: slice anchor "START here" moved — re-anchor this test, never widen it to the whole file/,
|
|
606
|
-
);
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
test("betweenPhrases throws when the to phrase no longer occurs after the from anchor", () => {
|
|
610
|
-
assert.throws(
|
|
611
|
-
() => betweenPhrases("START here.\nno closing phrase follows.\n", "START here", "CUT it", "the fixture"),
|
|
612
|
-
/the fixture: slice end anchor "CUT it" moved — re-anchor this test, never widen it to the whole file/,
|
|
613
|
-
);
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
test("betweenPhrases throws when the to phrase occurs more than once, rather than binding the wrong copy", () => {
|
|
617
|
-
assert.throws(
|
|
618
|
-
() => betweenPhrases("START here.\nCUT it once.\nCUT it twice.\n", "START here", "CUT it", "the fixture"),
|
|
619
|
-
/the fixture: slice end anchor "CUT it" occurs 2 times — a pin would bind the wrong copy; narrow the anchor/,
|
|
620
|
-
);
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
// Same duplicate, but with a `bound` supplied — the message names the bound
|
|
624
|
-
// here because the caller gave one; the unbounded test above must NOT, or a
|
|
625
|
-
// bound-scoped failure and a whole-document failure read identically.
|
|
626
|
-
test("betweenPhrases throws when the to phrase occurs more than once inside the bound, naming the bound in the message", () => {
|
|
627
|
-
const doc = "START here.\nCUT it once.\nCUT it twice.\n---\nafter the bound.\n";
|
|
628
|
-
assert.throws(
|
|
629
|
-
() => betweenPhrases(doc, "START here", "CUT it", "the fixture", { bound: /\n---\n/ }),
|
|
630
|
-
/the fixture: slice end anchor "CUT it" occurs 2 times inside the bound — a pin would bind the wrong copy; narrow the anchor/,
|
|
631
|
-
);
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
// `bound` exists so a `to` reworded away cannot silently resolve to a LATER,
|
|
635
|
-
// unrelated copy past a structural boundary — the same false green `between`'s
|
|
636
|
-
// own header describes for an unbounded end anchor. Unbounded, this fixture's
|
|
637
|
-
// only copy of `to` sits past the boundary and the slice silently widens past
|
|
638
|
-
// it; bounded, that copy falls outside the search and the throw fires instead.
|
|
639
|
-
test("betweenPhrases: a bound stops the search there, rather than reaching a later copy of `to`", () => {
|
|
640
|
-
const doc = "START here.\nreal middle before bound.\n---\nCUT it after the bound.\n";
|
|
641
|
-
assert.throws(
|
|
642
|
-
() => betweenPhrases(doc, "START here", "CUT it", "the fixture", { bound: /\n---\n/ }),
|
|
643
|
-
/the fixture: slice end anchor "CUT it" lies past the end bound, which first matched at line 3 \("---"\)/,
|
|
644
|
-
);
|
|
645
|
-
assert.equal(
|
|
646
|
-
betweenPhrases(doc, "START here", "CUT it", "the fixture"),
|
|
647
|
-
"START here.\nreal middle before bound.\n---\n",
|
|
648
|
-
);
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
// A bound that matches BEFORE an intact `to` — here a wrap that put
|
|
652
|
-
// `3.` at column 0, which CommonMark renders as a new list item — used to
|
|
653
|
-
// report `slice end anchor "…" moved`, sending a reader after an edit to an
|
|
654
|
-
// anchor nobody touched. The anchor did not move; the bound did. Still a
|
|
655
|
-
// throw either way, so the message is the whole of the change: it names the
|
|
656
|
-
// line the bound first matched. A `to` found NOWHERE after `from` keeps
|
|
657
|
-
// "moved", and a `to` the bound cuts through the middle of counts as past it.
|
|
658
|
-
test("betweenPhrases names the bound's line, not a moved anchor, when the bound matches before an intact `to`", () => {
|
|
659
|
-
const doc = "1. START here, fix it and repeat from\n3. then CUT it here.\n4. the next item.\n";
|
|
660
|
-
const bound = /\n\d+\.\s/;
|
|
661
|
-
const pastBound = /the fixture: slice end anchor "(CUT it|from 3\. then)" lies past the end bound, which first matched at line 2 \("3\. then CUT it here\."\)/;
|
|
662
|
-
assert.throws(() => betweenPhrases(doc, "START here", "CUT it", "the fixture", { bound }), pastBound);
|
|
663
|
-
assert.throws(() => betweenPhrases(doc, "START here", "from 3. then", "the fixture", { bound }), pastBound);
|
|
664
|
-
assert.throws(
|
|
665
|
-
() => betweenPhrases(doc.replace("CUT it", "SNIP it"), "START here", "CUT it", "the fixture", { bound }),
|
|
666
|
-
/the fixture: slice end anchor "CUT it" moved — re-anchor this test, never widen it to the whole file/,
|
|
667
|
-
);
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
// The excerpt truncates a long bound-matched line rather than dumping it
|
|
671
|
-
// whole — every existing fixture in this bound-scoped family is short enough
|
|
672
|
-
// to pass through `line.length > 72` untouched, so nothing else in this
|
|
673
|
-
// suite would catch the threshold, or the truncate-with-ellipsis format,
|
|
674
|
-
// silently drifting or being dropped.
|
|
675
|
-
test("betweenPhrases truncates a long bound-matched line in its excerpt", () => {
|
|
676
|
-
const line2 =
|
|
677
|
-
"3. then CUT it here, followed by enough filler words to push this line well past seventy two characters total.";
|
|
678
|
-
const doc = `1. START here, fix it and repeat from\n${line2}\n4. the next item.\n`;
|
|
679
|
-
assert.throws(
|
|
680
|
-
() => betweenPhrases(doc, "START here", "CUT it", "the fixture", { bound: /\n\d+\.\s/ }),
|
|
681
|
-
/the fixture: slice end anchor "CUT it" lies past the end bound, which first matched at line 2 \("3\. then CUT it here, followed by enough filler words to push this line w…"\)/,
|
|
682
|
-
);
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
// Every bound above opens with `\n` and then a content character, so the
|
|
686
|
-
// named line is where that content sits. A bound made of line breaks — a
|
|
687
|
-
// blank line (`\n\n`), a whitespace-only line (`\n\s*\n`), a zero-width
|
|
688
|
-
// `^$` — has no content character to land on, and #2268 measured the message
|
|
689
|
-
// skipping past every blank line to the next paragraph's text, a line the
|
|
690
|
-
// bound never touched. The line named is the blank line itself: the match's
|
|
691
|
-
// leading `\n` terminates the text before the match and is skipped, but only
|
|
692
|
-
// that one.
|
|
693
|
-
test("betweenPhrases names the blank line a line-break bound matched, not the next paragraph's text", () => {
|
|
694
|
-
const pastBound = (line, excerpt) =>
|
|
695
|
-
new RegExp(`the fixture: slice end anchor "CUT it" lies past the end bound, which first matched at line ${line} \\("${excerpt}"\\)`);
|
|
696
|
-
const run = (doc, bound) => () => betweenPhrases(doc, "START here", "CUT it", "the fixture", { bound });
|
|
697
|
-
assert.throws(run("START here.\nmiddle.\n\n\n\nnext para, CUT it here.\n", /\n\n/), pastBound(3, ""));
|
|
698
|
-
assert.throws(run("START here.\nmiddle.\n \nnext para, CUT it here.\n", /\n\s*\n/), pastBound(3, " "));
|
|
699
|
-
assert.throws(run("START here.\nmiddle.\n\nnext para, CUT it here.\n", /^$/m), pastBound(3, ""));
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
// A `bound` that never matches the remaining text is a caller error, not an
|
|
703
|
-
// invitation to fall back to an unbounded search — that fallback is exactly
|
|
704
|
-
// the false green `bound` exists to prevent: a `to` reworded away could still
|
|
705
|
-
// be satisfied by an unrelated LATER decoy once the search reopens the whole
|
|
706
|
-
// document. This fixture's only `to` copy sits BEFORE where the bound would
|
|
707
|
-
// have been, so the old unbounded fallback would find it and return silently;
|
|
708
|
-
// the fix must throw instead, before ever searching for `to`.
|
|
709
|
-
test("betweenPhrases throws when the bound never matches, rather than silently searching the whole document", () => {
|
|
710
|
-
const doc = "START here.\nCUT it once.\n";
|
|
711
|
-
assert.throws(
|
|
712
|
-
() => betweenPhrases(doc, "START here", "CUT it", "the fixture", { bound: /\n---\n/ }),
|
|
713
|
-
/the fixture: end bound no longer matches after "START here" — re-anchor this test, never widen it to the whole document/,
|
|
714
|
-
);
|
|
715
|
-
});
|
|
716
|
-
|
|
717
|
-
// The "occurs more than once" assert is scoped to `bound`, not the whole rest
|
|
718
|
-
// of the document: a restatement of `to` PAST the bound must not count, or a
|
|
719
|
-
// pin could never pass once any later, unrelated copy of the same phrase
|
|
720
|
-
// exists anywhere below it. This fixture has exactly one `to` inside the
|
|
721
|
-
// bound and a second, decoy copy after it.
|
|
722
|
-
test("betweenPhrases does not count a `to` phrase restated past the bound as a duplicate", () => {
|
|
723
|
-
const doc = "START here.\nCUT it once.\n---\nCUT it again, but after the bound.\n";
|
|
724
|
-
assert.equal(
|
|
725
|
-
betweenPhrases(doc, "START here", "CUT it", "the fixture", { bound: /\n---\n/ }),
|
|
726
|
-
"START here.\n",
|
|
727
|
-
);
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
// `anchorAt` returns the offset where the anchor STARTS, not where it ends.
|
|
731
|
-
// `paragraph` slices forward from it, so either offset would look right there;
|
|
732
|
-
// `runAbove` slices BACKWARD from it to take the comment block above a
|
|
733
|
-
// declaration, and there the two are a whole anchor apart — an end offset
|
|
734
|
-
// would leave the anchor's own bytes at the tail of the slice, where they stop
|
|
735
|
-
// the `$`-bound run from matching and hand back "" on a comment that is
|
|
736
|
-
// present. Written here rather than left to either consumer, per this file's
|
|
737
|
-
// own header: a guard with no dedicated test is a guard nobody is pinning, and
|
|
738
|
-
// a consumer can stop needing the contract it happens to pin today.
|
|
739
|
-
test("anchorAt returns the offset where the anchor starts, not where it ends", () => {
|
|
740
|
-
assert.equal(anchorAt("pad\n\nTHE RULE says X.", "THE RULE", "the fixture"), 5);
|
|
741
|
-
});
|
|
742
|
-
|
|
743
|
-
// `runAbove` is the backward bound, for source files where `paragraph`'s blank
|
|
744
|
-
// line is the wrong cut: in source the blank line after a comment block sits
|
|
745
|
-
// BELOW the code the block documents, so a blank-line slice runs past the
|
|
746
|
-
// prose into live code. Its own two halves, each with its own false green. The
|
|
747
|
-
// bound: a run that did not stop at code would take an earlier comment block,
|
|
748
|
-
// or the code between, and a decoy in either satisfies the pin. The anchor:
|
|
749
|
-
// routed through `anchorAt`, so a restated declaration reds rather than
|
|
750
|
-
// handing back the comment above the wrong copy. Three consumer files
|
|
751
|
-
// hand-rolled this before #1604 and one of them is a `#` gutter, so the marker
|
|
752
|
-
// is a parameter and both dialects are exercised here.
|
|
753
|
-
test("runAbove takes the run immediately above the anchor, not an earlier one", () => {
|
|
754
|
-
const src = "// a decoy block\nconst other = 1;\n// the real block\n// still it\nconst TARGET = 2;\n";
|
|
755
|
-
assert.equal(runAbove(src, "const TARGET", "the fixture", "//"), "// the real block\n// still it\n");
|
|
756
|
-
});
|
|
757
|
-
|
|
758
|
-
// The ACCEPT side: a run this bound must not refuse. Shell gutter, indented
|
|
759
|
-
// run, an anchor carrying regex metacharacters — `reap.sh`'s own
|
|
760
|
-
// `gp_sep=$(printf '\002')`, which reaches the match only because `anchorAt`
|
|
761
|
-
// routes it through `phrase()` — and an INDENTED ANCHOR, the case every
|
|
762
|
-
// hand-rolled copy refused before #1604: their run ended at `$`, so text
|
|
763
|
-
// ending in the declaration's own indent matched nothing and the caller was
|
|
764
|
-
// told the comment was gone. The expected value pins the other half of that
|
|
765
|
-
// fix: the indent is tolerated, never returned as part of the run.
|
|
766
|
-
test("runAbove accepts an indented `#` run below an indented anchor", () => {
|
|
767
|
-
const sh = "setup() {\n # the note\n # and its second line\n gp_sep=$(printf '\\002')\n}\n";
|
|
768
|
-
assert.equal(runAbove(sh, "gp_sep=$(printf '\\002')", "the fixture", "#"), " # the note\n # and its second line\n");
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
// #1622: the mirror of the indented-anchor case above, but on the SAME line
|
|
772
|
-
// as the anchor rather than beneath it. `const TARGET` anchors inside
|
|
773
|
-
// `export const TARGET = 2;`, so the text ending right before the anchor is
|
|
774
|
-
// `"...export "` — not whitespace — and the old `[ \t]*$` tail could not
|
|
775
|
-
// match, handing back "" with the comment sitting right there. The expected
|
|
776
|
-
// value pins the fix: the keyword prefix is tolerated, never returned as
|
|
777
|
-
// part of the run.
|
|
778
|
-
test("runAbove accepts a same-line keyword prefix before the anchor", () => {
|
|
779
|
-
const src = "// doc\n// still\nexport const TARGET = 2;\n";
|
|
780
|
-
assert.equal(runAbove(src, "const TARGET", "the fixture", "//"), "// doc\n// still\n");
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
// #1622: the tail bound's keyword-chain tolerance is `)*$`, not `)?$` — the
|
|
784
|
-
// PR's own rationale names multi-keyword prefixes like `export default async
|
|
785
|
-
// function` and `export abstract class` as the intended case, not just a
|
|
786
|
-
// single modifier. A narrowed quantifier that only tolerated one token would
|
|
787
|
-
// still pass the single-keyword fixture above while silently regressing
|
|
788
|
-
// this one.
|
|
789
|
-
test("runAbove accepts a same-line chain of multiple keyword prefixes", () => {
|
|
790
|
-
const src = "// doc\n// still\nexport default async function TARGET() {}\n";
|
|
791
|
-
assert.equal(runAbove(src, "TARGET", "the fixture", "//"), "// doc\n// still\n");
|
|
792
|
-
});
|
|
793
|
-
|
|
794
|
-
// #1622: `DECLARATION_PREFIX_KEYWORDS` is a closed, bounded list, not
|
|
795
|
-
// arbitrary text tolerated before the anchor. A same-line token that is not
|
|
796
|
-
// one of the declaration/modifier keywords must still refuse the run, or
|
|
797
|
-
// the guard this PR advertises is unenforced and any prefix would slip
|
|
798
|
-
// through.
|
|
799
|
-
test("runAbove refuses a same-line prefix that is not a declaration keyword", () => {
|
|
800
|
-
const src = "// doc\n// still\nsomeCode TARGET = 2;\n";
|
|
801
|
-
assert.equal(runAbove(src, "TARGET", "the fixture", "//"), "");
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
// Empty, never a throw: `gp-sep-invariant-prose.test.mjs` slices at module load
|
|
805
|
-
// and names the empty case in a test of its own, which an import-time throw
|
|
806
|
-
// would pre-empt. Three shapes here return "" — plain code, code carrying
|
|
807
|
-
// the marker MID-LINE (which is the one that would quietly swallow a line and
|
|
808
|
-
// a decoy in it if the gutter were matched anywhere but at a line's start),
|
|
809
|
-
// and a comment block separated from the anchor by a blank line: the `$`
|
|
810
|
-
// bound is `[ \t]*$`, not `\s*$`, so a blank line between the block and the
|
|
811
|
-
// declaration is not adjacency and the block is not adopted.
|
|
812
|
-
test('runAbove returns "" when nothing but code sits above the anchor', () => {
|
|
813
|
-
assert.equal(runAbove("const other = 1;\nconst TARGET = 2;\n", "const TARGET", "the fixture", "//"), "");
|
|
814
|
-
assert.equal(runAbove('// a decoy\nconst u = "http://x";\nconst TARGET = 2;\n', "const TARGET", "the fixture", "//"), "");
|
|
815
|
-
assert.equal(runAbove("// the doc block\n\nconst TARGET = 2;\n", "const TARGET", "the fixture", "//"), "");
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
// The other half of the run's start bound: `(?:^|\n)` also matches at the
|
|
819
|
-
// absolute start of the sliced text, for a comment block with nothing above
|
|
820
|
-
// it — not just mid-document, preceded by a newline.
|
|
821
|
-
test("runAbove takes a comment block that starts at the beginning of the text", () => {
|
|
822
|
-
assert.equal(runAbove("// only comment\nconst TARGET = 2;\n", "const TARGET", "the fixture", "//"), "// only comment\n");
|
|
823
|
-
});
|
|
824
|
-
|
|
825
|
-
// The half `anchorAt` owns, asserted through this caller because a slicer that
|
|
826
|
-
// took the FIRST hit would look right on every fixture above.
|
|
827
|
-
test("runAbove throws when the anchor matches twice, rather than taking the comment above the wrong copy", () => {
|
|
828
|
-
assert.throws(
|
|
829
|
-
() => runAbove("// the real block\nconst TARGET = 2;\n\n// a restatement\nconst TARGET = 3;\n", "const TARGET", "the fixture", "//"),
|
|
830
|
-
/the fixture: slice anchor "const TARGET" occurs 2 times — a pin would bind the wrong copy; narrow the anchor/,
|
|
831
|
-
);
|
|
832
|
-
});
|
|
833
|
-
|
|
834
|
-
// The marker is a LITERAL. Unescaped, a `+` gutter is a quantifier with
|
|
835
|
-
// nothing to repeat, and the RegExp constructor throws rather than handing
|
|
836
|
-
// back the block above the anchor. This pins marker-escaping only —
|
|
837
|
-
// `runAbove` has no `/* ... */` block-comment dialect; every live gutter in
|
|
838
|
-
// this repo is `#` or `//`.
|
|
839
|
-
test("runAbove escapes the marker, so a gutter carrying a regex metacharacter still matches literally", () => {
|
|
840
|
-
const src = "const other = 1;\n+ the block\n+ still it\nconst TARGET = 2;\n";
|
|
841
|
-
assert.equal(runAbove(src, "const TARGET", "the fixture", "+"), "+ the block\n+ still it\n");
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
// An empty marker is not a narrower gutter — it is no gutter at all, and the
|
|
845
|
-
// regex above would match every line above the anchor, comment or not. That
|
|
846
|
-
// silent total widening is worse than a throw, so runAbove refuses it up front.
|
|
847
|
-
test("runAbove throws on an empty marker, rather than silently matching every line above the anchor", () => {
|
|
848
|
-
assert.throws(
|
|
849
|
-
() => runAbove("some prose line\nanother arbitrary line\nconst TARGET = 2;\n", "const TARGET", "the fixture", ""),
|
|
850
|
-
/the fixture: runAbove needs a non-empty marker/,
|
|
851
|
-
);
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
// `quoteBlocks` and `quoteBlock` are the bound a whole-block golden fixture
|
|
855
|
-
// needs (#1002), and the one thing they must never do is what every slicer in
|
|
856
|
-
// this directory did before them: return a slice that is not exactly one block.
|
|
857
|
-
// Fixtures here are short literal strings for this file's standing reason —
|
|
858
|
-
// pinning them against `run-team/SKILL.md` would re-couple them to whatever that
|
|
859
|
-
// file's blocks say today.
|
|
860
|
-
const QUOTED = "intro\n\n> first block, line one\n> line two\n>\n> second paragraph, same block\n\nprose between\n\n> second block\n\ntail";
|
|
861
|
-
|
|
862
|
-
// A blank quote line continues the block; a line with no gutter ends it. Both
|
|
863
|
-
// halves matter to a golden: the first decides whether a two-paragraph block is
|
|
864
|
-
// one fixture or two, and the second is the whole reason a block spliced in
|
|
865
|
-
// after this one cannot be absorbed into its slice.
|
|
866
|
-
test("quoteBlocks returns each maximal quote run, and a bare `>` line does not split one", () => {
|
|
867
|
-
assert.deepEqual(quoteBlocks(QUOTED), [
|
|
868
|
-
"> first block, line one\n> line two\n>\n> second paragraph, same block",
|
|
869
|
-
"> second block",
|
|
870
|
-
]);
|
|
871
|
-
});
|
|
872
|
-
|
|
873
|
-
// Nothing before the first quote line and nothing after the last may leak in: an
|
|
874
|
-
// unquoted line inside the slice is text the controller does not carry, so a
|
|
875
|
-
// fixture holding one would be blessing prose the member never sees.
|
|
876
|
-
test("quoteBlocks returns no unquoted line, including at a run that ends the text", () => {
|
|
877
|
-
assert.deepEqual(quoteBlocks("> only\nprose"), ["> only"]);
|
|
878
|
-
assert.deepEqual(quoteBlocks("prose\n> last"), ["> last"]);
|
|
879
|
-
});
|
|
880
|
-
|
|
881
|
-
// The identifier names the block by what it BEGINS with. A later block that
|
|
882
|
-
// merely contains the same words is the copy a `text.indexOf(opener)` bound
|
|
883
|
-
// would have taken — this is the assertion that keeps `quoteBlock` from being
|
|
884
|
-
// that bound with extra steps.
|
|
885
|
-
test("quoteBlock returns the run that BEGINS with the opener, never one that merely contains it", () => {
|
|
886
|
-
const text = "> a rule about stashing\n\n> never stash: a rule about stashing is above";
|
|
887
|
-
assert.equal(quoteBlock(text, "never stash", "the fixture"), "> never stash: a rule about stashing is above");
|
|
888
|
-
// The case above never exercises the `^` anchor: "never stash" is not a
|
|
889
|
-
// substring of the non-matching block at all, so an unanchored
|
|
890
|
-
// `new RegExp(phrase(opener).source)` would pass it exactly as the anchored
|
|
891
|
-
// form does. This puts the opener MID-block instead, where only the `^`
|
|
892
|
-
// anchor tells the two regexes apart.
|
|
893
|
-
assert.throws(
|
|
894
|
-
() => quoteBlock("> intro sentence never stash mid-block words", "never stash", "the fixture"),
|
|
895
|
-
/no quote block opens/,
|
|
896
|
-
);
|
|
897
|
-
});
|
|
898
|
-
|
|
899
|
-
// Reflow-safe for `paragraph`'s reason, one bound over: an opener that the
|
|
900
|
-
// source has wrapped is still that block's opener, and a literal `indexOf`
|
|
901
|
-
// would throw "block deleted" on a reflow the block survived intact.
|
|
902
|
-
test("quoteBlock finds a block whose opener is hard-wrapped across two lines", () => {
|
|
903
|
-
assert.equal(quoteBlock("> Read the\n> issue first\n> and only then", "Read the issue first", "the fixture"), "> Read the\n> issue first\n> and only then");
|
|
904
|
-
});
|
|
905
|
-
|
|
906
|
-
// The two throws, and the false green each one denies. A golden mechanism whose
|
|
907
|
-
// extractor returns "" for a block it cannot find compares nothing against
|
|
908
|
-
// nothing and a DELETED block passes; one that returns the first of two takes
|
|
909
|
-
// the decoy and lets the real block be gutted.
|
|
910
|
-
test("quoteBlock throws when no block opens on the identifier, rather than returning nothing", () => {
|
|
911
|
-
assert.throws(
|
|
912
|
-
() => quoteBlock("> some other rule\n\nRead the issue first — unquoted now", "Read the issue first", "the fixture"),
|
|
913
|
-
/the fixture: no quote block opens on "Read the issue first"/,
|
|
914
|
-
);
|
|
915
|
-
});
|
|
916
|
-
|
|
917
|
-
test("quoteBlock throws when two blocks open on the identifier, rather than binding the first", () => {
|
|
918
|
-
assert.throws(
|
|
919
|
-
() => quoteBlock("> Read the issue first\n\n> Read the issue first, again", "Read the issue first", "the fixture"),
|
|
920
|
-
/the fixture: 2 quote blocks open on "Read the issue first"/,
|
|
921
|
-
);
|
|
922
|
-
});
|
|
923
|
-
|
|
924
|
-
// #1609. `logicalLines` exists for the pins that DERIVE their subjects from a
|
|
925
|
-
// document rather than look for words they already know, and every fixture
|
|
926
|
-
// below is a single-line scan of the shape that forced it —
|
|
927
|
-
// `see \*\*([^*\n]+)\*\*`, whose literal space and `\n`-free class are both
|
|
928
|
-
// load-bearing and both defeated by a wrap the reader cannot see.
|
|
929
|
-
const SEE = /see \*\*([^*\n]+)\*\*/g;
|
|
930
|
-
const names = (s) => [...s.matchAll(SEE)].map((m) => m[1]);
|
|
931
|
-
|
|
932
|
-
test("logicalLines joins a paragraph's wrapped lines and stops at the paragraph bound", () => {
|
|
933
|
-
assert.deepEqual(names("see\n**Target**"), []);
|
|
934
|
-
assert.deepEqual(names(logicalLines("see\n**Target**").text), ["Target"]);
|
|
935
|
-
// The bound, and the false green losing it buys: a `see` ending one
|
|
936
|
-
// paragraph would bind the `**Bold**` opening the NEXT one, and the scan
|
|
937
|
-
// would report a pointer clause the document does not contain.
|
|
938
|
-
assert.equal(logicalLines("tail see\n\n**Other**").text, "tail see\n\n**Other**");
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
test("logicalLines rejoins on exactly one space, whatever indent and trailing space the wrap left", () => {
|
|
942
|
-
// Both trims matter to a literal-space scan and neither is visible in a
|
|
943
|
-
// rendered document: the continuation's indent on one side, the trailing
|
|
944
|
-
// whitespace an editor leaves behind on the other. Either one surviving
|
|
945
|
-
// puts two spaces after `see` and the clause stops matching.
|
|
946
|
-
assert.equal(logicalLines("see\n **Target**").text, "see **Target**");
|
|
947
|
-
assert.equal(logicalLines("see \n**Target**").text, "see **Target**");
|
|
948
|
-
// A tab is whitespace an editor leaves, not markdown's hard break, so this
|
|
949
|
-
// joins — `HARD_BREAK` is two SPACES, and the test above it holds that half.
|
|
950
|
-
assert.equal(logicalLines("see \t\n\t **Target**").text, "see **Target**");
|
|
951
|
-
});
|
|
952
|
-
|
|
953
|
-
test("lineAt answers the PHYSICAL line a hit in the joined view came from", () => {
|
|
954
|
-
// The whole reason the joined text is returned with a mapper rather than
|
|
955
|
-
// alone: a pin that reports an offset into the joined copy names a line
|
|
956
|
-
// number no reader can open. One-based, like an editor and like `grep -n`.
|
|
957
|
-
const { text, lineAt } = logicalLines("# Heading\n\nfirst para\nwrapped on\nthree lines\n\nsee\n**Target**");
|
|
958
|
-
assert.equal(lineAt(text.indexOf("# Heading")), 1);
|
|
959
|
-
assert.equal(lineAt(text.indexOf("first para")), 3);
|
|
960
|
-
assert.equal(lineAt(text.indexOf("wrapped on")), 4);
|
|
961
|
-
assert.equal(lineAt(text.indexOf("three lines")), 5);
|
|
962
|
-
assert.equal(lineAt(text.indexOf("**Target**")), 8);
|
|
963
|
-
// The bisect's tie: an offset landing exactly ON a line's first character
|
|
964
|
-
// answers that line, never the one before or after it.
|
|
965
|
-
assert.equal(lineAt(0), 1);
|
|
966
|
-
assert.equal(lineAt(text.length - 1), 8);
|
|
967
|
-
});
|
|
968
|
-
|
|
969
|
-
test("lineAt throws on an offset outside the joined view, rather than clamping it", () => {
|
|
970
|
-
// A clamp returns a plausible-looking WRONG line number for a caller's own
|
|
971
|
-
// bug — the same silent-wide-match failure `between`, `anchorAt` and
|
|
972
|
-
// `quoteBlock` all refuse elsewhere in this file, by throwing instead of
|
|
973
|
-
// guessing. `lineAt` only ever receives an offset a match on `text`
|
|
974
|
-
// actually produced, so anything outside `[0, text.length)` is a defect
|
|
975
|
-
// at the call site, not a document to open.
|
|
976
|
-
const { lineAt } = logicalLines("a\nb\nc");
|
|
977
|
-
assert.throws(() => lineAt(-5), /out of range/);
|
|
978
|
-
assert.throws(() => lineAt(9999), /out of range/);
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
test("logicalLines never joins a line the reader sees as a new block", () => {
|
|
982
|
-
// Joining only ever ADDS matches, so every one of these is a potential
|
|
983
|
-
// pointer clause invented out of two unrelated blocks. A heading, a list
|
|
984
|
-
// item, a blockquote, a table row and a thematic break each terminate their
|
|
985
|
-
// predecessor on the page, so each must terminate it here.
|
|
986
|
-
for (const next of ["## Heading", "- item", "* item", "+ item", "3. item", "> quoted", "| cell |", "---", "```js"]) {
|
|
987
|
-
assert.equal(logicalLines(`see\n${next}`).text, `see\n${next}`, `joined a new block: ${next}`);
|
|
988
|
-
}
|
|
989
|
-
});
|
|
990
|
-
|
|
991
|
-
test("logicalLines continues a list item but never a heading or a thematic break", () => {
|
|
992
|
-
// The asymmetry, and the reason there are two regexes rather than one. A
|
|
993
|
-
// list item and a blockquote take lazy continuation lines — that is where
|
|
994
|
-
// the #1609 pointers actually live, inside a wrapped numbered step — while
|
|
995
|
-
// a heading and a thematic break are complete on their own line. Collapsing
|
|
996
|
-
// the two sets either loses every list-item wrap or swallows the paragraph
|
|
997
|
-
// under a heading into the heading itself.
|
|
998
|
-
assert.equal(logicalLines("1. step see\n **Target**").text, "1. step see **Target**");
|
|
999
|
-
assert.equal(logicalLines("- step see\n **Target**").text, "- step see **Target**");
|
|
1000
|
-
assert.equal(logicalLines("> quoted see\n> more").text, "> quoted see\n> more");
|
|
1001
|
-
assert.equal(logicalLines("# Heading\nbody").text, "# Heading\nbody");
|
|
1002
|
-
assert.equal(logicalLines("---\ndescription: x").text, "---\ndescription: x");
|
|
1003
|
-
});
|
|
1004
|
-
|
|
1005
|
-
test("logicalLines leaves fenced code exactly as written", () => {
|
|
1006
|
-
// A wrap inside prose is not semantic; a line break inside code is. Joining
|
|
1007
|
-
// a fenced block would hand any pin scanning code through this view a single
|
|
1008
|
-
// line that no shell, and no reader, would recognise.
|
|
1009
|
-
const fence = "prose see\n\n```sh\nfirst --flag\nsecond --flag\n```\n\nmore prose";
|
|
1010
|
-
assert.equal(logicalLines(fence).text, fence);
|
|
1011
|
-
});
|
|
1012
|
-
|
|
1013
|
-
test("logicalLines keeps an authored hard line break", () => {
|
|
1014
|
-
// Two trailing spaces and a trailing backslash are markdown's line break —
|
|
1015
|
-
// the author asked for it, so it is not a wrap point to undo.
|
|
1016
|
-
assert.equal(logicalLines("see \n**Target**").text, "see \n**Target**");
|
|
1017
|
-
assert.equal(logicalLines("see\\\n**Target**").text, "see\\\n**Target**");
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
test("logicalLines keeps a block-leading span at column 0 and takes a wrap-leading one off it", () => {
|
|
1021
|
-
// The mirror direction, and the silent one. A `/^\*\*/m` scan means "leads a
|
|
1022
|
-
// block", and on raw bytes a reflow that happens to push a mid-paragraph
|
|
1023
|
-
// bold to column 0 mints a target the author never wrote — so a pointer
|
|
1024
|
-
// resolves to a block the wrap invented and the pin passes for free.
|
|
1025
|
-
const lead = /^\*\*([^*\n]+)\*\*/gm;
|
|
1026
|
-
const wrapped = "a sentence ending here\n**Not A Block** but mid-paragraph prose";
|
|
1027
|
-
assert.deepEqual([...wrapped.matchAll(lead)].map((m) => m[1]), ["Not A Block"]);
|
|
1028
|
-
assert.deepEqual([...logicalLines(wrapped).text.matchAll(lead)].map((m) => m[1]), []);
|
|
1029
|
-
// And the half that must still be ACCEPTED: a span that genuinely opens its
|
|
1030
|
-
// block stays at column 0 even when the rest of that block is wrapped, so
|
|
1031
|
-
// tightening `^` this way costs no real target.
|
|
1032
|
-
const real = "**A Real Block** whose own paragraph\nwraps onto a second line";
|
|
1033
|
-
assert.deepEqual([...logicalLines(real).text.matchAll(lead)].map((m) => m[1]), ["A Real Block"]);
|
|
1034
|
-
});
|