Skip to content

Commit

Permalink
refactor(utils): Prevent double negative symbol when converting patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed May 1, 2018
1 parent 69a905d commit 22a0850
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/utils/pattern.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ describe('Utils → Pattern', () => {

assert.equal(actual, expected);
});

it('should returns pattern without changes', () => {
const expected: Pattern = '!*.js';

const actual = util.convertToNegativePattern('!*.js');

assert.equal(actual, expected);
});
});

describe('.isNegativePattern', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ export function unixifyPattern(pattern: Pattern): Pattern {
}

/**
* Returns negative pattern as positive pattern.
* Returns negative pattern as positive pattern if required.
*/
export function convertToPositivePattern(pattern: Pattern): Pattern {
return isNegativePattern(pattern) ? pattern.slice(1) : pattern;
}

/**
* Returns positive pattern as negative pattern.
* Returns positive pattern as negative pattern if required.
*/
export function convertToNegativePattern(pattern: Pattern): Pattern {
return '!' + pattern;
return isNegativePattern(pattern) ? pattern : '!' + pattern;
}

/**
Expand Down

0 comments on commit 22a0850

Please sign in to comment.