Team Ai
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 21d agoView on Hugging Face
0likes1.2kdownloads
source-history.test.ts73 linesDownload Raw Back to unit
1import { SourceHistory } from '$lib/utils';2import { describe, expect, it } from 'vitest';3 4describe('SourceHistory', () => {5	it('coalesces pushes inside the group window into one undo step', () => {6		const h = new SourceHistory(100, 800);7 8		h.push({ caret: 0, value: '' }, 1000);9		h.push({ caret: 1, value: 'a' }, 1200);10		h.push({ caret: 2, value: 'ab' }, 1500);11 12		expect(h.undo({ caret: 3, value: 'abc' })).toEqual({ caret: 0, value: '' });13		expect(h.undo({ caret: 0, value: '' })).toBeNull();14	});15 16	it('starts a new group once the window has passed', () => {17		const h = new SourceHistory(100, 800);18 19		h.push({ caret: 0, value: '' }, 1000);20		h.push({ caret: 3, value: 'abc' }, 2000);21 22		expect(h.undo({ caret: 6, value: 'abcdef' })).toEqual({ caret: 3, value: 'abc' });23		expect(h.undo({ caret: 3, value: 'abc' })).toEqual({ caret: 0, value: '' });24	});25 26	it('newGroup forces a separate entry even inside the window', () => {27		const h = new SourceHistory(100, 800);28 29		h.push({ caret: 0, value: '' }, 1000);30		h.push({ caret: 3, value: 'abc' }, 1100, true);31 32		expect(h.undo({ caret: 4, value: 'abc\n' })).toEqual({ caret: 3, value: 'abc' });33		expect(h.undo({ caret: 3, value: 'abc' })).toEqual({ caret: 0, value: '' });34	});35 36	it('redo round-trips and a fresh push clears the redo stack', () => {37		const h = new SourceHistory(100, 800);38 39		h.push({ caret: 0, value: '' }, 1000);40 41		const undone = h.undo({ caret: 3, value: 'abc' });42 43		expect(undone).toEqual({ caret: 0, value: '' });44		expect(h.redo({ caret: 0, value: '' })).toEqual({ caret: 3, value: 'abc' });45 46		h.undo({ caret: 3, value: 'abc' });47		h.push({ caret: 0, value: '' }, 5000);48		expect(h.redo({ caret: 1, value: 'x' })).toBeNull();49	});50 51	it('starts a new group on the first edit after an undo', () => {52		const h = new SourceHistory(100, 800);53 54		h.push({ caret: 0, value: '' }, 1000);55		h.undo({ caret: 3, value: 'abc' });56 57		h.push({ caret: 0, value: '' }, 1200);58		expect(h.undo({ caret: 1, value: 'x' })).toEqual({ caret: 0, value: '' });59	});60 61	it('evicts the oldest entry past the limit', () => {62		const h = new SourceHistory(2, 800);63 64		h.push({ caret: 0, value: 'one' }, 1000);65		h.push({ caret: 0, value: 'two' }, 2000);66		h.push({ caret: 0, value: 'three' }, 3000);67 68		expect(h.undo({ caret: 0, value: 'cur' })).toEqual({ caret: 0, value: 'three' });69		expect(h.undo({ caret: 0, value: 'three' })).toEqual({ caret: 0, value: 'two' });70		expect(h.undo({ caret: 0, value: 'two' })).toBeNull();71	});72});73