-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { buildPredicate } from '../../../../src/utils/predicateBuilder/predicateBuilder'; | ||
|
||
describe(`predicate builder`, () => { | ||
it(`should return truthy predicate from undefined include and exclude`, () => { | ||
const predicate = buildPredicate(undefined, undefined); | ||
expect(predicate(`dummy`)).toBe(true); | ||
}); | ||
|
||
it(`should return truthy predicate from empty include and exclude`, () => { | ||
const predicate = buildPredicate(``, ``); | ||
expect(predicate(`dummy`)).toBe(true); | ||
}); | ||
|
||
it(`should return truthy predicate from empty (after trim) include and exclude`, () => { | ||
const predicate = buildPredicate(` `, ` `); | ||
expect(predicate(`dummy`)).toBe(true); | ||
}); | ||
|
||
it(`should return falsy predicate if include equals exclude`, () => { | ||
const predicate = buildPredicate(`a`, `a`); | ||
expect(predicate(`a`)).toBe(false); | ||
expect(predicate(`b`)).toBe(false); | ||
}); | ||
|
||
it(`should predicate based on include only`, () => { | ||
const predicate = buildPredicate(`a b c, d`, undefined); | ||
expect(predicate(`a`)).toBe(true); | ||
expect(predicate(`b`)).toBe(true); | ||
expect(predicate(`c`)).toBe(true); | ||
expect(predicate(`d`)).toBe(true); | ||
expect(predicate(`dummy`)).toBe(false); | ||
expect(predicate(`ab`)).toBe(false); | ||
}); | ||
|
||
it(`should predicate based on exclude only`, () => { | ||
const predicate = buildPredicate(undefined, `a b c, d`); | ||
expect(predicate(`a`)).toBe(false); | ||
expect(predicate(`b`)).toBe(false); | ||
expect(predicate(`c`)).toBe(false); | ||
expect(predicate(`d`)).toBe(false); | ||
expect(predicate(`dummy`)).toBe(true); | ||
expect(predicate(`ab`)).toBe(true); | ||
}); | ||
|
||
it(`should predicate based on include and exclude`, () => { | ||
const predicate = buildPredicate(`a, b`, `c, d`); | ||
expect(predicate(`a`)).toBe(true); | ||
expect(predicate(`b`)).toBe(true); | ||
expect(predicate(`c`)).toBe(false); | ||
expect(predicate(`d`)).toBe(false); | ||
expect(predicate(`dummy`)).toBe(false); | ||
expect(predicate(`ab`)).toBe(false); | ||
}); | ||
|
||
it(`should predicate based on include and exclude intersection`, () => { | ||
const predicate = buildPredicate(`/a/`, `a`); | ||
expect(predicate(`a`)).toBe(false); | ||
expect(predicate(`ab`)).toBe(true); | ||
expect(predicate(`c`)).toBe(false); | ||
}); | ||
|
||
it(`should predicate based on include and exclude intersection 2`, () => { | ||
const predicate = buildPredicate(`a`, `/a/`); | ||
expect(predicate(`a`)).toBe(false); | ||
expect(predicate(`ab`)).toBe(false); | ||
expect(predicate(`c`)).toBe(false); | ||
}); | ||
|
||
it(`should predicate based on regex flags`, () => { | ||
const predicate = buildPredicate(`/a/`, undefined); | ||
expect(predicate(`a`)).toBe(true); | ||
expect(predicate(`A`)).toBe(false); | ||
}); | ||
|
||
it(`should predicate based on regex flags 2`, () => { | ||
const predicate = buildPredicate(`/a/i`, undefined); | ||
expect(predicate(`a`)).toBe(true); | ||
expect(predicate(`A`)).toBe(true); | ||
}); | ||
|
||
it(`should predicate based on regex global flag`, () => { | ||
const predicate = buildPredicate(`/a/g`, undefined); | ||
expect(predicate(`a`)).toBe(true); | ||
expect(predicate(`a`)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters