df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 1 | import assert from 'node:assert/strict'; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 2 | import { test } from 'node:test'; |
6d6a4c34bdc1 | atagen | 2026-10-24 06:51 UTC | 3 | import { parseCode } from '../src/lib/code.ts'; |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 4 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 5 | test('splits inline code', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 6 | assert.deepEqual(parseCode('run `ls -l` now'), [ |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 7 | { kind: 'text', text: 'run ' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 8 | { kind: 'inline', text: 'ls -l' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 9 | { kind: 'text', text: ' now' } |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 10 | ]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 11 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 12 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 13 | test('parses fenced blocks with language', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 14 | assert.deepEqual(parseCode('see\n```rust\nfn main() {}\n```\nok'), [ |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 15 | { kind: 'text', text: 'see\n' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 16 | { kind: 'block', text: 'fn main() {}', lang: 'rust' }, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 17 | { kind: 'text', text: 'ok' } |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 18 | ]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 19 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 20 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 21 | test('backticks inside a block stay literal', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 22 | assert.deepEqual(parseCode('```\na `b` c\n```'), [{ kind: 'block', text: 'a `b` c', lang: null }]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 23 | }); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 24 | |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 25 | test('unclosed backtick is text', () => { |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 26 | assert.deepEqual(parseCode('a ` b'), [{ kind: 'text', text: 'a ` b' }]); |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 27 | }); |