From a7982b0e347070038e0e9050bb3f20e201c75200 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Wed, 6 Feb 2013 12:12:43 -0800 Subject: [PATCH] Support for include/excludes as arrays --- lib/fileset.js | 5 ++-- tests/fixtures/an (odd) filename.js | 1 + tests/test.js | 38 ++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 tests/fixtures/an (odd) filename.js diff --git a/lib/fileset.js b/lib/fileset.js index 0abb200..a74077c 100644 --- a/lib/fileset.js +++ b/lib/fileset.js @@ -9,9 +9,10 @@ function fileset(include, exclude, options, cb) { if (typeof exclude === 'function') cb = exclude, exclude = ''; else if (typeof options === 'function') cb = options, options = {}; + var includes = (typeof include === 'string') ? include.split(' ') : include; + var excludes = (typeof exclude === 'string') ? exclude.split(' ') : exclude; + var em = new EventEmitter, - includes = include.split(' '), - excludes = exclude.split(' '), remaining = includes.length, results = []; diff --git a/tests/fixtures/an (odd) filename.js b/tests/fixtures/an (odd) filename.js new file mode 100644 index 0000000..fbf9f2b --- /dev/null +++ b/tests/fixtures/an (odd) filename.js @@ -0,0 +1 @@ +var odd = true; \ No newline at end of file diff --git a/tests/test.js b/tests/test.js index 677e0c2..cb0ceb1 100644 --- a/tests/test.js +++ b/tests/test.js @@ -27,7 +27,7 @@ test('Say we want the **.js files, but not those in node_modules', function() { fileset('**/*.js', 'node_modules/**', function(err, results) { if(err) return em.emit('error', err); assert.ok(Array.isArray(results), 'should be an array'); - assert.equal(results.length, 3); + assert.equal(results.length, 4); em.emit('end'); }); }, @@ -36,11 +36,12 @@ test('Say we want the **.js files, but not those in node_modules', function() { fileset('**/*.js *.md', 'node_modules/**', function(err, results) { if(err) return em.emit('error', err); assert.ok(Array.isArray(results), 'should be an array'); - assert.equal(results.length, 4); + assert.equal(results.length, 5); assert.deepEqual(results, [ 'README.md', 'lib/fileset.js', + 'tests/fixtures/an (odd) filename.js', 'tests/helper.js', 'tests/test.js' ]); @@ -53,10 +54,11 @@ test('Say we want the **.js files, but not those in node_modules', function() { fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) { if(err) return em.emit('error', err); assert.ok(Array.isArray(results), 'should be an array'); - assert.equal(results.length, 1); + assert.equal(results.length, 2); assert.deepEqual(results, [ - 'lib/fileset.js' + 'lib/fileset.js', + 'tests/fixtures/an (odd) filename.js', ]); em.emit('end'); @@ -75,7 +77,7 @@ test('Testing out emmited events', function() { .on('error', em.emit.bind(em, 'error')) .on('end', function(results) { assert.ok(Array.isArray(results), 'should be an array'); - assert.equal(results.length, 3); + assert.equal(results.length, 4); em.emit('end'); }); }, @@ -85,11 +87,12 @@ test('Testing out emmited events', function() { .on('error', em.emit.bind(em, 'error')) .on('end', function(results) { assert.ok(Array.isArray(results), 'should be an array'); - assert.equal(results.length, 4); + assert.equal(results.length, 5); assert.deepEqual(results, [ 'README.md', 'lib/fileset.js', + 'tests/fixtures/an (odd) filename.js', 'tests/helper.js', 'tests/test.js' ]); @@ -101,6 +104,29 @@ test('Testing out emmited events', function() { }); +test('Testing patterns passed as arrays', function() { + + return { + 'Should match files passed as an array with odd filenames': function(em) { + fileset(['lib/*.js', 'tests/fixtures/an (odd) filename.js'], ['node_modules/**']) + .on('error', em.emit.bind(em, 'error')) + .on('end', function(results) { + assert.ok(Array.isArray(results), 'should be an array'); + assert.equal(results.length, 2); + + assert.deepEqual(results, [ + 'lib/fileset.js', + 'tests/fixtures/an (odd) filename.js', + ]); + + em.emit('end'); + }); + } + } + +}); + + test.run();