import assert from 'node:assert/strict';
import { test } from 'node:test';
import { parseCode } from '../src/lib/code.ts';

test('splits inline code', () => {
  assert.deepEqual(parseCode('run `ls -l` now'), [
    { kind: 'text', text: 'run ' },
    { kind: 'inline', text: 'ls -l' },
    { kind: 'text', text: ' now' }
  ]);
});

test('parses fenced blocks with language', () => {
  assert.deepEqual(parseCode('see\n```rust\nfn main() {}\n```\nok'), [
    { kind: 'text', text: 'see\n' },
    { kind: 'block', text: 'fn main() {}', lang: 'rust' },
    { kind: 'text', text: 'ok' }
  ]);
});

test('backticks inside a block stay literal', () => {
  assert.deepEqual(parseCode('```\na `b` c\n```'), [{ kind: 'block', text: 'a `b` c', lang: null }]);
});

test('unclosed backtick is text', () => {
  assert.deepEqual(parseCode('a ` b'), [{ kind: 'text', text: 'a ` b' }]);
});

