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/) }) import { lineBlockDiff, charDiff, insertionMakesSense, newerVersion } from '../dist/logic.js' test('leftover paren is a one-character deletion', () => { const d = charDiff('const v = fromString(someString))', 'const v = fromString(someString)') assert.deepEqual(d, { start: 32, deleteEnd: 33, insert: '' }) }) test('line block diff finds the changed lines', () => { const d = lineBlockDiff('a\nb\nc\nd\n', 'a\nB\nB2\nd\n') assert.deepEqual(d, { oldStart: 1, oldEnd: 3, oldLines: ['b', 'c'], newLines: ['B', 'B2'] }) assert.equal(lineBlockDiff('x\n', 'x\n'), null) }) test('cursor-move gate', () => { assert.equal(insertionMakesSense(' ', 4, false), true) assert.equal(insertionMakesSense(' foo()', 7, false), true) assert.equal(insertionMakesSense(' foo()', 3, false), false) assert.equal(insertionMakesSense(' foo()', 3, true), true) }) test('version comparison', () => { assert.equal(newerVersion('0.10.0', '0.9.3'), true) assert.equal(newerVersion('0.5.0', '0.5.0'), false) })