diff --git a/src/lib/shortcuts.test.ts b/src/lib/shortcuts.test.ts deleted file mode 100644 index 3b3754663a..0000000000 --- a/src/lib/shortcuts.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { beforeEach, describe, expect, it } from 'vitest'; -import { - eventToChord, - loadKeybindings, - matchKeybinding, - resetKeybindings, - Shortcut -} from './shortcuts'; - -const key = ( - key: string, - modifiers: Partial> = {} -) => - ({ - key, - ctrlKey: false, - metaKey: false, - altKey: false, - shiftKey: false, - ...modifiers - }) as KeyboardEvent; - -describe('shortcuts', () => { - beforeEach(() => { - resetKeybindings(); - }); - - it('normalizes ctrl to Cmd on non-Mac platforms', () => { - expect(eventToChord(key('k', { ctrlKey: true }))).toBe('Cmd+K'); - expect(matchKeybinding(key('k', { ctrlKey: true }))).toBe(Shortcut.SEARCH); - }); - - it('loads saved bindings, including unassigned shortcuts', () => { - loadKeybindings({ - [Shortcut.SEARCH]: 'Cmd+Shift+P', - [Shortcut.NEW_CHAT]: '' - }); - - expect(matchKeybinding(key('k', { ctrlKey: true }))).toBeNull(); - expect(matchKeybinding(key('p', { ctrlKey: true, shiftKey: true }))).toBe(Shortcut.SEARCH); - expect(matchKeybinding(key('o', { ctrlKey: true, shiftKey: true }))).toBeNull(); - }); -}); diff --git a/src/lib/utils/_template_old.ts b/src/lib/utils/_template_old.ts deleted file mode 100644 index f69ef22601..0000000000 --- a/src/lib/utils/_template_old.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { titleGenerationTemplate } from '$lib/utils/index'; -import { expect, test } from 'vitest'; - -test('titleGenerationTemplate correctly replaces {{prompt}} placeholder', () => { - const template = 'Hello {{prompt}}!'; - const prompt = 'world'; - const expected = 'Hello world!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); - -test('titleGenerationTemplate correctly replaces {{prompt:start:}} placeholder', () => { - const template = 'Hello {{prompt:start:3}}!'; - const prompt = 'world'; - const expected = 'Hello wor!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); - -test('titleGenerationTemplate correctly replaces {{prompt:end:}} placeholder', () => { - const template = 'Hello {{prompt:end:3}}!'; - const prompt = 'world'; - const expected = 'Hello rld!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); - -test('titleGenerationTemplate correctly replaces {{prompt:middletruncate:}} placeholder when prompt length is greater than length', () => { - const template = 'Hello {{prompt:middletruncate:4}}!'; - const prompt = 'world'; - const expected = 'Hello wo...ld!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); - -test('titleGenerationTemplate correctly replaces {{prompt:middletruncate:}} placeholder when prompt length is less than or equal to length', () => { - const template = 'Hello {{prompt:middletruncate:5}}!'; - const prompt = 'world'; - const expected = 'Hello world!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); - -test('titleGenerationTemplate returns original template when no placeholders are present', () => { - const template = 'Hello world!'; - const prompt = 'world'; - const expected = 'Hello world!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); - -test('titleGenerationTemplate does not replace placeholders inside of replaced placeholders', () => { - const template = 'Hello {{prompt}}!'; - const prompt = 'World, {{prompt}} injection'; - const expected = 'Hello World, {{prompt}} injection!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); - -test('titleGenerationTemplate correctly replaces multiple placeholders', () => { - const template = 'Hello {{prompt}}! This is {{prompt:start:3}}!'; - const prompt = 'world'; - const expected = 'Hello world! This is wor!'; - const actual = titleGenerationTemplate(template, prompt); - expect(actual).toBe(expected); -}); diff --git a/src/lib/utils/marked/colon-fence-extension.test.ts b/src/lib/utils/marked/colon-fence-extension.test.ts deleted file mode 100644 index a82ebd663d..0000000000 --- a/src/lib/utils/marked/colon-fence-extension.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { Marked } from 'marked'; - -import colonFenceExtension from './colon-fence-extension'; - -type ColonFenceToken = { - type: string; - fenceType: string; - attributes: Record; - text: string; -}; - -const firstFence = (src: string) => { - const marked = new Marked(); - marked.use(colonFenceExtension()); - const tokens = marked.lexer(src) as unknown as ColonFenceToken[]; - return tokens.find((token) => token.type === 'colonFence') as ColonFenceToken; -}; - -describe('colon fence extension', () => { - it('tokenizes a block without attributes', () => { - const token = firstFence(':::writing\n\nHello\n:::\n'); - - expect(token.fenceType).toBe('writing'); - expect(token.attributes).toEqual({}); - expect(token.text).toBe('Hello'); - }); - - it('parses the attributes on the opening line', () => { - const token = firstFence( - ':::writing{variant="email" id="48173" subject="Short question" recipient="mail@example.com"}\n\nHello\n:::\n' - ); - - expect(token.attributes).toEqual({ - variant: 'email', - id: '48173', - subject: 'Short question', - recipient: 'mail@example.com' - }); - expect(token.text).toBe('Hello'); - }); - - it('does not read attributes from unbraced trailing text', () => { - const token = firstFence(':::writing{variant="document"} draft subject="junk"\n\nHello\n:::\n'); - - expect(token.attributes).toEqual({ variant: 'document' }); - }); - - it('ignores an opening line that has no braces at all', () => { - const token = firstFence( - ':::note prose mentioning recipient="evil@example.com"\n\nHello\n:::\n' - ); - - expect(token.fenceType).toBe('note'); - expect(token.attributes).toEqual({}); - }); - - it('ignores an unclosed brace', () => { - const token = firstFence(':::writing{subject="Short question"\n\nHello\n:::\n'); - - expect(token.attributes).toEqual({}); - }); - - it('allows braces inside an attribute value', () => { - const token = firstFence(':::writing{subject="use {x} here"}\n\nHello\n:::\n'); - - expect(token.attributes.subject).toBe('use {x} here'); - }); -});