Skip to content

Commit

Permalink
test: enhance exclude & matching testings
Browse files Browse the repository at this point in the history
  • Loading branch information
WindomZ committed Apr 28, 2017
1 parent bb8a370 commit e1bd05e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/exclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {matchingString, matchingRegular} = require('./matching')
* @api public
*/
function exclude (file, isDirectory) {
if (!file) return false
if (isDirectory) {
if (excludeMatching(file, list.dirs.matching)) {
return true
Expand Down
22 changes: 20 additions & 2 deletions lib/matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
* Created by WindomZ on 17-4-26.
*/

function matchingString (src = '', matching = []) {
/**
* Match src from matching strings Array.
*
* @param {string} src
* @param {Array} matching
* @return boolean
* @api public
*/
function matchingString (src, matching) {
if (!src || !matching) return false
let result = false
matching.some(item => {
if (src.toLowerCase() === item.toLowerCase()) {
Expand All @@ -13,7 +22,16 @@ function matchingString (src = '', matching = []) {
return result
}

function matchingRegular (src = '', regular = []) {
/**
* Regular src from matching regulars Array.
*
* @param {string} src
* @param {Array} regular
* @return boolean
* @api public
*/
function matchingRegular (src, regular) {
if (!src || !regular) return false
let result = false
regular.some(item => {
if (src.toLowerCase().match(new RegExp(item, 'i'))) {
Expand Down
6 changes: 5 additions & 1 deletion test/exclude.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const test = require('ava')

const exclude = require('../lib/exclude')

test.serial('exclude pass', t => {
test('exclude pass', t => {
t.true(exclude('node_modules', true))
t.false(exclude('node_modules', false))

Expand All @@ -18,4 +18,8 @@ test.serial('exclude pass', t => {
t.true(exclude('.xxx', false))
t.false(exclude('xxx', true))
t.false(exclude('xxx', false))

t.false(exclude(undefined, true))
t.false(exclude(undefined, undefined))
t.false(exclude(null, null))
})
19 changes: 19 additions & 0 deletions test/matching.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Created by WindomZ on 17-4-28.
*/
const test = require('ava')

const {matchingString, matchingRegular} = require('../lib/matching')

test('matching pass', t => {
t.true(matchingString('node_modules', ['node_modules']))
t.false(matchingString('node_modules', ['node_modules-x']))

t.true(matchingRegular('node_modules', ['^node']))
t.false(matchingRegular('node_modules', ['^modules']))

t.false(matchingString(undefined, undefined))
t.false(matchingString(null, null))
t.false(matchingRegular(undefined, undefined))
t.false(matchingRegular(null, null))
})

0 comments on commit e1bd05e

Please sign in to comment.