@@ -269,6 +269,110 @@ describe("unittests:: core paths", () => {
269
269
assert . strictEqual ( ts . resolvePath ( "a" , "b" , "/c" ) , "/c" ) ;
270
270
assert . strictEqual ( ts . resolvePath ( "a" , "b" , "../c" ) , "a/c" ) ;
271
271
} ) ;
272
+ it ( "getNormalizedAbsolutePath" , ( ) => {
273
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/" , "" ) , "/" ) ;
274
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/." , "" ) , "/" ) ;
275
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/./" , "" ) , "/" ) ;
276
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/../" , "" ) , "/" ) ;
277
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a" , "" ) , "/a" ) ;
278
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/" , "" ) , "/a" ) ;
279
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/." , "" ) , "/a" ) ;
280
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/foo." , "" ) , "/a/foo." ) ;
281
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/./" , "" ) , "/a" ) ;
282
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/./b" , "" ) , "/a/b" ) ;
283
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/./b/" , "" ) , "/a/b" ) ;
284
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/.." , "" ) , "/" ) ;
285
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/../" , "" ) , "/" ) ;
286
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/../" , "" ) , "/" ) ;
287
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/../b" , "" ) , "/b" ) ;
288
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/../b/" , "" ) , "/b" ) ;
289
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/.." , "" ) , "/" ) ;
290
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/.." , "/" ) , "/" ) ;
291
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/.." , "b/" ) , "/" ) ;
292
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/.." , "/b" ) , "/" ) ;
293
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/." , "b" ) , "/a" ) ;
294
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/." , "." ) , "/a" ) ;
295
+
296
+ // Tests as above, but with backslashes.
297
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\" , "" ) , "/" ) ;
298
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\." , "" ) , "/" ) ;
299
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\.\\" , "" ) , "/" ) ;
300
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\..\\" , "" ) , "/" ) ;
301
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.\\" , "" ) , "/a" ) ;
302
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.\\b" , "" ) , "/a/b" ) ;
303
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.\\b\\" , "" ) , "/a/b" ) ;
304
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.." , "" ) , "/" ) ;
305
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\..\\" , "" ) , "/" ) ;
306
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\..\\" , "" ) , "/" ) ;
307
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\..\\b" , "" ) , "/b" ) ;
308
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\..\\b\\" , "" ) , "/b" ) ;
309
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.." , "" ) , "/" ) ;
310
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.." , "\\" ) , "/" ) ;
311
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.." , "b\\" ) , "/" ) ;
312
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\.." , "\\b" ) , "/" ) ;
313
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\." , "b" ) , "/a" ) ;
314
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\." , "." ) , "/a" ) ;
315
+
316
+ // Relative paths on an empty currentDirectory.
317
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "" , "" ) , "" ) ;
318
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "." , "" ) , "" ) ;
319
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "./" , "" ) , "" ) ;
320
+ // Strangely, these do not normalize to the empty string.
321
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( ".." , "" ) , ".." ) ;
322
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "../" , "" ) , ".." ) ;
323
+
324
+ // Interaction between relative paths and currentDirectory.
325
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "" , "/home" ) , "/home" ) ;
326
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "." , "/home" ) , "/home" ) ;
327
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "./" , "/home" ) , "/home" ) ;
328
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( ".." , "/home" ) , "/" ) ;
329
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "../" , "/home" ) , "/" ) ;
330
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a" , "b" ) , "b/a" ) ;
331
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a" , "b/c" ) , "b/c/a" ) ;
332
+
333
+ // Base names starting or ending with a dot do not affect normalization.
334
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( ".a" , "" ) , ".a" ) ;
335
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "..a" , "" ) , "..a" ) ;
336
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a." , "" ) , "a." ) ;
337
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a.." , "" ) , "a.." ) ;
338
+
339
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/./.a" , "" ) , "/base/.a" ) ;
340
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/../.a" , "" ) , "/.a" ) ;
341
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/./..a" , "" ) , "/base/..a" ) ;
342
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/../..a" , "" ) , "/..a" ) ;
343
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/./..a/b" , "" ) , "/base/..a/b" ) ;
344
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/../..a/b" , "" ) , "/..a/b" ) ;
345
+
346
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/./a." , "" ) , "/base/a." ) ;
347
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/../a." , "" ) , "/a." ) ;
348
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/./a.." , "" ) , "/base/a.." ) ;
349
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/../a.." , "" ) , "/a.." ) ;
350
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/./a../b" , "" ) , "/base/a../b" ) ;
351
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/base/../a../b" , "" ) , "/a../b" ) ;
352
+
353
+ // Consecutive intermediate slashes are normalized to a single slash.
354
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a//b" , "" ) , "a/b" ) ;
355
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a///b" , "" ) , "a/b" ) ;
356
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a/b//c" , "" ) , "a/b/c" ) ;
357
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "/a/b//c" , "" ) , "/a/b/c" ) ;
358
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "//a/b//c" , "" ) , "//a/b/c" ) ;
359
+
360
+ // Backslashes are converted to slashes,
361
+ // and then consecutive intermediate slashes are normalized to a single slash
362
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a\\\\b" , "" ) , "a/b" ) ;
363
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a\\\\\\b" , "" ) , "a/b" ) ;
364
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a\\b\\\\c" , "" ) , "a/b/c" ) ;
365
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\b\\\\c" , "" ) , "/a/b/c" ) ;
366
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\\\a\\b\\\\c" , "" ) , "//a/b/c" ) ;
367
+
368
+ // The same occurs for mixed slashes.
369
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a/\\b" , "" ) , "a/b" ) ;
370
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a\\/b" , "" ) , "a/b" ) ;
371
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a\\/\\b" , "" ) , "a/b" ) ;
372
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "a\\b//c" , "" ) , "a/b/c" ) ;
373
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\a\\b\\\\c" , "" ) , "/a/b/c" ) ;
374
+ assert . strictEqual ( ts . getNormalizedAbsolutePath ( "\\\\a\\b\\\\c" , "" ) , "//a/b/c" ) ;
375
+ } ) ;
272
376
it ( "getPathRelativeTo" , ( ) => {
273
377
assert . strictEqual ( ts . getRelativePathFromDirectory ( "/" , "/" , /*ignoreCase*/ false ) , "" ) ;
274
378
assert . strictEqual ( ts . getRelativePathFromDirectory ( "/a" , "/a" , /*ignoreCase*/ false ) , "" ) ;
0 commit comments