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