3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

Answer prose round 1: 0 🔴, 3 🟡 (0 misread); the destinationEnds comment names a stop and the stack, the changelog entry says neither escaped nor closed, the test name says where the paren is open

This commit is contained in:
2026-10-28 13:12:57 +01:00
committed by Lillem4n
parent fda02e9acb
commit becd7d8d4e
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ test('an unbracketed destination ends at its first unmatched `)`', () => {
assert.deepEqual(targets('[a](b\\)c)'), [{ destination: 'b)c', length: 6 }])
})
test('a destination holding an unbalanced unescaped `(` at a space or the end reads as none', () => {
test('an unbracketed destination with an unescaped `(` still open where it stops reads as none', () => {
assert.deepEqual(targets('[a](b(c "t")'), [undefined])
assert.deepEqual(targets('[a](b(c "t") [d](e)'), [undefined, { destination: 'e', length: 3 }])
assert.deepEqual(targets('[a](b(c) "t")'), [{ destination: 'b(c)', length: 10, title: 't' }])
+1 -1
View File
@@ -72,7 +72,7 @@ export function targetMemo(text: string): TargetMemo {
return { destinationEnds: undefined, tails: new Map(), text }
}
// `ends[start]` is where an unbracketed destination from `start` stops, filled in one pass for every start a target can have: just after a `(`, a space or a control character, and 0, where `readDestination`'s run begins. At a stop only the innermost open start has its parentheses balanced, so the starts below it keep no end.
// `ends[start]` is where an unbracketed destination from `start` stops, for every start a target can have: just after a `(`, a space or a control character, and 0, where `readDestination`'s run begins. A destination stops at a space, a control character or the end of the text. Of the starts on the `open` stack only the innermost has its parentheses balanced there, so every start below it keeps 0, which reads as no destination.
function destinationEnds(text: string): Int32Array {
const ends = new Int32Array(text.length + 1)
let open = [0]