char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e21152dc9
char/aliceai-t5-moe
1import { URI_TEMPLATE_SYMBOLS } from '../../src/lib/constants/uri-template.constants' ; 2import { 3expandTemplate , 4extractTemplateVariables , 5isTemplateComplete , 6normalizeResourceUri 7} from '../../src/lib/utils/uri-template' ; 8import { describe , expect , it } from 'vitest' ; 9 10describe ( 'extractTemplateVariables' , () => { 11it ( 'extracts simple variables' , () => { 12const vars = extractTemplateVariables ( 'file:///{path}' ); 13 14expect ( vars ). toEqual ([{ name :'path' , operator :'' }]); 15}); 16 17it ( 'extracts multiple variables' , () => { 18const vars = extractTemplateVariables ( 'db://{schema}/{table}' ); 19 20expect ( vars ). toEqual ([ 21{ name :'schema' , operator :'' }, 22{ name :'table' , operator :'' } 23]); 24}); 25 26it ( 'extracts variables with operators' , () => { 27const vars = extractTemplateVariables ( 'http://example.com{+path}' ); 28 29expect ( vars ). toEqual ([{ name :'path' , operator :URI_TEMPLATE_SYMBOLS . RESERVED }]); 30}); 31 32it ( 'extracts comma-separated variable lists' , () => { 33const vars = extractTemplateVariables ( '{x,y,z}' ); 34 35expect ( vars ). toEqual ([ 36{ name :'x' , operator :'' }, 37{ name :'y' , operator :'' }, 38{ name :'z' , operator :'' } 39]); 40}); 41 42it ( 'deduplicates variable names' , () => { 43const vars = extractTemplateVariables ( '{name}/{name}' ); 44 45expect ( vars ). toEqual ([{ name :'name' , operator :'' }]); 46}); 47 48it ( 'handles fragment expansion' , () => { 49const vars = extractTemplateVariables ( 'http://example.com/page{#section}' ); 50 51expect ( vars ). toEqual ([{ name :'section' , operator :URI_TEMPLATE_SYMBOLS . FRAGMENT }]); 52}); 53 54it ( 'handles path segment expansion' , () => { 55const vars = extractTemplateVariables ( 'http://example.com{/path}' ); 56 57expect ( vars ). toEqual ([{ name :'path' , operator :URI_TEMPLATE_SYMBOLS . PATH_SEGMENT }]); 58}); 59 60it ( 'returns empty array for template without variables' , () => { 61const vars = extractTemplateVariables ( 'http://example.com/static' ); 62 63expect ( vars ). toEqual ([]); 64}); 65 66it ( 'strips explode modifier' , () => { 67const vars = extractTemplateVariables ( '{list*}' ); 68 69expect ( vars ). toEqual ([{ name :'list' , operator :'' }]); 70}); 71 72it ( 'strips prefix modifier' , () => { 73const vars = extractTemplateVariables ( '{value:5}' ); 74 75expect ( vars ). toEqual ([{ name :'value' , operator :'' }]); 76}); 77}); 78 79describe ( 'expandTemplate' , () => { 80it ( 'expands simple variable' , () => { 81const result = expandTemplate ( 'file:///{path}' , { path :'src/main.rs' }); 82 83expect ( result ). toBe ( 'file:///src%2Fmain.rs' ); 84}); 85 86it ( 'expands reserved variable (no encoding)' , () => { 87const result = expandTemplate ( 'file:///{+path}' , { path :'src/main.rs' }); 88 89expect ( result ). toBe ( 'file:///src/main.rs' ); 90}); 91 92it ( 'expands multiple variables' , () => { 93const result = expandTemplate ( 'db://{schema}/{table}' , { 94schema :'public' , 95table :'users' 96}); 97 98expect ( result ). toBe ( 'db://public/users' ); 99}); 100 101it ( 'leaves empty for missing variables' , () => { 102const result = expandTemplate ( '{missing}' , {}); 103 104expect ( result ). toBe ( '' ); 105}); 106 107it ( 'expands fragment' , () => { 108const result = expandTemplate ( 'http://example.com/page{#section}' , { 109section :'intro' 110}); 111 112expect ( result ). toBe ( 'http://example.com/page#intro' ); 113}); 114 115it ( 'expands path segments' , () => { 116const result = expandTemplate ( 'http://example.com{/path}' , { path :'docs' }); 117 118expect ( result ). toBe ( 'http://example.com/docs' ); 119}); 120 121it ( 'expands query parameters' , () => { 122const result = expandTemplate ( 'http://example.com{?q}' , { q :'search term' }); 123 124expect ( result ). toBe ( 'http://example.com?q=search%20term' ); 125}); 126 127it ( 'expands multiple query parameters' , () => { 128const result = expandTemplate ( 'http://example.com{?q,sort}' , { 129q :'search term' , 130sort :'descending' 131}); 132 133expect ( result ). toBe ( 'http://example.com?q=search%20term&sort=descending' ); 134}); 135 136it ( 'keeps static parts unchanged' , () => { 137const result = expandTemplate ( 'http://example.com/static' , {}); 138 139expect ( result ). toBe ( 'http://example.com/static' ); 140}); 141}); 142 143describe ( 'isTemplateComplete' , () => { 144it ( 'returns true when all variables are filled' , () => { 145expect ( isTemplateComplete ( 'file:///{path}' , { path :'test.txt' })). toBe ( true ); 146}); 147 148it ( 'returns false when a variable is missing' , () => { 149expect ( isTemplateComplete ( 'db://{schema}/{table}' , { schema :'public' })). toBe ( false ); 150}); 151 152it ( 'returns false when a variable is empty' , () => { 153expect ( isTemplateComplete ( 'file:///{path}' , { path :'' })). toBe ( false ); 154}); 155 156it ( 'returns false when a variable is whitespace only' , () => { 157expect ( isTemplateComplete ( 'file:///{path}' , { path :' ' })). toBe ( false ); 158}); 159 160it ( 'returns true for template without variables' , () => { 161expect ( isTemplateComplete ( 'http://example.com/static' , {})). toBe ( true ); 162}); 163 164it ( 'returns true when all multiple variables are filled' , () => { 165expect ( isTemplateComplete ( 'db://{schema}/{table}' , { schema :'public' , table :'users' })). toBe ( 166true 167); 168}); 169}); 170 171describe ( 'normalizeResourceUri' , () => { 172it ( 'passes through a normal URI unchanged' , () => { 173expect ( normalizeResourceUri ( 'svelte://svelte/$effect.md' )). toBe ( 'svelte://svelte/$effect.md' ); 174}); 175 176it ( 'normalizes triple-slash URIs from path-style template expansion' , () => { 177expect ( normalizeResourceUri ( 'svelte:///svelte/$effect.md' )). toBe ( 'svelte://svelte/$effect.md' ); 178}); 179 180it ( 'normalizes quadruple-slash URIs' , () => { 181expect ( normalizeResourceUri ( 'svelte:////svelte/$effect.md' )). toBe ( 'svelte://svelte/$effect.md' ); 182}); 183 184it ( 'handles file:// URIs' , () => { 185expect ( normalizeResourceUri ( 'file:///home/user/doc.txt' )). toBe ( 'file://home/user/doc.txt' ); 186}); 187 188it ( 'handles http URIs unchanged' , () => { 189expect ( normalizeResourceUri ( 'http://example.com/path' )). toBe ( 'http://example.com/path' ); 190}); 191 192it ( 'returns non-URI strings unchanged' , () => { 193expect ( normalizeResourceUri ( 'not-a-uri' )). toBe ( 'not-a-uri' ); 194}); 195});