Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ensure the cache key used for reusing MatcherCollections works when being provided matchers not string patterns
  • Loading branch information
stefanpenner committed Aug 10, 2015
1 parent 13163d3 commit f6a6623
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion may-contain.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ MatcherCollection.prototype.mayContain = function(value) {
};

function getMatcher(value) {
var key = value.join('\x00');
var key = value.map(function(entry) {
if (entry.globSet) {
return entry.globSet.join('\x00');
} else {
return entry;
}
}).join('\x00');

if (MATCHER_CACHE[key]) { return MATCHER_CACHE[key]; }
var m = new MatcherCollection(value);
Expand Down
8 changes: 7 additions & 1 deletion test/may-contain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs')
var tap = require('tap')
var test = tap.test
var mayContain = require('../may-contain')

var Minimatch = require('minimatch').Minimatch;
tap.Test.prototype.addAssert('mayContain', 2, function(path, matcher) {
this.assert(mayContain(path, matcher), 'expected: `' + path + '` to match: `' + matcher + '`')
})
Expand All @@ -11,6 +11,12 @@ tap.Test.prototype.addAssert('mayNotContain', 2, function(path, matcher) {
this.assert(!mayContain(path, matcher), 'expected to NOT: `' + path + '` to match: `' + matcher + '`')
})

test('getMatcher internal cache', function(t) {
t.assert(mayContain('foo/bar', [new Minimatch('foo/bar')]))
t.assert(!mayContain('foo/bar', [new Minimatch('bar/foo')]))
t.end()
});

test('should traverse', function(t) {
t.mayContain('dir/bar.txt', 'dir/bar.txt')
t.mayNotContain('dir/bar.foo', 'dir/bar.txt')
Expand Down

0 comments on commit f6a6623

Please sign in to comment.