char-fork/llama.cpp

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

Pascalui: UI/chat form follow ups (#26743)4dee52f82

char/aliceai-t5-moe
1.6 KiB48 linesraw
1import { splitMentionSegments } from '$lib/utils/mention-badge';
2import { describe, expect, it } from 'vitest';
3
4describe('splitMentionSegments', () => {
5	it('returns a single plain run when there is no mention', () => {
6		const segments = splitMentionSegments('# not a heading here');
7
8		expect(segments).toEqual([{ mention: null, text: '# not a heading here' }]);
9	});
10
11	it('splits text around a mention', () => {
12		const segments = splitMentionSegments('look at [main.c](file:///src/main.c) please');
13
14		expect(segments.map((segment) => segment.text)).toEqual([
15			'look at ',
16			'[main.c](file:///src/main.c)',
17			' please'
18		]);
19		expect(segments[1].mention).toEqual({ name: 'main.c', path: '/src/main.c' });
20	});
21
22	it('decodes percent-encoded paths', () => {
23		const segments = splitMentionSegments('[a b.txt](file:///tmp/a%20b.txt)');
24
25		expect(segments[0].mention?.path).toBe('/tmp/a b.txt');
26	});
27
28	it('keeps the directory marker so the folder icon is picked', () => {
29		const segments = splitMentionSegments('[src](file:///repo/src/)');
30
31		expect(segments[0].mention?.path).toBe('/repo/src/');
32	});
33
34	it('handles adjacent mentions with no text between them', () => {
35		const segments = splitMentionSegments('[a](file:///a)[b](file:///b)');
36
37		expect(segments).toHaveLength(2);
38		expect(segments.every((segment) => segment.mention !== null)).toBe(true);
39	});
40
41	it('preserves the exact source when segments are joined back', () => {
42		const source = 'see [a](file:///a) and [b](file:///b/) done';
43
44		expect(splitMentionSegments(source).reduce((acc, segment) => acc + segment.text, '')).toBe(
45			source
46		);
47	});
48});