|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const { test } = require('tap') |
| 4 | +const basename = require('../lib/utils/basename') |
| 5 | + |
| 6 | +test('basename', (t) => { |
| 7 | + const testCases = [ |
| 8 | + { description: 'returns an empty string if the path is not a string', path: {}, expected: '' }, |
| 9 | + { description: 'returns an empty string if the path includes a \' and the char after is a .', path: 'path\\.', expected: '' }, |
| 10 | + { description: 'returns an empty string if the path includes a / and the char after is a .', path: 'path/.', expected: '' }, |
| 11 | + { description: 'returns an empty string if the path includes a \' and the chars after are a ..', path: 'path\\..', expected: '' }, |
| 12 | + { description: 'returns an empty string if the path includes a / and the chars after are a ..', path: 'path/..', expected: '' }, |
| 13 | + { description: 'returns the path if the path includes a \' and the rest is anything other than dots', path: 'path\\subpath', expected: 'subpath' }, |
| 14 | + { description: 'returns the path if the path includes a / and the rest is anything other than dots', path: 'path/subpath', expected: 'subpath' }, |
| 15 | + { description: 'returns an empty string if the path is a .', path: '.', expected: '' }, |
| 16 | + { description: 'returns an empty string if the path is a ..', path: '..', expected: '' }, |
| 17 | + { description: 'returns the path if the path is anything other than dots', path: 'subpath', expected: 'subpath' } |
| 18 | + ] |
| 19 | + |
| 20 | + t.plan(testCases.length) |
| 21 | + |
| 22 | + testCases.forEach((testCase, index) => { |
| 23 | + t.test(testCase.description, t => { |
| 24 | + t.plan(1) |
| 25 | + t.equal(basename(testCase.path), testCase.expected, `Test case ${index + 1}`) |
| 26 | + }) |
| 27 | + }) |
| 28 | +}) |
0 commit comments