Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: string match function naming (#27392)
- Loading branch information
Showing
12 changed files
with
65 additions
and
75 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
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 |
---|---|---|
@@ -1,93 +1,89 @@ | ||
import { | ||
anyMatchRegexOrMinimatch, | ||
configRegexPredicate, | ||
matchRegexOrMinimatch, | ||
getRegexPredicate, | ||
matchRegexOrGlob, | ||
matchRegexOrGlobList, | ||
} from './string-match'; | ||
|
||
describe('util/string-match', () => { | ||
describe('anyMatchRegexOrMinimatch()', () => { | ||
describe('matchRegexOrGlobList()', () => { | ||
it('returns false if empty patterns', () => { | ||
expect(anyMatchRegexOrMinimatch('test', [])).toBeFalse(); | ||
expect(matchRegexOrGlobList('test', [])).toBeFalse(); | ||
}); | ||
|
||
it('returns false if no match', () => { | ||
expect(anyMatchRegexOrMinimatch('test', ['/test2/'])).toBeFalse(); | ||
expect(matchRegexOrGlobList('test', ['/test2/'])).toBeFalse(); | ||
}); | ||
|
||
it('returns true if any match', () => { | ||
expect(anyMatchRegexOrMinimatch('test', ['test', '/test2/'])).toBeTrue(); | ||
expect(matchRegexOrGlobList('test', ['test', '/test2/'])).toBeTrue(); | ||
}); | ||
|
||
it('returns true if one match with negative patterns', () => { | ||
expect(anyMatchRegexOrMinimatch('test', ['!/test2/'])).toBeTrue(); | ||
expect(matchRegexOrGlobList('test', ['!/test2/'])).toBeTrue(); | ||
}); | ||
|
||
it('returns true if every match with negative patterns', () => { | ||
expect( | ||
anyMatchRegexOrMinimatch('test', ['!/test2/', '!/test3/']), | ||
).toBeTrue(); | ||
expect(matchRegexOrGlobList('test', ['!/test2/', '!/test3/'])).toBeTrue(); | ||
}); | ||
|
||
it('returns true if matching positive and negative patterns', () => { | ||
expect(anyMatchRegexOrMinimatch('test', ['test', '!/test3/'])).toBeTrue(); | ||
expect(matchRegexOrGlobList('test', ['test', '!/test3/'])).toBeTrue(); | ||
}); | ||
|
||
it('returns true if matching every negative pattern (regex)', () => { | ||
expect( | ||
anyMatchRegexOrMinimatch('test', ['test', '!/test3/', '!/test4/']), | ||
matchRegexOrGlobList('test', ['test', '!/test3/', '!/test4/']), | ||
).toBeTrue(); | ||
}); | ||
|
||
it('returns false if not matching every negative pattern (regex)', () => { | ||
expect( | ||
anyMatchRegexOrMinimatch('test', ['!/test3/', '!/test/']), | ||
).toBeFalse(); | ||
expect(matchRegexOrGlobList('test', ['!/test3/', '!/test/'])).toBeFalse(); | ||
}); | ||
|
||
it('returns true if matching every negative pattern (glob)', () => { | ||
expect( | ||
anyMatchRegexOrMinimatch('test', ['test', '!test3', '!test4']), | ||
matchRegexOrGlobList('test', ['test', '!test3', '!test4']), | ||
).toBeTrue(); | ||
}); | ||
|
||
it('returns false if not matching every negative pattern (glob)', () => { | ||
expect(anyMatchRegexOrMinimatch('test', ['!test3', '!te*'])).toBeFalse(); | ||
expect(matchRegexOrGlobList('test', ['!test3', '!te*'])).toBeFalse(); | ||
}); | ||
}); | ||
|
||
describe('configRegexPredicate', () => { | ||
describe('getRegexPredicate()', () => { | ||
it('allows valid regex pattern', () => { | ||
expect(configRegexPredicate('/hello/')).not.toBeNull(); | ||
expect(getRegexPredicate('/hello/')).not.toBeNull(); | ||
}); | ||
|
||
it('invalidates invalid regex pattern', () => { | ||
expect(configRegexPredicate('/^test\\d+$/m')).toBeNull(); | ||
expect(getRegexPredicate('/^test\\d+$/m')).toBeNull(); | ||
}); | ||
|
||
it('allows the i flag in regex pattern', () => { | ||
expect(configRegexPredicate('/^test\\d+$/i')).not.toBeNull(); | ||
expect(getRegexPredicate('/^test\\d+$/i')).not.toBeNull(); | ||
}); | ||
|
||
it('allows negative regex pattern', () => { | ||
expect(configRegexPredicate('!/^test\\d+$/i')).not.toBeNull(); | ||
expect(getRegexPredicate('!/^test\\d+$/i')).not.toBeNull(); | ||
}); | ||
|
||
it('does not allow non-regex input', () => { | ||
expect(configRegexPredicate('hello')).toBeNull(); | ||
expect(getRegexPredicate('hello')).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('matchRegexOrMinimatch()', () => { | ||
describe('matchRegexOrGlob()', () => { | ||
it('returns true if positive regex pattern matched', () => { | ||
expect(matchRegexOrMinimatch('test', '/test/')).toBeTrue(); | ||
expect(matchRegexOrGlob('test', '/test/')).toBeTrue(); | ||
}); | ||
|
||
it('returns true if negative regex is not matched', () => { | ||
expect(matchRegexOrMinimatch('test', '!/test3/')).toBeTrue(); | ||
expect(matchRegexOrGlob('test', '!/test3/')).toBeTrue(); | ||
}); | ||
|
||
it('returns false if negative pattern is matched', () => { | ||
expect(matchRegexOrMinimatch('test', '!/te/')).toBeFalse(); | ||
expect(matchRegexOrGlob('test', '!/te/')).toBeFalse(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.