UNPKG

25.4 kBJavaScriptView Raw
1/**
2 * matched <https://github.com/jonschlinkert/matched>
3 *
4 * Copyright (c) 2014 Jon Schlinkert, contributors.
5 * Licensed under the MIT license.
6 */
7
8'use strict';
9
10var expect = require('chai').expect;
11var globule = require('globule');
12var multimatch = require('multimatch');
13var matched = require('../');
14
15var globMatch = function(arr, patterns, options) {
16 return globule.match(patterns, arr, options);
17};
18
19
20describe('when an array of additive glob patterns is defined:', function () {
21 it('should return an array of matches', function (done) {
22 expect(multimatch(['foo', 'bar', 'baz'], ['f*'])).to.eql(['foo']);
23 expect(globMatch(['foo', 'bar', 'baz'], ['f*'])).to.eql(['foo']);
24 expect(matched(['foo', 'bar', 'baz'], ['f*'])).to.eql(['foo']);
25
26 expect(multimatch(['foo', 'bar', 'baz'], ['f*', 'bar'])).to.eql(['foo', 'bar']);
27 expect(globMatch(['foo', 'bar', 'baz'], ['f*', 'bar'])).to.eql(['foo', 'bar']);
28 expect(matched(['foo', 'bar', 'baz'], ['f*', 'bar'])).to.eql(['foo', 'bar']);
29 done();
30 });
31
32 it('should return matches in the order the patterns were defined', function (done) {
33 expect(multimatch(['foo', 'bar', 'baz'], ['bar', 'f*'])).to.eql(['bar', 'foo']);
34 expect(globMatch(['foo', 'bar', 'baz'], ['bar', 'f*'])).to.eql(['bar', 'foo']);
35 expect(matched(['foo', 'bar', 'baz'], ['bar', 'f*'])).to.eql(['bar', 'foo']);
36
37 expect(multimatch(['foo', 'bar', 'baz'], ['f*', '*z'])).to.eql(['foo', 'baz']);
38 expect(globMatch(['foo', 'bar', 'baz'], ['f*', '*z'])).to.eql(['foo', 'baz']);
39 expect(matched(['foo', 'bar', 'baz'], ['f*', '*z'])).to.eql(['foo', 'baz']);
40
41 expect(multimatch(['foo', 'bar', 'baz'], ['*z', 'f*'])).to.eql(['baz', 'foo']);
42 expect(globMatch(['foo', 'bar', 'baz'], ['*z', 'f*'])).to.eql(['baz', 'foo']);
43 expect(matched(['foo', 'bar', 'baz'], ['*z', 'f*'])).to.eql(['baz', 'foo']);
44 done();
45 });
46});
47
48
49describe('when additive string patterns are defined and matches are found:', function () {
50 it('should return an array of matches', function (done) {
51 expect(multimatch(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']);
52 expect(globMatch(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']);
53 expect(matched(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']);
54 done();
55 });
56});
57
58describe('when negation string patterns are defined', function () {
59 it('should return an array with negations omitted', function (done) {
60 expect(multimatch(['foo', 'bar', 'baz'], '!foo')).to.eql(['bar', 'baz']); // expected?
61 expect(globMatch(['foo', 'bar', 'baz'], '!foo')).to.eql([]); // expected?
62 expect(matched(['foo', 'bar', 'baz'], '!foo')).to.eql([]); // expected?
63 done();
64 });
65});
66
67describe('when an array of additive string patterns is defined and matches are found:', function () {
68 it('should return an array of matches', function (done) {
69 expect(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']);
70 expect(globMatch(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']);
71 expect(matched(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']);
72 done();
73 });
74
75 it('should return an empty array when no matches are found', function (done) {
76 expect(multimatch(['foo', 'bar', 'baz'], ['quux'])).to.eql([]);
77 expect(globMatch(['foo', 'bar', 'baz'], ['quux'])).to.eql([]);
78 expect(matched(['foo', 'bar', 'baz'], ['quux'])).to.eql([]);
79 done();
80 });
81});
82
83
84describe('when an array of negation glob patterns is defined', function () {
85 it('should return an array with negations omitted', function (done) {
86 expect(multimatch(['foo', 'bar', 'baz'], ['!*z'])).to.eql(['foo', 'bar']); // expected?
87 expect(globMatch(['foo', 'bar', 'baz'], ['!*z'])).to.eql([]); // expected?
88 expect(matched(['foo', 'bar', 'baz'], ['!*z'])).to.eql([]); // expected?
89 done();
90 });
91
92 it('should return an array with negations omitted', function (done) {
93 expect(multimatch(['foo', 'bar', 'baz'], ['!*z', '!*a*'])).to.eql(['foo']); // expected?
94 expect(globMatch(['foo', 'bar', 'baz'], ['!*z', '!*a*'])).to.eql([]); // expected?
95 expect(matched(['foo', 'bar', 'baz'], ['!*z', '!*a*'])).to.eql([]); // expected?
96 done();
97 });
98
99 it('should return an empty array when no matches are found', function (done) {
100 expect(multimatch(['foo', 'bar', 'baz'], ['!*'])).to.eql([]);
101 expect(globMatch(['foo', 'bar', 'baz'], ['!*'])).to.eql([]);
102 expect(matched(['foo', 'bar', 'baz'], ['!*'])).to.eql([]);
103 done();
104 });
105});
106
107
108describe('when an array of filepaths is passed, and an array of negation glob patterns is defined', function () {
109 var fixtures = ['vendor/js/foo.js', 'vendor/js/bar.js', 'vendor/js/baz.js'];
110
111 it('should return an array with negations omitted', function (done) {
112 expect(multimatch(fixtures, ['!**/*z.js'])).to.eql(['vendor/js/foo.js', 'vendor/js/bar.js']); // expected?
113 expect(globMatch(fixtures, ['!**/*z.js'])).to.eql([]); // expected?
114 expect(matched(fixtures, ['!**/*z.js'])).to.eql([]); // expected?
115 done();
116 });
117
118 it('should return an array with negations omitted', function (done) {
119 expect(multimatch(fixtures, ['!**/*z.js', '**/foo.js'])).to.eql(['vendor/js/foo.js', 'vendor/js/bar.js']); // expected?
120 expect(globMatch(fixtures, ['!**/*z.js', '**/foo.js'])).to.eql(['vendor/js/foo.js']); // expected?
121 expect(matched(fixtures, ['!**/*z.js', '**/foo.js'])).to.eql(['vendor/js/foo.js']); // expected?
122 done();
123 });
124
125 it('should return an array with negations omitted', function (done) {
126 expect(multimatch(fixtures, ['!**/*z.js', '!**/*a*.js'])).to.eql(['vendor/js/foo.js']); // expected?
127 expect(globMatch(fixtures, ['!**/*z.js', '!**/*a*.js'])).to.eql([]); // expected?
128 expect(matched(fixtures, ['!**/*z.js', '!**/*a*.js'])).to.eql([]); // expected?
129 done();
130 });
131
132 it('should return an empty array when no matches are found', function (done) {
133 expect(multimatch(fixtures, ['!**/*.js'])).to.eql([]);
134 expect(globMatch(fixtures, ['!**/*.js'])).to.eql([]);
135 expect(matched(fixtures, ['!**/*.js'])).to.eql([]);
136 done();
137 });
138});
139
140
141describe('when an array of negation string patterns is defined', function () {
142 it('should return an array with negations omitted', function (done) {
143 expect(multimatch(['foo', 'bar', 'baz'], ['!foo'])).to.eql(['bar', 'baz']); // expected?
144 expect(globMatch(['foo', 'bar', 'baz'], ['!foo'])).to.eql([]); // expected?
145 expect(matched(['foo', 'bar', 'baz'], ['!foo'])).to.eql([]); // expected?
146
147 expect(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql(['baz']); // expected?
148 expect(globMatch(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql([]); // expected?
149 expect(matched(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql([]); // expected?
150 done();
151 });
152});
153
154
155
156describe('when inclusion and negation patterns are defined', function () {
157 it('should return an array of matches, sans negations', function (done) {
158 expect(multimatch(['foo', 'bar', 'baz'], ['!*a*'])).to.eql(['foo']); // expected?
159 expect(globMatch(['foo', 'bar', 'baz'], ['!*a*'])).to.eql([]); // expected?
160 expect(matched(['foo', 'bar', 'baz'], ['!*a*'])).to.eql([]); // expected?
161 done();
162 });
163
164 it('should override negations and re-include explicitly defined patterns', function (done) {
165 expect(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['foo', 'baz']); // expected?
166 expect(globMatch(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); // expected?
167 expect(matched(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); // expected?
168 done();
169 });
170
171 it('patterns should be order insensitive', function (done) {
172 expect(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['foo', 'baz']); // expected?
173 expect(globMatch(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); // expected?
174 expect(matched(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); // expected?
175 expect(multimatch(['foo', 'bar', 'baz'], ['*z', '!*a*'])).to.eql([]); // expected?
176 expect(globMatch(['foo', 'bar', 'baz'], ['*z', '!*a*'])).to.eql([]); // expected?
177 expect(matched(['foo', 'bar', 'baz'], ['*z', '!*a*'])).to.eql([]); // expected?
178
179 expect(multimatch(['foo', 'foam', 'for', 'forum'], ['!*m', 'f*'])).to.eql(['foo', 'for', 'foam', 'forum']); // expected?
180 expect(globMatch(['foo', 'foam', 'for', 'forum'], ['!*m', 'f*'])).to.eql(['foo', 'foam', 'for', 'forum']); // expected?
181 expect(matched(['foo', 'foam', 'for', 'forum'], ['!*m', 'f*'])).to.eql(['foo', 'foam', 'for', 'forum']); // expected?
182 expect(multimatch(['foo', 'foam', 'for', 'forum'], ['f*', '!*m'])).to.eql(['foo', 'for']);
183 expect(globMatch(['foo', 'foam', 'for', 'forum'], ['f*', '!*m'])).to.eql(['foo', 'for']);
184 expect(matched(['foo', 'foam', 'for', 'forum'], ['f*', '!*m'])).to.eql(['foo', 'for']);
185
186 expect(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['baz', 'foo']); // expected?
187 expect(globMatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['foo']); // expected?
188 expect(matched(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['foo']); // expected?
189 expect(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]);
190 expect(globMatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]);
191 expect(matched(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]);
192
193 expect(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar', 'baz']);
194 expect(globMatch(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar']);
195 expect(matched(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar']);
196 expect(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']);
197 expect(globMatch(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']);
198 expect(matched(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']);
199
200 expect(multimatch(['foo', 'bar', 'baz'], ['bar', '!foo', 'foo'])).to.eql(['bar', 'foo']);
201 expect(globMatch(['foo', 'bar', 'baz'], ['bar', '!foo', 'foo'])).to.eql(['bar', 'foo']);
202 expect(matched(['foo', 'bar', 'baz'], ['bar', '!foo', 'foo'])).to.eql(['bar', 'foo']);
203 expect(multimatch(['foo', 'bar', 'baz'], ['foo', '!foo', 'bar'])).to.eql(['bar']);
204 expect(globMatch(['foo', 'bar', 'baz'], ['foo', '!foo', 'bar'])).to.eql(['bar']);
205 expect(matched(['foo', 'bar', 'baz'], ['foo', '!foo', 'bar'])).to.eql(['bar']);
206
207 done();
208 });
209
210 it('should override negations and re-include explicitly defined patterns', function (done) {
211 expect(multimatch(['foo', 'bar', 'baz'], ['!*'])).to.eql([]);
212 expect(multimatch(['foo', 'bar', 'baz'], ['!*a*'])).to.eql(['foo']); // expected?
213 expect(multimatch(['foo', 'bar', 'baz'], ['bar', '!*a*'])).to.eql([]); // expected?
214 expect(multimatch(['foo', 'bar', 'baz'], ['!*a*', 'bar'])).to.eql(['foo', 'bar']); // expected?
215 expect(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*'])).to.eql(['foo', 'bar', 'baz']);
216 expect(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['foo', 'baz']); // expected?
217
218 expect(globMatch(['foo', 'bar', 'baz'], ['!*'])).to.eql([]);
219 expect(globMatch(['foo', 'bar', 'baz'], ['!*a*'])).to.eql([]);
220 expect(globMatch(['foo', 'bar', 'baz'], ['bar', '!*a*'])).to.eql([]);
221 expect(globMatch(['foo', 'bar', 'baz'], ['!*a*', 'bar'])).to.eql(['bar']);
222 expect(globMatch(['foo', 'bar', 'baz'], ['!*a*', '*'])).to.eql(['foo', 'bar', 'baz']);
223 expect(globMatch(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); // expected?
224
225 expect(matched(['foo', 'bar', 'baz'], ['!*'])).to.eql([]);
226 expect(matched(['foo', 'bar', 'baz'], ['!*a*'])).to.eql([]);
227 expect(matched(['foo', 'bar', 'baz'], ['bar', '!*a*'])).to.eql([]);
228 expect(matched(['foo', 'bar', 'baz'], ['!*a*', 'bar'])).to.eql(['bar']);
229 expect(matched(['foo', 'bar', 'baz'], ['!*a*', '*'])).to.eql(['foo', 'bar', 'baz']);
230 expect(matched(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); // expected?
231 done();
232 });
233});
234
235
236describe('misc', function () {
237 it('misc', function (done) {
238 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
239 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
240 expect(matched(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
241
242 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!foo', 'bar'])).to.eql(['bar', 'baz']);
243 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!foo', 'bar'])).to.eql(['bar', 'baz']);
244 expect(matched(['foo', 'bar', 'baz'], ['*', '!foo', 'bar'])).to.eql(['bar', 'baz']);
245
246 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
247 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
248 expect(matched(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
249
250 expect(multimatch(['foo', 'bar', 'baz'], ['!foo', '*'])).to.eql(['bar', 'baz', 'foo']); // expected?
251 expect(globMatch(['foo', 'bar', 'baz'], ['!foo', '*'])).to.eql(['foo', 'bar', 'baz']); // expected?
252 expect(matched(['foo', 'bar', 'baz'], ['!foo', '*'])).to.eql(['foo', 'bar', 'baz']); // expected?
253
254 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!foo', '!bar'])).to.eql(['baz']);
255 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!foo', '!bar'])).to.eql(['baz']);
256 expect(matched(['foo', 'bar', 'baz'], ['*', '!foo', '!bar'])).to.eql(['baz']);
257
258 expect(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*'])).to.eql(['baz', 'foo', 'bar']); // expected?
259 expect(globMatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*'])).to.eql(['foo', 'bar', 'baz']); // expected?
260 expect(matched(['foo', 'bar', 'baz'], ['!*{o,r}', '*'])).to.eql(['foo', 'bar', 'baz']); // expected?
261
262 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']);
263 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']);
264 expect(matched(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']);
265
266 expect(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', '*'])).to.eql(['foo', 'bar', 'baz']); // expected?
267 expect(globMatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', '*'])).to.eql(['foo', 'bar', 'baz']); // expected?
268 expect(matched(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', '*'])).to.eql(['foo', 'bar', 'baz']); // expected?
269
270 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}', 'foo'])).to.eql(['baz', 'foo']); // expected?
271 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}', 'foo'])).to.eql(['baz', 'foo']); // expected?
272 expect(matched(['foo', 'bar', 'baz'], ['*', '!*{o,r}', 'foo'])).to.eql(['baz', 'foo']); // expected?
273
274 expect(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*', 'foo'])).to.eql(['baz', 'foo', 'bar']); // expected?
275 expect(globMatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*', 'foo'])).to.eql(['foo', 'bar', 'baz']); // expected?
276 expect(matched(['foo', 'bar', 'baz'], ['!*{o,r}', '*', 'foo'])).to.eql(['foo', 'bar', 'baz']); // expected?
277
278 expect(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]); // expected?
279 expect(globMatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]); // expected?
280 expect(matched(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]); // expected?
281
282 expect(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', 'foo'])).to.eql(['foo']);
283 expect(globMatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', 'foo'])).to.eql(['foo']);
284 expect(matched(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', 'foo'])).to.eql(['foo']);
285
286 expect(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['baz', 'foo']);
287 expect(globMatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['foo']);
288 expect(matched(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['foo']);
289
290 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']);
291 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']);
292 expect(matched(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']);
293
294 expect(multimatch(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']);
295 expect(globMatch(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']);
296 expect(matched(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']);
297
298 expect(multimatch(['foo', 'bar', 'baz'], ['!foo'])).to.eql(['bar', 'baz']); // expected?
299 expect(globMatch(['foo', 'bar', 'baz'], ['!foo'])).to.eql([]); // expected?
300 expect(matched(['foo', 'bar', 'baz'], ['!foo'])).to.eql([]); // expected?
301
302 expect(multimatch(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
303 expect(globMatch(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
304 expect(matched(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']);
305
306 expect(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']);
307 expect(globMatch(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']);
308 expect(matched(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']);
309
310 expect(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']);
311 expect(globMatch(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']);
312 expect(matched(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']);
313 expect(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar', 'baz']); // expected?
314 expect(globMatch(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar']); // expected?
315 expect(matched(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar']); // expected?
316
317 expect(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql(['baz']);
318 expect(globMatch(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql([]);
319 expect(matched(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql([]);
320 expect(multimatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['once', '!o*', 'once'])).to.eql(['once']);
321 expect(globMatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['once', '!o*', 'once'])).to.eql(['once']);
322 expect(matched(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['once', '!o*', 'once'])).to.eql(['once']);
323 expect(multimatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['*', '!o*', 'once'])).to.eql(['foo', 'two', 'four', 'do', 'once']);
324 expect(globMatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['*', '!o*', 'once'])).to.eql(['foo', 'two', 'four', 'do', 'once']);
325 expect(matched(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['*', '!o*', 'once'])).to.eql(['foo', 'two', 'four', 'do', 'once']);
326 done();
327 });
328});
329
330
331/**
332 * Tests from globule
333 * @return {[type]} [description]
334 */
335
336describe('globule', function () {
337 it('Should return empty set if a required argument is missing or an empty set.', function (done) {
338 expect(multimatch('', 'foo.js')).to.eql([]);
339 expect(globMatch('', 'foo.js')).to.eql([]);
340 expect(matched('', 'foo.js')).to.eql([]);
341 expect(multimatch('*.js', '')).to.eql([]);
342 expect(globMatch('*.js', '')).to.eql([]);
343 expect(matched('*.js', '')).to.eql([]);
344 expect(multimatch([], 'foo.js')).to.eql([]);
345 expect(globMatch([], 'foo.js')).to.eql([]);
346 expect(matched([], 'foo.js')).to.eql([]);
347 expect(multimatch('*.js', [])).to.eql([]);
348 expect(globMatch('*.js', [])).to.eql([]);
349 expect(matched('*.js', [])).to.eql([]);
350 expect(multimatch('', ['foo.js'])).to.eql([]);
351 expect(globMatch('', ['foo.js'])).to.eql([]);
352 expect(matched('', ['foo.js'])).to.eql([]);
353 expect(multimatch(['*.js'], '')).to.eql([]);
354 expect(globMatch(['*.js'], '')).to.eql([]);
355 expect(matched(['*.js'], '')).to.eql([]);
356 done();
357 });
358
359 it('basic matching should match correctly', function (done) {
360 expect(multimatch('foo.js', '*.js')).to.eql(['foo.js']);
361 expect(globMatch('foo.js', '*.js')).to.eql(['foo.js']);
362 expect(matched('foo.js', '*.js')).to.eql(['foo.js']);
363 expect(multimatch(['foo.js'], '*.js')).to.eql(['foo.js']);
364 expect(globMatch(['foo.js'], '*.js')).to.eql(['foo.js']);
365 expect(matched(['foo.js'], '*.js')).to.eql(['foo.js']);
366 expect(multimatch(['foo.js', 'bar.css'], '*.js')).to.eql(['foo.js']);
367 expect(globMatch(['foo.js', 'bar.css'], '*.js')).to.eql(['foo.js']);
368 expect(matched(['foo.js', 'bar.css'], '*.js')).to.eql(['foo.js']);
369 expect(multimatch('foo.js', ['*.js', '*.css'])).to.eql(['foo.js']);
370 expect(globMatch('foo.js', ['*.js', '*.css'])).to.eql(['foo.js']);
371 expect(matched('foo.js', ['*.js', '*.css'])).to.eql(['foo.js']);
372 expect(multimatch(['foo.js'], ['*.js', '*.css'])).to.eql(['foo.js']);
373 expect(globMatch(['foo.js'], ['*.js', '*.css'])).to.eql(['foo.js']);
374 expect(matched(['foo.js'], ['*.js', '*.css'])).to.eql(['foo.js']);
375 expect(multimatch(['foo.js', 'bar.css'], ['*.js', '*.css'])).to.eql(['foo.js', 'bar.css']);
376 expect(globMatch(['foo.js', 'bar.css'], ['*.js', '*.css'])).to.eql(['foo.js', 'bar.css']);
377 expect(matched(['foo.js', 'bar.css'], ['*.js', '*.css'])).to.eql(['foo.js', 'bar.css']);
378 done();
379 });
380
381 describe('no matches:', function () {
382 it('should fail to match', function (done) {
383 expect(multimatch('foo.css', '*.js')).to.eql([]);
384 expect(globMatch('foo.css', '*.js')).to.eql([]);
385 expect(matched('foo.css', '*.js')).to.eql([]);
386 expect(multimatch(['foo.css', 'bar.css'], '*.js')).to.eql([]);
387 expect(globMatch(['foo.css', 'bar.css'], '*.js')).to.eql([]);
388 expect(matched(['foo.css', 'bar.css'], '*.js')).to.eql([]);
389 done();
390 });
391 });
392
393 describe('unique:', function () {
394 it('should return a uniqued set', function (done) {
395 expect(multimatch(['foo.js', 'foo.js'], '*.js')).to.eql(['foo.js']);
396 expect(globMatch(['foo.js', 'foo.js'], '*.js')).to.eql(['foo.js']);
397 expect(matched(['foo.js', 'foo.js'], '*.js')).to.eql(['foo.js']);
398 expect(multimatch(['foo.js', 'foo.js'], ['*.js', '*.*'])).to.eql(['foo.js']);
399 expect(globMatch(['foo.js', 'foo.js'], ['*.js', '*.*'])).to.eql(['foo.js']);
400 expect(matched(['foo.js', 'foo.js'], ['*.js', '*.*'])).to.eql(['foo.js']);
401 done();
402 });
403 });
404
405 describe('flatten:', function () {
406 it('should process nested pattern / filepaths arrays correctly', function (done) {
407 // expect(multimatch([['foo.js', ['bar.css']]], [['*.js', '*.css'], ['*.*', '*.js']])).to.eql(['foo.js', 'bar.css']); // multimatch fails
408 expect(globMatch([['foo.js', ['bar.css']]], [['*.js', '*.css'], ['*.*', '*.js']])).to.eql(['foo.js', 'bar.css']);
409 expect(matched([['foo.js', ['bar.css']]], [['*.js', '*.css'], ['*.*', '*.js']])).to.eql(['foo.js', 'bar.css']);
410 done();
411 });
412 });
413
414 describe('exclusion:', function () {
415 it('solitary exclusion should match nothing', function (done) {
416 expect(multimatch(['foo.js', 'bar.js'], ['!*.js'])).to.eql([]);
417 expect(globMatch(['foo.js', 'bar.js'], ['!*.js'])).to.eql([]);
418 expect(matched(['foo.js', 'bar.js'], ['!*.js'])).to.eql([]);
419 done();
420 });
421 it('exclusion should cancel match', function (done) {
422 expect(multimatch(['foo.js', 'bar.js'], ['*.js', '!*.js'])).to.eql([]);
423 expect(globMatch(['foo.js', 'bar.js'], ['*.js', '!*.js'])).to.eql([]);
424 expect(matched(['foo.js', 'bar.js'], ['*.js', '!*.js'])).to.eql([]);
425 done();
426 });
427 it('partial exclusion should partially cancel match', function (done) {
428 expect(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js'])).to.eql(['bar.js', 'baz.js']);
429 expect(globMatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js'])).to.eql(['bar.js', 'baz.js']);
430 expect(matched(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js'])).to.eql(['bar.js', 'baz.js']);
431 done();
432 });
433 it('inclusion / exclusion order matters', function (done) {
434 expect(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!*.js', 'b*.js'])).to.eql(['bar.js', 'baz.js']);
435 expect(globMatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!*.js', 'b*.js'])).to.eql(['bar.js', 'baz.js']);
436 expect(matched(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!*.js', 'b*.js'])).to.eql(['bar.js', 'baz.js']);
437 done();
438 });
439 it('inclusion / exclusion order matters', function (done) {
440 expect(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js', '*.js'])).to.eql(['bar.js', 'baz.js', 'foo.js']);
441 expect(globMatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js', '*.js'])).to.eql(['bar.js', 'baz.js', 'foo.js']);
442 expect(matched(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js', '*.js'])).to.eql(['bar.js', 'baz.js', 'foo.js']);
443 done();
444 });
445 });
446
447 describe('options.matchBase:', function () {
448 it('should matchBase (minimatch) when specified.', function (done) {
449 expect(multimatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js', {matchBase: true})).to.eql(['foo.js', 'baz/xyz.js']);
450 expect(globMatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js', {matchBase: true})).to.eql(['foo.js', 'baz/xyz.js']);
451 expect(matched(['foo.js', 'bar', 'baz/xyz.js'], '*.js', {matchBase: true})).to.eql(['foo.js', 'baz/xyz.js']);
452 done();
453 });
454
455 it('should not matchBase (minimatch) by default.', function (done) {
456 expect(multimatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js')).to.eql(['foo.js']);
457 expect(globMatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js')).to.eql(['foo.js']);
458 expect(matched(['foo.js', 'bar', 'baz/xyz.js'], '*.js')).to.eql(['foo.js']);
459 done();
460 });
461 });
462});