Skip to content

Commit

Permalink
lint unit tests
Browse files Browse the repository at this point in the history
add tests for non-exclusive globstars
  • Loading branch information
jonschlinkert committed Oct 31, 2019
1 parent 07876fa commit 0159b55
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 11 deletions.
1 change: 0 additions & 1 deletion test/api.picomatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('./support');
require('mocha');
const assert = require('assert').strict;
const picomatch = require('..');
Expand Down
7 changes: 6 additions & 1 deletion test/api.scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('picomatch', () => {
prefix: './'
});
});

it('should respect nonegate opts', () => {
assert.deepEqual(scan('!foo/bar/*.js', { nonegate: true }), {
input: '!foo/bar/*.js',
Expand Down Expand Up @@ -188,6 +188,11 @@ describe('picomatch', () => {
assert.equal(base('foo/(b c)/baz'), 'foo');
assert.equal(base('a/(b c)/'), 'a');
assert.equal(base('a/(b c)/d'), 'a');
assert.equal(base('a/(b c)', { noparen: true }), 'a/(b c)');
assert.equal(base('a/(b c)/', { noparen: true }), 'a/(b c)/');
assert.equal(base('a/(b c)/d', { noparen: true }), 'a/(b c)/d');
assert.equal(base('foo/(b c)/baz', { noparen: true }), 'foo/(b c)/baz');
assert.equal(base('path/(foo bar)/subdir/foo.*', { noparen: true }), 'path/(foo bar)/subdir');
assert.equal(base('a/\\(b c)'), 'a/\\(b c)', 'parens must be escaped');
assert.equal(base('a/\\+\\(b c)/foo'), 'a/\\+\\(b c)/foo', 'parens must be escaped');
assert.equal(base('js/t(wo|est)/*.js'), 'js');
Expand Down
9 changes: 6 additions & 3 deletions test/extglobs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('./support');
const assert = require('assert').strict;
const match = require('./support/match');
const { isMatch, makeRe } = require('..');
Expand Down Expand Up @@ -35,7 +34,6 @@ describe('extglobs', () => {
describe('negation', () => {
it('should support negation extglobs as the entire pattern', () => {
assert(!isMatch('abc', '!(abc)'));

assert(!isMatch('a', '!(a)'));
assert(isMatch('aa', '!(a)'));
assert(isMatch('b', '!(a)'));
Expand All @@ -45,7 +43,6 @@ describe('extglobs', () => {
assert(isMatch('aac', 'a!(b)c'));
assert(!isMatch('abc', 'a!(b)c'));
assert(isMatch('acc', 'a!(b)c'));

assert(isMatch('abz', 'a!(z)'));
assert(!isMatch('az', 'a!(z)'));
});
Expand Down Expand Up @@ -273,6 +270,12 @@ describe('extglobs', () => {
assert(isMatch('aa.md', '?(a|aa|b).md'));
assert(isMatch('ab.md', '?(a|ab|b).md'));
assert(isMatch('b.md', '?(a|ab|b).md'));

// see https://github.com/micromatch/micromatch/issues/186
assert(isMatch('ab', '+(a)?(b)'));
assert(isMatch('aab', '+(a)?(b)'));
assert(isMatch('aa', '+(a)?(b)'));
assert(isMatch('a', '+(a)?(b)'));
});
});

Expand Down
24 changes: 24 additions & 0 deletions test/globstars.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,33 @@ describe('stars', () => {
});

it('should regard non-exclusive double-stars as single stars', () => {
const fixtures = ['a', 'a/', 'a/a', 'a/a/', 'a/a/a', 'a/a/a/', 'a/a/a/a', 'a/a/a/a/', 'a/a/a/a/a', 'a/a/a/a/a/', 'a/a/b', 'a/a/b/', 'a/b', 'a/b/', 'a/b/c/.d/e/', 'a/c', 'a/c/', 'a/b', 'a/x/', 'b', 'b/', 'x/y', 'x/y/', 'z/z', 'z/z/'];

assert.deepEqual(match(fixtures, '**a/a/*/'), ['a/a/a/', 'a/a/b/']);
assert(!isMatch('aaa/bba/ccc', 'aaa/**ccc'));
assert(!isMatch('aaa/bba/ccc', 'aaa/**z'));
assert(isMatch('aaa/bba/ccc', 'aaa/**b**/ccc'));
assert(!isMatch('a/b/c', '**c'));
assert(!isMatch('a/b/c', 'a/**c'));
assert(!isMatch('a/b/c', 'a/**z'));
assert(!isMatch('a/b/c/b/c', 'a/**b**/c'));
assert(!isMatch('a/b/c/d/e.js', 'a/b/c**/*.js'));
assert(isMatch('a/b/c/b/c', 'a/**/b/**/c'));
assert(isMatch('a/aba/c', 'a/**b**/c'));
assert(isMatch('a/b/c', 'a/**b**/c'));
assert(isMatch('a/b/c/d.js', 'a/b/c**/*.js'));
});

it('should support globstars followed by braces', () => {
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**/c/**{,(/z|/x)}/*.md'));
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**{,(/x|/z)}/*.md'));
});

it('should support globstars followed by braces with nested extglobs', () => {
assert(isMatch('/x/foo.md', '@(/x|/z)/*.md'));
assert(isMatch('/z/foo.md', '@(/x|/z)/*.md'));
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**/c/**@(/z|/x)/*.md'));
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**@(/x|/z)/*.md'));
});

it('should support multiple globstars in one pattern', () => {
Expand Down
1 change: 0 additions & 1 deletion test/issue-related.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('./support');
const assert = require('assert').strict;
const { isMatch } = require('..');

Expand Down
1 change: 0 additions & 1 deletion test/malicious.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('./support');
const assert = require('assert').strict;
const { isMatch } = require('..');
const repeat = n => '\\'.repeat(n);
Expand Down
10 changes: 7 additions & 3 deletions test/non-globs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict';

require('mocha');
const path = require('path');
const assert = require('assert').strict;
const support = require('./support');
const { isMatch } = require('..');

describe('non-globs', () => {
before(() => support.resetPathSep());
after(() => support.resetPathSep());
afterEach(() => support.resetPathSep());

it('should match non-globs', () => {
assert(!isMatch('/ab', '/a'));
assert(!isMatch('a/a', 'a/b'));
Expand Down Expand Up @@ -50,9 +54,9 @@ describe('non-globs', () => {
});

it('should match windows paths', () => {
path.sep = '\\';
support.windowsPathSep();
assert(isMatch('aaa\\bbb', 'aaa/bbb'));
assert(isMatch('aaa/bbb', 'aaa/bbb'));
path.sep = process.env.ORIGINAL_PATH_SEP;
support.resetPathSep();
});
});
5 changes: 5 additions & 0 deletions test/slashes-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

require('mocha');
const assert = require('assert').strict;
const support = require('./support');
const { isMatch } = require('..');

describe('slash handling - posix', () => {
before(() => support.resetPathSep());
after(() => support.resetPathSep());
afterEach(() => support.resetPathSep());

it('should match a literal string', () => {
assert(!isMatch('a/a', '(a/b)'));
assert(isMatch('a/b', '(a/b)'));
Expand Down
2 changes: 2 additions & 0 deletions test/slashes-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const { isMatch, makeRe } = require('..');
describe('slash handling - windows', () => {
beforeEach(() => support.windowsPathSep());
afterEach(() => support.resetPathSep());
before(() => support.resetPathSep());
after(() => support.resetPathSep());

it('should match absolute windows paths with regex from makeRe', () => {
const regex = makeRe('**/path/**', { windows: true });
Expand Down
7 changes: 6 additions & 1 deletion test/special-characters.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
'use strict';

require('mocha');
const assert = require('assert').strict;
const path = require('path');
const assert = require('assert').strict;
const support = require('./support');
const { isMatch, makeRe } = require('..');

describe('special characters', () => {
before(() => support.resetPathSep());
after(() => support.resetPathSep());
afterEach(() => support.resetPathSep());

describe('numbers', () => {
it('should match numbers in the input string', () => {
assert(!isMatch('1', '*/*'));
Expand Down

0 comments on commit 0159b55

Please sign in to comment.