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

Read and write unclosed backtick runs and HTML openers in time linear in the text

This commit is contained in:
2026-10-18 10:41:02 +02:00
committed by Lillem4n
parent ba15ca84b9
commit e12249e593
9 changed files with 138 additions and 35 deletions
@@ -0,0 +1,24 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { backtickRuns, closingRun } from './backtick-runs.ts'
test('a code span closes on the first later run of exactly its opener length', () => {
const runs = backtickRuns('`a``b```c`')
assert.equal(closingRun(runs, 1, 1), 9)
assert.equal(closingRun(runs, 1, 2), 2)
assert.equal(closingRun(runs, 1, 3), 5)
assert.equal(closingRun(runs, 1, 4), undefined)
})
test('a run before the opener closes nothing', () => {
const runs = backtickRuns('``a``b')
assert.equal(closingRun(runs, 2, 2), 3)
assert.equal(closingRun(runs, 5, 2), undefined)
})
test('an ask from earlier in the text than the last finds the earlier closer', () => {
const runs = backtickRuns('`a`b`c`')
assert.equal(closingRun(runs, 5, 1), 6)
assert.equal(closingRun(runs, 1, 1), 2)
})