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