Debian Codegraph @

globrex/test/helpers/index.js

raw
1 const globrex = require('../../');
2 const isWin = process.platform === 'win32';
3
4 function match(glob, strUnix, strWin, opts = {}) {
5 if (typeof strWin === 'object') {
6 opts = strWin;
7 strWin = false;
8 }
9 let res = globrex(glob, opts);
10 return res.regex.test(isWin && strWin ? strWin : strUnix);
11 }
12
13 function matchRegex(t, pattern, ifUnix, ifWin, opts) {
14 const res = globrex(pattern, opts);
15 const {regex} = (opts.filepath ? res.path : res);
16 t.is(regex.toString(), isWin ? ifWin : ifUnix, '~> regex matches expectant');
17 return res;
18 }
19
20 function matchSegments(t, pattern, ifUnix, ifWin, opts) {
21 const res = globrex(pattern, {filepath:true, ...opts});
22 const str = res.path.segments.join(' ');
23 const exp = (isWin ? ifWin : ifUnix).join(' ');
24 t.is(str, exp);
25 return res;
26 }
27
28 module.exports = { match, matchRegex, matchSegments };