diff --git a/demo/src/utils/wordList.spec.ts b/demo/src/utils/wordList.spec.ts index 0a6eb3a..78a8a84 100644 --- a/demo/src/utils/wordList.spec.ts +++ b/demo/src/utils/wordList.spec.ts @@ -1,69 +1,48 @@ import { parseString, WhitespaceHandling } from './wordList'; -interface TestCase { - delimiter: string; - inputString: string; -} - const { Preserve, TrimLeadingAndTrailing } = WhitespaceHandling; describe('parseString', () => { - it('returns an empty array when input string is empty', () => { - function testInput(input: string): void { - const wordList = parseString(input, ',', Preserve); + it.each(['', null, undefined])( + 'returns an empty array when input string is %p', + input => { + const wordList = parseString(input as string, ',', Preserve); expect(wordList).toEqual([]); } + ); - ['', null, undefined].forEach(val => testInput(val as string)); - }); - - it('returns entire input string in array when delimiter is empty', () => { - function testDelimiter(delimiter: string): void { + it.each(['', null, undefined])( + 'returns entire input string in array when delimiter is %p', + testDelimiter => { + const delimiter = testDelimiter as string; const wordList = parseString(' some input string ', delimiter, Preserve); expect(wordList).toEqual([' some input string ']); } + ); - ['', null, undefined].forEach(val => testDelimiter(val as string)); - }); - - it('returns entire input string in array when delimiter is not present in input string', () => { - function testDelimiter(delimiter: string): void { + it.each([',', '\n', '\t'])( + 'returns entire input string in array when delimiter %p is not present in input string', + delimiter => { const wordList = parseString(' some input string ', delimiter, Preserve); expect(wordList).toEqual([' some input string ']); } - - [',', '\n', '\t'].forEach(testDelimiter); - }); - - it('splits input string by delimiter', () => { - const expectedResult = ['foo', 'Bar', ' b@z ']; - const testCases: TestCase[] = [ - { delimiter: ',', inputString: 'foo,Bar, b@z ' }, - { delimiter: '\t', inputString: 'foo Bar b@z ' }, - { delimiter: 'aaa', inputString: 'fooaaaBaraaa b@z ' }, - ]; - - function testSplit({ delimiter, inputString }: TestCase): void { - const wordList = parseString(inputString, delimiter, Preserve); - expect(wordList).toEqual(expectedResult); - } - - testCases.forEach(testSplit); + ); + + it.each([ + ['foo,Bar, b@z ', ','], + ['foo Bar b@z ', '\t'], + ['fooaaaBaraaa b@z ', 'aaa'], + ])('splits input string %p by delimiter %p', (inputString, delimiter) => { + const wordList = parseString(inputString, delimiter, Preserve); + expect(wordList).toEqual(['foo', 'Bar', ' b@z ']); }); - it('splits input string by whitespace delimiter', () => { - const expectedResult = ['foo', 'Bar', 'b@z', '']; - const testCases: TestCase[] = [ - { delimiter: ' ', inputString: 'foo Bar b@z ' }, - { delimiter: ' ', inputString: 'foo Bar b@z ' }, - ]; - - function testSplit({ delimiter, inputString }: TestCase): void { - const wordList = parseString(inputString, delimiter, Preserve); - expect(wordList).toEqual(expectedResult); - } - - testCases.forEach(testSplit); + it.each([ + ['foo Bar b@z ', ' '], + ['foo Bar b@z ', ' '], + ])('splits input string %p by delimiter %p', (inputString, delimiter) => { + const wordList = parseString(inputString, delimiter, Preserve); + expect(wordList).toEqual(['foo', 'Bar', 'b@z', '']); }); it('splits multiline input string by newline delimiter', () => { diff --git a/package.json b/package.json index db53502..0e1ed9f 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "@types/jest-when": "^2.7.0", "@typescript-eslint/eslint-plugin": "^2.2.0", "@typescript-eslint/parser": "^2.2.0", - "codecov": "^3.6.1", "eslint": "6.1.0", "eslint-config-airbnb-base": "14.0.0", "eslint-config-prettier": "^6.3.0", @@ -61,12 +60,11 @@ "eslint-plugin-jest": "^22.17.0", "husky": "^0.14.3", "jest": "^26.0.0", - "jest-when": "^2.7.0", + "jest-when": "^3.1.0", "npm-run-all": "^4.1.5", "prettier": "^1.13.7", "pretty-quick": "^1.6.0", - "regenerator-runtime": "^0.13.3", - "regex-to-strings": "^1.0.0", + "regex-to-strings": "^2.0.1", "rimraf": "^2.6.2", "ts-jest": "^26.4.4", "ts-loader": "^6.1.0", diff --git a/src/utils/pattern.spec.ts b/src/utils/pattern.spec.ts index c35b91b..6437bc1 100644 --- a/src/utils/pattern.spec.ts +++ b/src/utils/pattern.spec.ts @@ -1,5 +1,3 @@ -import 'regenerator-runtime/runtime'; - import { expandAll } from 'regex-to-strings'; import { CharTrie } from '../types/charTrie'; import { build } from './pattern';