char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
fa4ec4590
char/aliceai-t5-moe
1import { badgeAwareWordJump , leadingBadgeEdgeOffset } from '$lib/utils' ; 2import { describe , expect , it } from 'vitest' ; 3 4// Layout of `hello [docs](file:///a/b) world foo`: 5// "hello" 0-4, " " 5, badge 6-24 (length 19), " " 25, "world" 26-30, " " 31, "foo" 32-34 6const BADGE = '[docs](file:///a/b)' ; 7const SOURCE = `hello ${ BADGE } world foo` ; 8const BADGE_START = 6 ; 9const BADGE_END = 25 ; 10 11describe ( 'badgeAwareWordJump' , () => { 12it ( 'returns null when the buffer has no badge' , () => { 13expect ( badgeAwareWordJump ( 'hello world' , 0 , 'forward' )). toBeNull (); 14expect ( badgeAwareWordJump ( 'hello world' , 11 , 'backward' )). toBeNull (); 15}); 16 17it ( 'jumps forward onto a badge landing at its end, not the next word' , () => { 18expect ( badgeAwareWordJump ( SOURCE , BADGE_START , 'forward' )). toBe ( BADGE_END ); 19}); 20 21it ( 'jumps forward from the space before a badge landing at its end' , () => { 22expect ( badgeAwareWordJump ( SOURCE , BADGE_START - 1 , 'forward' )). toBe ( BADGE_END ); 23}); 24 25it ( 'jumps backward over a badge landing at its start' , () => { 26expect ( badgeAwareWordJump ( SOURCE , BADGE_END , 'backward' )). toBe ( BADGE_START ); 27}); 28 29it ( 'jumps backward from the next word onto the badge start' , () => { 30// caret at the start of "world" 31expect ( badgeAwareWordJump ( SOURCE , BADGE_END + 1 , 'backward' )). toBe ( BADGE_START ); 32}); 33 34it ( 'returns null for jumps that cross no badge' , () => { 35// forward over "hello" only 36expect ( badgeAwareWordJump ( SOURCE , 0 , 'forward' )). toBeNull (); 37// backward over "foo" only 38expect ( badgeAwareWordJump ( SOURCE , SOURCE . length , 'backward' )). toBeNull (); 39// backward away from the badge (over "hello") 40expect ( badgeAwareWordJump ( SOURCE , BADGE_START , 'backward' )). toBeNull (); 41}); 42 43it ( 'treats a leading badge as one word in both directions' , () => { 44const source = ` ${ BADGE } rest` ; 45 46expect ( badgeAwareWordJump ( source , 0 , 'forward' )). toBe ( BADGE . length ); 47expect ( badgeAwareWordJump ( source , BADGE . length , 'backward' )). toBe ( 0 ); 48}); 49 50it ( 'treats adjacent badges as separate words' , () => { 51// each badge is 14 chars: "[a](file:///x)" / "[b](file:///y)" 52const source = '[a](file:///x)[b](file:///y)' ; 53 54expect ( badgeAwareWordJump ( source , 0 , 'forward' )). toBe ( 14 ); 55expect ( badgeAwareWordJump ( source , 14 , 'forward' )). toBe ( 28 ); 56expect ( badgeAwareWordJump ( source , 28 , 'backward' )). toBe ( 14 ); 57expect ( badgeAwareWordJump ( source , 14 , 'backward' )). toBe ( 0 ); 58}); 59 60it ( 'jumps over a badge following punctuation' , () => { 61// "foo," 0-3, " " 4, badge 5-23 (end 24), " bar" 24-27 62const source = `foo, ${ BADGE } bar` ; 63 64expect ( badgeAwareWordJump ( source , 0 , 'forward' )). toBeNull (); 65expect ( badgeAwareWordJump ( source , 3 , 'forward' )). toBe ( 24 ); 66}); 67}); 68 69describe ( 'leadingBadgeEdgeOffset' , () => { 70it ( 'returns 0 when the caret sits exactly at a leading badge end' , () => { 71expect ( leadingBadgeEdgeOffset ( ` ${ BADGE } rest` , BADGE . length )). toBe ( 0 ); 72}); 73 74it ( 'returns null when the caret is anywhere else' , () => { 75expect ( leadingBadgeEdgeOffset ( ` ${ BADGE } rest` , 0 )). toBeNull (); 76expect ( leadingBadgeEdgeOffset ( ` ${ BADGE } rest` , BADGE . length + 2 )). toBeNull (); 77}); 78 79it ( 'returns null when the buffer does not start with a badge' , () => { 80expect ( leadingBadgeEdgeOffset ( SOURCE , BADGE_END )). toBeNull (); 81expect ( leadingBadgeEdgeOffset ( '' , 0 )). toBeNull (); 82}); 83});