Skip to content

Commit

Permalink
fixes #70
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jul 15, 2016
1 parent dcbeb91 commit 9d9ff9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 0 additions & 7 deletions lib/expand.js
Expand Up @@ -138,13 +138,6 @@ function expand(pattern, options) {
glob.pattern = globstar(opts.dot);

} else {
// '/*/*/*' => '(?:/*){3}'
glob._replace(/(\/\*)+/g, function(match) {
var len = match.length / 2;
if (len === 1) { return match; }
return '(?:\\/*){' + len + '}';
});

glob.pattern = balance(glob.pattern, '[', ']');
glob.escape(glob.pattern);

Expand Down
25 changes: 24 additions & 1 deletion test/micromatch.js
Expand Up @@ -7,8 +7,9 @@

'use strict';

var path = require('path');
require('should');
var path = require('path');
var assert = require('assert');
var argv = require('minimist')(process.argv.slice(2));
var mm = require('..');

Expand Down Expand Up @@ -111,6 +112,28 @@ describe('micromatch array patterns', function() {
});
});

describe('directories:', function() {
it('should match a single directory deep:', function() {
assert.deepEqual(mm(['a/b/c/d/e', 'a/b/c/d', 'a/b/c', 'a/b', 'a'], ['*']), ['a']);
});

it('should match a directory for each `*/`', function() {
var fixture = ['a/b/c/d/e', 'a/b/c/d', 'a/b/c', 'a/b', 'a'];
assert.deepEqual(mm(fixture, ['*/*']), ['a/b']);
assert.deepEqual(mm(fixture, ['*/*/*']), ['a/b/c']);
assert.deepEqual(mm(fixture, ['*/*/*/*']), ['a/b/c/d']);
assert.deepEqual(mm(fixture, ['*/*/*/*/*']), ['a/b/c/d/e']);
});

it('should match no less than the numbe of `*/` patterns when a globstar is passed', function() {
var fixture = ['a/b/c/d/e', 'a/b/c/d', 'a/b/c', 'a/b', 'a'];
assert.deepEqual(mm(fixture, ['*/*/**']), ['a/b/c/d/e', 'a/b/c/d', 'a/b/c']);
assert.deepEqual(mm(fixture, ['*/*/*/**']), ['a/b/c/d/e', 'a/b/c/d']);
assert.deepEqual(mm(fixture, ['*/*/*/*/**']), ['a/b/c/d/e']);
assert.deepEqual(mm(fixture, ['*/*/*/*/*/**']), []);
});
});

describe('double stars:', function() {
it('should match path segments:', function() {
mm(['.gitignore'], ['a/**/z/*.md']).should.eql([]);
Expand Down

0 comments on commit 9d9ff9e

Please sign in to comment.