@@ -10,6 +10,7 @@ import {
1010 Node ,
1111 Query ,
1212 URIRef ,
13+ joinPath ,
1314} from '../korrel8r/types' ;
1415
1516describe ( 'Query' , ( ) => {
@@ -184,3 +185,46 @@ describe('Graph', () => {
184185 expect ( g . nodes ) . toEqual ( a . nodes . map ( ( n ) => new Node ( n ) ) ) ;
185186 expect ( g . edges ) . toEqual ( a . edges . map ( ( e ) => new Edge ( g . node ( e . start ) , g . node ( e . goal ) ) ) ) ;
186187} ) ;
188+
189+ describe ( 'joinPath' , ( ) => {
190+ it . each ( [
191+ // Basic path joining
192+ [ 'path1' , 'path2' , 'path1/path2' ] ,
193+ [ 'path1' , 'path2' , 'path3' , 'path1/path2/path3' ] ,
194+
195+ // Handling trailing slash on first path
196+ [ 'path1/' , 'path2' , 'path1/path2' ] ,
197+ [ 'path1//' , 'path2' , 'path1/path2' ] ,
198+
199+ // Handling leading slashes on subsequent paths
200+ [ 'path1' , '/path2' , 'path1/path2' ] ,
201+ [ 'path1' , '//path2' , 'path1/path2' ] ,
202+
203+ // Handling trailing slashes on subsequent paths
204+ [ 'path1' , 'path2/' , 'path1/path2' ] ,
205+ [ 'path1' , 'path2//' , 'path1/path2' ] ,
206+
207+ // Complex combinations
208+ [ 'path1/' , '/path2/' , '/path3/' , 'path1/path2/path3' ] ,
209+ [ '/path1/' , '//path2//' , '///path3///' , '/path1/path2/path3' ] ,
210+
211+ // Empty paths
212+ [ '' , 'path2' , '/path2' ] ,
213+ [ 'path1' , '' , 'path1/' ] ,
214+ [ '' , '' , '/' ] ,
215+
216+ // Single path
217+ [ 'single' , 'single' ] ,
218+ [ 'single/' , 'single' ] ,
219+ [ '/single/' , '/single' ] ,
220+
221+ // Absolute paths
222+ [ '/absolute' , 'relative' , '/absolute/relative' ] ,
223+ [ '/absolute/' , '/relative/' , '/absolute/relative' ] ,
224+ ] as Array < string [ ] > ) ( 'joins paths correctly: %s' , ( ...args : string [ ] ) => {
225+ const expected = args . pop ( ) as string ;
226+ const paths = args as string [ ] ;
227+ const [ first , ...rest ] = paths ;
228+ expect ( joinPath ( first , ...rest ) ) . toEqual ( expected ) ;
229+ } ) ;
230+ } ) ;
0 commit comments