Download this file
| 1 | // The editor's port reads every line in time linear in its length |
| 2 | // (Fable round 3, L8, and round 2's M1): the shapes that made it |
| 3 | // quadratic each read in well under the bound here. |
| 4 | import { test } from 'node:test' |
| 5 | import assert from 'node:assert/strict' |
| 6 | import { spans } from './markup.mjs' |
| 7 | |
| 8 | const shapes = { |
| 9 | 'image openers': '', |
| 10 | 'shared link address': '[x]('.repeat(25000) + 'a)', |
| 11 | 'shared web address': '[x](http://e.com/'.repeat(25000) + 'a)' |
| 12 | } |
| 13 | |
| 14 | for (const [name, text] of Object.entries(shapes)) { |
| 15 | test(`a line of ${name} reads in linear time`, () => { |
| 16 | const started = performance.now() |
| 17 | spans(text) |
| 18 | const took = performance.now() - started |
| 19 | assert.ok(took < 2000, `${name} took ${Math.round(took)} ms`) |
| 20 | }) |
| 21 | } |
| 22 | |