char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e21152dc9
char/aliceai-t5-moe
1import { GLOB , SEARCH } from '$lib/constants' ; 2import { 3buildCaseInsensitiveGlob , 4buildGlobSearchArgs , 5highlightMatch , 6joinPath , 7rankEntries , 8splitPathQuery 9} from '$lib/utils' ; 10import { describe , expect , it } from 'vitest' ; 11 12describe ( 'splitPathQuery' , () => { 13it ( 'treats a plain query as a home-relative glob (not navigation)' , () => { 14expect ( splitPathQuery ( 'docs' )). toBeNull (); 15}); 16 17it ( 'navigates the root for `/`' , () => { 18expect ( splitPathQuery ( '/' )). toEqual ({ last :'' , parent :'/' }); 19}); 20 21it ( 'navigates home for `~`' , () => { 22expect ( splitPathQuery ( '~' )). toEqual ({ last :'' , parent :'~' }); 23}); 24 25it ( 'splits an absolute path into parent and last segment' , () => { 26expect ( splitPathQuery ( '/Users/al/proj' )). toEqual ({ last :'proj' , parent :'/Users/al' }); 27}); 28 29it ( 'navigates a Windows drive path written with backslashes' , () => { 30expect ( splitPathQuery ( 'C:\\repos\\llama.cpp' )). toEqual ({ 31last :'llama.cpp' , 32parent :'C:/repos' 33}); 34}); 35 36it ( 'navigates a Windows drive path written with forward slashes' , () => { 37expect ( splitPathQuery ( 'D:/repos' )). toEqual ({ last :'repos' , parent :'D:/' }); 38}); 39 40it ( 'treats a bare drive as its root' , () => { 41expect ( splitPathQuery ( 'D:' )). toEqual ({ last :'' , parent :'D:/' }); 42expect ( splitPathQuery ( 'D:\\' )). toEqual ({ last :'' , parent :'D:/' }); 43}); 44 45it ( 'navigates a UNC share' , () => { 46expect ( splitPathQuery ( '\\\\host\\share\\proj' )). toEqual ({ 47last :'proj' , 48parent :'//host/share/' 49}); 50}); 51 52it ( 'keeps a backslash as a POSIX filename character' , () => { 53expect ( splitPathQuery ( '/tmp/a\\b' )). toEqual ({ last :'a\\b' , parent :'/tmp' }); 54}); 55 56it ( 'splits a home-relative path into parent and last segment' , () => { 57expect ( splitPathQuery ( '~/Documents' )). toEqual ({ last :'Documents' , parent :'~' }); 58}); 59 60it ( 'strips trailing slashes before splitting' , () => { 61expect ( splitPathQuery ( '/Users/al/' )). toEqual ({ last :'al' , parent :'/Users' }); 62}); 63 64it ( 'handles a single-segment absolute path' , () => { 65expect ( splitPathQuery ( '/opt' )). toEqual ({ last :'opt' , parent :'/' }); 66}); 67}); 68 69describe ( 'buildCaseInsensitiveGlob' , () => { 70it ( 'wraps letters in case-insensitive character classes' , () => { 71expect ( buildCaseInsensitiveGlob ( 'ab' )). toBe ( '*[aA][bB]*' ); 72}); 73 74it ( 'escapes glob metacharacters into literal fragments' , () => { 75expect ( buildCaseInsensitiveGlob ( 'a*b' )). toBe ( '*[aA][*][bB]*' ); 76}); 77}); 78 79describe ( 'rankEntries' , () => { 80const entries = [ 81{ path :'/h/README' , type :'dir' }, 82{ path :'/h/read' , type :'dir' }, 83{ path :'/h/readme.txt' , type :'dir' } 84]; 85 86it ( 'ranks exact basename match first' , () => { 87const ranked = rankEntries ( entries , 'read' ); 88 89expect ( ranked [ 0 ]. path ). toBe ( '/h/read' ); 90}); 91 92it ( 'breaks ties by shorter path, then alphabetically' , () => { 93const ranked = rankEntries ( entries , 'read' ); 94 95expect ( ranked [ ranked . length - 1 ]. path ). toBe ( '/h/readme.txt' ); 96}); 97 98it ( 'does not mutate the input' , () => { 99const snapshot = [ ...entries ]; 100 101rankEntries ( entries , 'read' ); 102expect ( entries ). toEqual ( snapshot ); 103}); 104}); 105 106describe ( 'joinPath' , () => { 107it ( 'joins base and relative avoiding a double slash' , () => { 108expect ( joinPath ( '/home/al/' , 'docs' )). toBe ( '/home/al/docs' ); 109}); 110 111it ( 'returns the relative path when base is empty' , () => { 112expect ( joinPath ( '' , 'docs' )). toBe ( 'docs' ); 113}); 114}); 115 116describe ( 'highlightMatch' , () => { 117it ( 'returns a single non-matching segment when query is empty' , () => { 118expect ( highlightMatch ( 'abc' , '' )). toEqual ([{ match :false , text :'abc' }]); 119}); 120 121it ( 'marks every case-insensitive occurrence of the query' , () => { 122expect ( highlightMatch ( 'aXa' , 'ax' )). toEqual ([ 123{ match :true , text :'aX' }, 124{ match :false , text :'a' } 125]); 126}); 127 128it ( 'returns non-matching text when the query is absent' , () => { 129expect ( highlightMatch ( 'abc' , 'z' )). toEqual ([{ match :false , text :'abc' }]); 130}); 131}); 132 133describe ( 'buildGlobSearchArgs' , () => { 134const DEPTH = 6 ; 135 136it ( 'glob-matches home-relative within the scope path' , () => { 137const args = buildGlobSearchArgs ( 'docs' , '/home' , DEPTH ); 138 139expect ( args . path ). toBe ( '/home' ); 140expect ( args . include ). toBe ( buildCaseInsensitiveGlob ( 'docs' )); 141expect ( args . maxDepth ). toBe ( DEPTH ); 142expect ( args . rankQuery ). toBe ( 'docs' ); 143expect ( args . last ). toBeUndefined (); 144}); 145 146it ( 'navigates home for a `~` path query' , () => { 147const args = buildGlobSearchArgs ( '~/proj' , '/home' , DEPTH ); 148 149expect ( args . path ). toBe ( '~' ); 150expect ( args . include ). toBe ( buildCaseInsensitiveGlob ( 'proj' )); 151expect ( args . maxDepth ). toBe ( SEARCH . PATH_NAV_MAX_DEPTH ); 152expect ( args . rankQuery ). toBe ( 'proj' ); 153expect ( args . last ). toBe ( 'proj' ); 154}); 155 156it ( 'lists the scope root when a path query has no last segment' , () => { 157const args = buildGlobSearchArgs ( '~/' , '/home' , DEPTH ); 158 159expect ( args . path ). toBe ( '~' ); 160expect ( args . include ). toBe ( GLOB . WILDCARD ); 161expect ( args . maxDepth ). toBe ( SEARCH . PATH_NAV_MAX_DEPTH ); 162}); 163 164it ( 'navigates an absolute path under its root' , () => { 165const args = buildGlobSearchArgs ( '/usr/local/bin' , '/home' , DEPTH ); 166 167expect ( args . path ). toBe ( '/usr/local' ); 168expect ( args . include ). toBe ( buildCaseInsensitiveGlob ( 'bin' )); 169expect ( args . maxDepth ). toBe ( SEARCH . PATH_NAV_MAX_DEPTH ); 170expect ( args . rankQuery ). toBe ( 'bin' ); 171expect ( args . last ). toBe ( 'bin' ); 172}); 173});