char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
2.4 KiB64 linesraw
1import { findMentionToken, takeMentionDismissSnapshot } from '$lib/utils';
2import { describe, expect, it } from 'vitest';
3
4describe('findMentionToken', () => {
5	it('returns null for an empty/bare cursor', () => {
6		expect(findMentionToken('', 0)).toBeNull();
7		expect(findMentionToken('text', 0)).toBeNull();
8	});
9
10	it('recognizes a mention at the start of the value', () => {
11		expect(findMentionToken('@pr', 3)).toEqual({ end: 3, query: 'pr', start: 0 });
12	});
13
14	it('recognizes a mention after a word boundary', () => {
15		expect(findMentionToken('hello @pr', 9)).toEqual({ end: 9, query: 'pr', start: 6 });
16	});
17
18	it('returns null when the @ is mid-identifier', () => {
19		expect(findMentionToken('em@', 3)).toBeNull();
20		expect(findMentionToken('text@pr', 7)).toBeNull();
21	});
22
23	it('returns null when the cursor is past the whitespace break', () => {
24		expect(findMentionToken('@pr hello', 9)).toBeNull();
25	});
26
27	it('treats boundary characters (parens, brackets, comma) as token starts', () => {
28		expect(findMentionToken('(@pr', 4)).toEqual({ end: 4, query: 'pr', start: 1 });
29		expect(findMentionToken('[@pr', 4)).toEqual({ end: 4, query: 'pr', start: 1 });
30		expect(findMentionToken('a,@pr', 5)).toEqual({ end: 5, query: 'pr', start: 2 });
31	});
32
33	it('does not treat an identifier character as a boundary', () => {
34		expect(findMentionToken('user@abc', 8)).toBeNull();
35	});
36
37	it('extracts the whole token up to the trailing boundary as the query', () => {
38		expect(findMentionToken('@', 1)).toEqual({ end: 1, query: '', start: 0 });
39		expect(findMentionToken('@hello', 6)).toEqual({ end: 6, query: 'hello', start: 0 });
40	});
41
42	it('keeps the whole token as the query when the caret is mid-token', () => {
43		expect(findMentionToken('@hello', 4)).toEqual({ end: 6, query: 'hello', start: 0 });
44		expect(findMentionToken('@hello world', 4)).toEqual({ end: 6, query: 'hello', start: 0 });
45	});
46
47	it('ignores a boundary @ and keeps the most recent token', () => {
48		expect(findMentionToken('a @foo @bar', 11)).toEqual({ end: 11, query: 'bar', start: 7 });
49	});
50});
51
52describe('takeMentionDismissSnapshot', () => {
53	it('returns null when there is no valid mention at the cursor', () => {
54		expect(takeMentionDismissSnapshot('plain text', 5)).toBeNull();
55		expect(takeMentionDismissSnapshot('user@abc', 8)).toBeNull();
56	});
57
58	it('captures start and query of the current mention', () => {
59		expect(takeMentionDismissSnapshot('hello @proj', 11)).toEqual({
60			query: 'proj',
61			start: 6
62		});
63	});
64});