|
| 1 | +'use strict'; |
| 2 | +var tape = require('tape'); |
| 3 | +var path = require('../'); |
| 4 | + |
| 5 | +var slashRE = /\//g; |
| 6 | + |
| 7 | +var pairs = [ |
| 8 | + [__filename, '.js'], |
| 9 | + ['', ''], |
| 10 | + ['/path/to/file', ''], |
| 11 | + ['/path/to/file.ext', '.ext'], |
| 12 | + ['/path.to/file.ext', '.ext'], |
| 13 | + ['/path.to/file', ''], |
| 14 | + ['/path.to/.file', ''], |
| 15 | + ['/path.to/.file.ext', '.ext'], |
| 16 | + ['/path/to/f.ext', '.ext'], |
| 17 | + ['/path/to/..ext', '.ext'], |
| 18 | + ['/path/to/..', ''], |
| 19 | + ['file', ''], |
| 20 | + ['file.ext', '.ext'], |
| 21 | + ['.file', ''], |
| 22 | + ['.file.ext', '.ext'], |
| 23 | + ['/file', ''], |
| 24 | + ['/file.ext', '.ext'], |
| 25 | + ['/.file', ''], |
| 26 | + ['/.file.ext', '.ext'], |
| 27 | + ['.path/file.ext', '.ext'], |
| 28 | + ['file.ext.ext', '.ext'], |
| 29 | + ['file.', '.'], |
| 30 | + ['.', ''], |
| 31 | + ['./', ''], |
| 32 | + ['.file.ext', '.ext'], |
| 33 | + ['.file', ''], |
| 34 | + ['.file.', '.'], |
| 35 | + ['.file..', '.'], |
| 36 | + ['..', ''], |
| 37 | + ['../', ''], |
| 38 | + ['..file.ext', '.ext'], |
| 39 | + ['..file', '.file'], |
| 40 | + ['..file.', '.'], |
| 41 | + ['..file..', '.'], |
| 42 | + ['...', '.'], |
| 43 | + ['...ext', '.ext'], |
| 44 | + ['....', '.'], |
| 45 | + ['file.ext/', '.ext'], |
| 46 | + ['file.ext//', '.ext'], |
| 47 | + ['file/', ''], |
| 48 | + ['file//', ''], |
| 49 | + ['file./', '.'], |
| 50 | + ['file.//', '.'] ]; |
| 51 | + |
| 52 | +tape('path.posix.extname', function (t) { |
| 53 | + pairs.forEach(function (p) { |
| 54 | + var input = p[0]; |
| 55 | + var expected = p[1]; |
| 56 | + t.strictEqual(expected, path.posix.extname(input)); |
| 57 | + }); |
| 58 | + t.end(); |
| 59 | +}); |
| 60 | + |
| 61 | +tape('path.win32.extname', { skip: true }, function (t) { |
| 62 | + pairs.forEach(function (p) { |
| 63 | + var input = p[0].replace(slashRE, '\\'); |
| 64 | + var expected = p[1]; |
| 65 | + t.strictEqual(expected, path.win32.extname(input)); |
| 66 | + t.strictEqual(expected, path.win32.extname("C:" + input)); |
| 67 | + }); |
| 68 | + t.end(); |
| 69 | +}); |
| 70 | + |
| 71 | +tape('path.win32.extname backslash', { skip: true }, function (t) { |
| 72 | + // On Windows, backslash is a path separator. |
| 73 | + t.strictEqual(path.win32.extname('.\\'), ''); |
| 74 | + t.strictEqual(path.win32.extname('..\\'), ''); |
| 75 | + t.strictEqual(path.win32.extname('file.ext\\'), '.ext'); |
| 76 | + t.strictEqual(path.win32.extname('file.ext\\\\'), '.ext'); |
| 77 | + t.strictEqual(path.win32.extname('file\\'), ''); |
| 78 | + t.strictEqual(path.win32.extname('file\\\\'), ''); |
| 79 | + t.strictEqual(path.win32.extname('file.\\'), '.'); |
| 80 | + t.strictEqual(path.win32.extname('file.\\\\'), '.'); |
| 81 | + t.end(); |
| 82 | +}); |
| 83 | + |
| 84 | +tape('path.posix.extname backslash', function (t) { |
| 85 | + // On *nix, backslash is a valid name component like any other character. |
| 86 | + t.strictEqual(path.posix.extname('.\\'), ''); |
| 87 | + t.strictEqual(path.posix.extname('..\\'), '.\\'); |
| 88 | + t.strictEqual(path.posix.extname('file.ext\\'), '.ext\\'); |
| 89 | + t.strictEqual(path.posix.extname('file.ext\\\\'), '.ext\\\\'); |
| 90 | + t.strictEqual(path.posix.extname('file\\'), ''); |
| 91 | + t.strictEqual(path.posix.extname('file\\\\'), ''); |
| 92 | + t.strictEqual(path.posix.extname('file.\\'), '.\\'); |
| 93 | + t.strictEqual(path.posix.extname('file.\\\\'), '.\\\\'); |
| 94 | + t.end(); |
| 95 | +}); |
| 96 | + |
0 commit comments