Skip to content

Commit 0159b55

Browse files
committed
lint unit tests
add tests for non-exclusive globstars
1 parent 07876fa commit 0159b55

10 files changed

+56
-11
lines changed

test/api.picomatch.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
require('./support');
43
require('mocha');
54
const assert = require('assert').strict;
65
const picomatch = require('..');

test/api.scan.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe('picomatch', () => {
146146
prefix: './'
147147
});
148148
});
149-
149+
150150
it('should respect nonegate opts', () => {
151151
assert.deepEqual(scan('!foo/bar/*.js', { nonegate: true }), {
152152
input: '!foo/bar/*.js',
@@ -188,6 +188,11 @@ describe('picomatch', () => {
188188
assert.equal(base('foo/(b c)/baz'), 'foo');
189189
assert.equal(base('a/(b c)/'), 'a');
190190
assert.equal(base('a/(b c)/d'), 'a');
191+
assert.equal(base('a/(b c)', { noparen: true }), 'a/(b c)');
192+
assert.equal(base('a/(b c)/', { noparen: true }), 'a/(b c)/');
193+
assert.equal(base('a/(b c)/d', { noparen: true }), 'a/(b c)/d');
194+
assert.equal(base('foo/(b c)/baz', { noparen: true }), 'foo/(b c)/baz');
195+
assert.equal(base('path/(foo bar)/subdir/foo.*', { noparen: true }), 'path/(foo bar)/subdir');
191196
assert.equal(base('a/\\(b c)'), 'a/\\(b c)', 'parens must be escaped');
192197
assert.equal(base('a/\\+\\(b c)/foo'), 'a/\\+\\(b c)/foo', 'parens must be escaped');
193198
assert.equal(base('js/t(wo|est)/*.js'), 'js');

test/extglobs.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
require('./support');
43
const assert = require('assert').strict;
54
const match = require('./support/match');
65
const { isMatch, makeRe } = require('..');
@@ -35,7 +34,6 @@ describe('extglobs', () => {
3534
describe('negation', () => {
3635
it('should support negation extglobs as the entire pattern', () => {
3736
assert(!isMatch('abc', '!(abc)'));
38-
3937
assert(!isMatch('a', '!(a)'));
4038
assert(isMatch('aa', '!(a)'));
4139
assert(isMatch('b', '!(a)'));
@@ -45,7 +43,6 @@ describe('extglobs', () => {
4543
assert(isMatch('aac', 'a!(b)c'));
4644
assert(!isMatch('abc', 'a!(b)c'));
4745
assert(isMatch('acc', 'a!(b)c'));
48-
4946
assert(isMatch('abz', 'a!(z)'));
5047
assert(!isMatch('az', 'a!(z)'));
5148
});
@@ -273,6 +270,12 @@ describe('extglobs', () => {
273270
assert(isMatch('aa.md', '?(a|aa|b).md'));
274271
assert(isMatch('ab.md', '?(a|ab|b).md'));
275272
assert(isMatch('b.md', '?(a|ab|b).md'));
273+
274+
// see https://github.com/micromatch/micromatch/issues/186
275+
assert(isMatch('ab', '+(a)?(b)'));
276+
assert(isMatch('aab', '+(a)?(b)'));
277+
assert(isMatch('aa', '+(a)?(b)'));
278+
assert(isMatch('a', '+(a)?(b)'));
276279
});
277280
});
278281

test/globstars.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,33 @@ describe('stars', () => {
1515
});
1616

1717
it('should regard non-exclusive double-stars as single stars', () => {
18+
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/'];
19+
20+
assert.deepEqual(match(fixtures, '**a/a/*/'), ['a/a/a/', 'a/a/b/']);
1821
assert(!isMatch('aaa/bba/ccc', 'aaa/**ccc'));
1922
assert(!isMatch('aaa/bba/ccc', 'aaa/**z'));
2023
assert(isMatch('aaa/bba/ccc', 'aaa/**b**/ccc'));
24+
assert(!isMatch('a/b/c', '**c'));
25+
assert(!isMatch('a/b/c', 'a/**c'));
26+
assert(!isMatch('a/b/c', 'a/**z'));
27+
assert(!isMatch('a/b/c/b/c', 'a/**b**/c'));
28+
assert(!isMatch('a/b/c/d/e.js', 'a/b/c**/*.js'));
29+
assert(isMatch('a/b/c/b/c', 'a/**/b/**/c'));
30+
assert(isMatch('a/aba/c', 'a/**b**/c'));
31+
assert(isMatch('a/b/c', 'a/**b**/c'));
32+
assert(isMatch('a/b/c/d.js', 'a/b/c**/*.js'));
33+
});
34+
35+
it('should support globstars followed by braces', () => {
36+
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**/c/**{,(/z|/x)}/*.md'));
37+
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**{,(/x|/z)}/*.md'));
38+
});
39+
40+
it('should support globstars followed by braces with nested extglobs', () => {
41+
assert(isMatch('/x/foo.md', '@(/x|/z)/*.md'));
42+
assert(isMatch('/z/foo.md', '@(/x|/z)/*.md'));
43+
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**/c/**@(/z|/x)/*.md'));
44+
assert(isMatch('a/b/c/d/e/z/foo.md', 'a/**@(/x|/z)/*.md'));
2145
});
2246

2347
it('should support multiple globstars in one pattern', () => {

test/issue-related.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
require('./support');
43
const assert = require('assert').strict;
54
const { isMatch } = require('..');
65

test/malicious.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
require('./support');
43
const assert = require('assert').strict;
54
const { isMatch } = require('..');
65
const repeat = n => '\\'.repeat(n);

test/non-globs.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
'use strict';
22

33
require('mocha');
4-
const path = require('path');
54
const assert = require('assert').strict;
5+
const support = require('./support');
66
const { isMatch } = require('..');
77

88
describe('non-globs', () => {
9+
before(() => support.resetPathSep());
10+
after(() => support.resetPathSep());
11+
afterEach(() => support.resetPathSep());
12+
913
it('should match non-globs', () => {
1014
assert(!isMatch('/ab', '/a'));
1115
assert(!isMatch('a/a', 'a/b'));
@@ -50,9 +54,9 @@ describe('non-globs', () => {
5054
});
5155

5256
it('should match windows paths', () => {
53-
path.sep = '\\';
57+
support.windowsPathSep();
5458
assert(isMatch('aaa\\bbb', 'aaa/bbb'));
5559
assert(isMatch('aaa/bbb', 'aaa/bbb'));
56-
path.sep = process.env.ORIGINAL_PATH_SEP;
60+
support.resetPathSep();
5761
});
5862
});

test/slashes-posix.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
require('mocha');
44
const assert = require('assert').strict;
5+
const support = require('./support');
56
const { isMatch } = require('..');
67

78
describe('slash handling - posix', () => {
9+
before(() => support.resetPathSep());
10+
after(() => support.resetPathSep());
11+
afterEach(() => support.resetPathSep());
12+
813
it('should match a literal string', () => {
914
assert(!isMatch('a/a', '(a/b)'));
1015
assert(isMatch('a/b', '(a/b)'));

test/slashes-windows.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const { isMatch, makeRe } = require('..');
88
describe('slash handling - windows', () => {
99
beforeEach(() => support.windowsPathSep());
1010
afterEach(() => support.resetPathSep());
11+
before(() => support.resetPathSep());
12+
after(() => support.resetPathSep());
1113

1214
it('should match absolute windows paths with regex from makeRe', () => {
1315
const regex = makeRe('**/path/**', { windows: true });

test/special-characters.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
'use strict';
22

33
require('mocha');
4-
const assert = require('assert').strict;
54
const path = require('path');
5+
const assert = require('assert').strict;
6+
const support = require('./support');
67
const { isMatch, makeRe } = require('..');
78

89
describe('special characters', () => {
10+
before(() => support.resetPathSep());
11+
after(() => support.resetPathSep());
12+
afterEach(() => support.resetPathSep());
13+
914
describe('numbers', () => {
1015
it('should match numbers in the input string', () => {
1116
assert(!isMatch('1', '*/*'));

0 commit comments

Comments
 (0)