import test from 'node:test' import assert from 'node:assert/strict' import { sliceDocument, applySelectedSuggestion, repoAndPath, statusText } from '../dist/logic.js' test('slices at the cursor', () => { const s = sliceDocument('abc\ndef', 5, 1000, 1000) assert.deepEqual(s, { prefix: 'abc\nd', suffix: 'ef', prefixLineOffset: 0 }) }) test('large prefixes are cut at a stable line chunk', () => { const doc = Array.from({ length: 2000 }, (_, i) => `line ${i}`).join('\n') const a = sliceDocument(doc, doc.length - 5, 5000, 100, 256) const b = sliceDocument(doc, doc.length - 2, 5000, 100, 256) // typed 3 more chars assert.equal(a.prefixLineOffset % 256, 0) assert.equal(a.prefixLineOffset, b.prefixLineOffset) assert.ok(a.prefix.startsWith(`line ${a.prefixLineOffset}\n`)) assert.ok(a.prefix.length <= 5000 + 20 * 256) }) test('suffix is cut at a line boundary', () => { const s = sliceDocument('x' + '\nabcdef'.repeat(10), 1, 1000, 15) assert.ok(s.suffix.endsWith('\n')) }) test('selected IntelliSense item is treated as typed', () => { const r = applySelectedSuggestion('this.conn', 5, 9, 'connections') assert.deepEqual(r, { text: 'this.connections', cursorOffset: 16 }) }) test('repo/path normalisation', () => { assert.deepEqual(repoAndPath('wrapped.cash', 'src\\a\\b.ts', '/x/src/a/b.ts'), { repo: 'wrapped.cash', path: 'src/a/b.ts' }) assert.deepEqual(repoAndPath(undefined, '', '/tmp/scratch.ts'), { repo: 'untitled', path: 'scratch.ts' }) }) test('status text', () => { assert.match(statusText({ enabled: true, mode: 'symbols', effectiveMode: 'simple', model: 'stage-c' }, 41.6), /symbols→simple · 42 ms/) assert.match(statusText(null, null), /no daemon/) })