|
| 1 | +import test from 'ava'; |
| 2 | +import { makeSubpathReplacer } from '../src/subpath.js'; |
| 3 | + |
| 4 | +test('no wildcard subpath replacement', t => { |
| 5 | + const replaceSubpath = makeSubpathReplacer('a/b/c', 'x/y/z'); |
| 6 | + t.is(replaceSubpath(''), null); |
| 7 | + t.is(replaceSubpath('a'), null); |
| 8 | + t.is(replaceSubpath('a/b'), null); |
| 9 | + t.is(replaceSubpath('a/b/c'), 'x/y/z'); |
| 10 | + t.is(replaceSubpath('a/b/c/d'), null); |
| 11 | +}); |
| 12 | + |
| 13 | +test('single wildcard subpath replacement', t => { |
| 14 | + const replaceSubpath = makeSubpathReplacer('a/*/c', 'x/*/z'); |
| 15 | + t.is(replaceSubpath(''), null); |
| 16 | + t.is(replaceSubpath('a'), null); |
| 17 | + t.is(replaceSubpath('a/b'), null); |
| 18 | + t.is(replaceSubpath('a/*/c'), 'x/*/z'); |
| 19 | + t.is(replaceSubpath('a/b/c'), 'x/b/z'); |
| 20 | + t.is(replaceSubpath('a/1/2/c'), 'x/1/2/z'); |
| 21 | +}); |
| 22 | + |
| 23 | +test('double wildcard subpath replacement', t => { |
| 24 | + const replaceSubpath = makeSubpathReplacer('a/*/b/*/c', 'x/*/y/*/z'); |
| 25 | + t.is(replaceSubpath('a/1/2/b/3/4/c'), 'x/1/2/y/3/4/z'); |
| 26 | +}); |
| 27 | + |
| 28 | +test('double wildcard subpath replacement without slashes', t => { |
| 29 | + const replaceSubpath = makeSubpathReplacer('a*b*c', 'x*y*z'); |
| 30 | + t.is(replaceSubpath('a12b34c'), 'x12y34z'); |
| 31 | +}); |
| 32 | + |
| 33 | +test('mismatched subpath', t => { |
| 34 | + const replaceSubpath = makeSubpathReplacer('*-*', '*'); |
| 35 | + t.is(replaceSubpath('1-2'), null); |
| 36 | +}); |
0 commit comments