diff options
| author | Eric Cheng <[email protected]> | 2022-11-14 17:56:49 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-14 22:56:49 +0000 |
| commit | 801e9e0a6afa2bd472652eb7aaee5581ef458342 (patch) | |
| tree | e33cf4d8682583164606e62d49876806664eb9d2 /test | |
| parent | 66ccca3e11721647c4c13179eb1e23f13d43ef03 (diff) | |
| download | faker-801e9e0a6afa2bd472652eb7aaee5581ef458342.tar.xz faker-801e9e0a6afa2bd472652eb7aaee5581ef458342.zip | |
refactor(string): rename params (#1551)
Diffstat (limited to 'test')
| -rw-r--r-- | test/__snapshots__/string.spec.ts.snap | 48 | ||||
| -rw-r--r-- | test/random.spec.ts | 8 | ||||
| -rw-r--r-- | test/string.spec.ts | 124 |
3 files changed, 90 insertions, 90 deletions
diff --git a/test/__snapshots__/string.spec.ts.snap b/test/__snapshots__/string.spec.ts.snap index f4a607b4..bcac1178 100644 --- a/test/__snapshots__/string.spec.ts.snap +++ b/test/__snapshots__/string.spec.ts.snap @@ -2,14 +2,14 @@ exports[`string > 42 > alpha > noArgs 1`] = `"t"`; -exports[`string > 42 > alpha > with bannedChars 1`] = `"A"`; - exports[`string > 42 > alpha > with casing = lower 1`] = `"j"`; exports[`string > 42 > alpha > with casing = mixed 1`] = `"t"`; exports[`string > 42 > alpha > with casing = upper 1`] = `"J"`; +exports[`string > 42 > alpha > with exclude 1`] = `"A"`; + exports[`string > 42 > alpha > with length 1`] = `"tPXjMO"`; exports[`string > 42 > alpha > with length parameter 1`] = `"tPXjM"`; @@ -22,18 +22,18 @@ exports[`string > 42 > alpha > with length parameter 4`] = `"rFhKH"`; exports[`string > 42 > alpha > with length parameter 5`] = `"bcYLR"`; -exports[`string > 42 > alpha > with length, casing and bannedChars 1`] = `"fwzcvwj"`; +exports[`string > 42 > alpha > with length, casing and exclude 1`] = `"fwzcvwj"`; exports[`string > 42 > alphanumeric > noArgs 1`] = `"n"`; -exports[`string > 42 > alphanumeric > with bannedChars 1`] = `"x"`; - exports[`string > 42 > alphanumeric > with casing = lower 1`] = `"d"`; exports[`string > 42 > alphanumeric > with casing = mixed 1`] = `"n"`; exports[`string > 42 > alphanumeric > with casing = upper 1`] = `"D"`; +exports[`string > 42 > alphanumeric > with exclude 1`] = `"x"`; + exports[`string > 42 > alphanumeric > with length 1`] = `"nNWbJM"`; exports[`string > 42 > alphanumeric > with length parameter 1`] = `"nNWbJ"`; @@ -46,7 +46,7 @@ exports[`string > 42 > alphanumeric > with length parameter 4`] = `"kB8HE"`; exports[`string > 42 > alphanumeric > with length parameter 5`] = `"13YIP"`; -exports[`string > 42 > alphanumeric > with length, casing and bannedChars 1`] = `"cvy4kvh"`; +exports[`string > 42 > alphanumeric > with length, casing and exclude 1`] = `"cvy4kvh"`; exports[`string > 42 > hexadecimal > noArgs 1`] = `"0x8"`; @@ -66,7 +66,7 @@ exports[`string > 42 > numeric > noArgs 1`] = `"4"`; exports[`string > 42 > numeric > with allowLeadingZeros 1`] = `"3"`; -exports[`string > 42 > numeric > with bannedDigits 1`] = `"7"`; +exports[`string > 42 > numeric > with exclude 1`] = `"7"`; exports[`string > 42 > numeric > with length 1`] = `"479177"`; @@ -80,7 +80,7 @@ exports[`string > 42 > numeric > with length parameter 4`] = `"46176"`; exports[`string > 42 > numeric > with length parameter 5`] = `"10978"`; -exports[`string > 42 > numeric > with length, allowLeadingZeros and bannedDigits 1`] = `"6890887"`; +exports[`string > 42 > numeric > with length, allowLeadingZeros and exclude 1`] = `"6890887"`; exports[`string > 42 > sample > noArgs 1`] = `"Cky2eiXX/J"`; @@ -106,14 +106,14 @@ exports[`string > 42 > uuid 5`] = `"d95f4984-24c2-410f-ac63-400d3bbbcc91"`; exports[`string > 1211 > alpha > noArgs 1`] = `"W"`; -exports[`string > 1211 > alpha > with bannedChars 1`] = `"X"`; - exports[`string > 1211 > alpha > with casing = lower 1`] = `"y"`; exports[`string > 1211 > alpha > with casing = mixed 1`] = `"W"`; exports[`string > 1211 > alpha > with casing = upper 1`] = `"Y"`; +exports[`string > 1211 > alpha > with exclude 1`] = `"X"`; + exports[`string > 1211 > alpha > with length 1`] = `"WxUOlg"`; exports[`string > 1211 > alpha > with length parameter 1`] = `"WxUOl"`; @@ -126,18 +126,18 @@ exports[`string > 1211 > alpha > with length parameter 4`] = `"iKMQa"`; exports[`string > 1211 > alpha > with length parameter 5`] = `"NIILR"`; -exports[`string > 1211 > alpha > with length, casing and bannedChars 1`] = `"yhywdcz"`; +exports[`string > 1211 > alpha > with length, casing and exclude 1`] = `"yhywdcz"`; exports[`string > 1211 > alphanumeric > noArgs 1`] = `"V"`; -exports[`string > 1211 > alphanumeric > with bannedChars 1`] = `"W"`; - exports[`string > 1211 > alphanumeric > with casing = lower 1`] = `"x"`; exports[`string > 1211 > alphanumeric > with casing = mixed 1`] = `"V"`; exports[`string > 1211 > alphanumeric > with casing = upper 1`] = `"X"`; +exports[`string > 1211 > alphanumeric > with exclude 1`] = `"W"`; + exports[`string > 1211 > alphanumeric > with length 1`] = `"VsTMd8"`; exports[`string > 1211 > alphanumeric > with length parameter 1`] = `"VsTMd"`; @@ -150,7 +150,7 @@ exports[`string > 1211 > alphanumeric > with length parameter 4`] = `"aHKO0"`; exports[`string > 1211 > alphanumeric > with length parameter 5`] = `"LFEJP"`; -exports[`string > 1211 > alphanumeric > with length, casing and bannedChars 1`] = `"yexv53z"`; +exports[`string > 1211 > alphanumeric > with length, casing and exclude 1`] = `"yexv53z"`; exports[`string > 1211 > hexadecimal > noArgs 1`] = `"0xE"`; @@ -170,7 +170,7 @@ exports[`string > 1211 > numeric > noArgs 1`] = `"9"`; exports[`string > 1211 > numeric > with allowLeadingZeros 1`] = `"9"`; -exports[`string > 1211 > numeric > with bannedDigits 1`] = `"9"`; +exports[`string > 1211 > numeric > with exclude 1`] = `"9"`; exports[`string > 1211 > numeric > with length 1`] = `"948721"`; @@ -184,7 +184,7 @@ exports[`string > 1211 > numeric > with length parameter 4`] = `"26780"`; exports[`string > 1211 > numeric > with length parameter 5`] = `"76678"`; -exports[`string > 1211 > numeric > with length, allowLeadingZeros and bannedDigits 1`] = `"9798609"`; +exports[`string > 1211 > numeric > with length, allowLeadingZeros and exclude 1`] = `"9798609"`; exports[`string > 1211 > sample > noArgs 1`] = `"wKti5-}$_/"`; @@ -210,14 +210,14 @@ exports[`string > 1211 > uuid 5`] = `"7b91ce88-effb-4d1d-93bb-ad759e00b86c"`; exports[`string > 1337 > alpha > noArgs 1`] = `"n"`; -exports[`string > 1337 > alpha > with bannedChars 1`] = `"v"`; - exports[`string > 1337 > alpha > with casing = lower 1`] = `"g"`; exports[`string > 1337 > alpha > with casing = mixed 1`] = `"n"`; exports[`string > 1337 > alpha > with casing = upper 1`] = `"G"`; +exports[`string > 1337 > alpha > with exclude 1`] = `"v"`; + exports[`string > 1337 > alpha > with length 1`] = `"nDiloC"`; exports[`string > 1337 > alpha > with length parameter 1`] = `"nDilo"`; @@ -230,18 +230,18 @@ exports[`string > 1337 > alpha > with length parameter 4`] = `"oMpfP"`; exports[`string > 1337 > alpha > with length parameter 5`] = `"ueGsg"`; -exports[`string > 1337 > alpha > with length, casing and bannedChars 1`] = `"eicdeih"`; +exports[`string > 1337 > alpha > with length, casing and exclude 1`] = `"eicdeih"`; exports[`string > 1337 > alphanumeric > noArgs 1`] = `"g"`; -exports[`string > 1337 > alphanumeric > with bannedChars 1`] = `"s"`; - exports[`string > 1337 > alphanumeric > with casing = lower 1`] = `"9"`; exports[`string > 1337 > alphanumeric > with casing = mixed 1`] = `"g"`; exports[`string > 1337 > alphanumeric > with casing = upper 1`] = `"9"`; +exports[`string > 1337 > alphanumeric > with exclude 1`] = `"s"`; + exports[`string > 1337 > alphanumeric > with length 1`] = `"gy9dhx"`; exports[`string > 1337 > alphanumeric > with length parameter 1`] = `"gy9dh"`; @@ -254,7 +254,7 @@ exports[`string > 1337 > alphanumeric > with length parameter 4`] = `"gJj7N"`; exports[`string > 1337 > alphanumeric > with length parameter 5`] = `"n5Cm7"`; -exports[`string > 1337 > alphanumeric > with length, casing and bannedChars 1`] = `"ag45age"`; +exports[`string > 1337 > alphanumeric > with length, casing and exclude 1`] = `"ag45age"`; exports[`string > 1337 > hexadecimal > noArgs 1`] = `"0x5"`; @@ -274,7 +274,7 @@ exports[`string > 1337 > numeric > noArgs 1`] = `"3"`; exports[`string > 1337 > numeric > with allowLeadingZeros 1`] = `"2"`; -exports[`string > 1337 > numeric > with bannedDigits 1`] = `"7"`; +exports[`string > 1337 > numeric > with exclude 1`] = `"7"`; exports[`string > 1337 > numeric > with length 1`] = `"351225"`; @@ -288,7 +288,7 @@ exports[`string > 1337 > numeric > with length parameter 4`] = `"37318"`; exports[`string > 1337 > numeric > with length parameter 5`] = `"40631"`; -exports[`string > 1337 > numeric > with length, allowLeadingZeros and bannedDigits 1`] = `"6706677"`; +exports[`string > 1337 > numeric > with length, allowLeadingZeros and exclude 1`] = `"6706677"`; exports[`string > 1337 > sample > noArgs 1`] = `"9U/4:SK$>6"`; diff --git a/test/random.spec.ts b/test/random.spec.ts index 2cdfd2c0..2e84a713 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -197,7 +197,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); @@ -316,7 +316,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); @@ -413,7 +413,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); @@ -426,7 +426,7 @@ describe('random', () => { }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); diff --git a/test/string.spec.ts b/test/string.spec.ts index 66c6bc59..6d34f098 100644 --- a/test/string.spec.ts +++ b/test/string.spec.ts @@ -14,11 +14,11 @@ describe('string', () => { .it('with casing = lower', { casing: 'lower' }) .it('with casing = upper', { casing: 'upper' }) .it('with casing = mixed', { casing: 'mixed' }) - .it('with bannedChars', { bannedChars: 'abcdefghijk' }) - .it('with length, casing and bannedChars', { + .it('with exclude', { exclude: 'abcdefghijk' }) + .it('with length, casing and exclude', { length: 7, casing: 'lower', - bannedChars: 'lmnopqrstu', + exclude: 'lmnopqrstu', }); }); @@ -29,11 +29,11 @@ describe('string', () => { .it('with casing = lower', { casing: 'lower' }) .it('with casing = upper', { casing: 'upper' }) .it('with casing = mixed', { casing: 'mixed' }) - .it('with bannedChars', { bannedChars: 'abcdefghijk12345' }) - .it('with length, casing and bannedChars', { + .it('with exclude', { exclude: 'abcdefghijk12345' }) + .it('with length, casing and exclude', { length: 7, casing: 'lower', - bannedChars: 'lmnopqrstu67890', + exclude: 'lmnopqrstu67890', }); }); @@ -56,11 +56,11 @@ describe('string', () => { .itRepeated('with length parameter', 5, 5) .it('with length', { length: 6 }) .it('with allowLeadingZeros', { allowLeadingZeros: true }) - .it('with bannedDigits', { bannedDigits: '12345' }) - .it('with length, allowLeadingZeros and bannedDigits', { + .it('with exclude', { exclude: '12345' }) + .it('with length, allowLeadingZeros and exclude', { length: 7, allowLeadingZeros: true, - bannedDigits: '12345', + exclude: '12345', }); }); @@ -114,7 +114,7 @@ describe('string', () => { const actual = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: ['a', 'p'], + exclude: ['a', 'p'], }); expect(actual).toHaveLength(5); @@ -125,35 +125,35 @@ describe('string', () => { const actual = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: 'ap', + exclude: 'ap', }); expect(actual).toHaveLength(5); expect(actual).toMatch(/^[b-oq-z]{5}$/); }); - it('should be able handle mistake in banned characters array', () => { + it('should be able handle mistake in excluded characters array', () => { const alphaText = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: ['a', 'a', 'p'], + exclude: ['a', 'a', 'p'], }); expect(alphaText).toHaveLength(5); expect(alphaText).toMatch(/^[b-oq-z]{5}$/); }); - it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + it('should throw if all possible characters being excluded', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); expect(() => faker.string.alpha({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); @@ -162,15 +162,15 @@ describe('string', () => { const input: { length: number; casing: 'mixed'; - bannedChars: string[]; + exclude: string[]; } = Object.freeze({ length: 5, casing: 'mixed', - bannedChars: ['a', '%'], + exclude: ['a', '%'], }); expect(() => faker.string.alpha(input)).not.toThrow(); - expect(input.bannedChars).toEqual(['a', '%']); + expect(input.exclude).toEqual(['a', '%']); }); }); @@ -206,92 +206,92 @@ describe('string', () => { ); it('should be able to ban all alphabetic characters', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all alphabetic characters via string', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'; + const exclude = 'abcdefghijklmnopqrstuvwxyz'; const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all numeric characters', () => { - const bannedChars = '0123456789'.split(''); + const exclude = '0123456789'.split(''); const alphaText = faker.string.alphanumeric({ length: 5, - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all numeric characters via string', () => { - const bannedChars = '0123456789'; + const exclude = '0123456789'; const alphaText = faker.string.alphanumeric({ length: 5, - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); - it('should be able to handle mistake in banned characters array', () => { + it('should be able to handle mistake in excluded characters array', () => { const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars: ['a', 'p', 'a'], + exclude: ['a', 'p', 'a'], }); expect(alphaText).toHaveLength(5); expect(alphaText).toMatch(/^[0-9b-oq-z]{5}$/); }); - it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); + it('should throw if all possible characters being excluded', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); expect(() => faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); - it('should throw if all possible characters being banned via string', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'; + it('should throw if all possible characters being excluded via string', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz0123456789'; expect(() => faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError(); }); @@ -299,14 +299,14 @@ describe('string', () => { it('should not mutate the input object', () => { const input: { length: number; - bannedChars: string[]; + exclude: string[]; } = Object.freeze({ length: 5, - bannedChars: ['a', '0', '%'], + exclude: ['a', '0', '%'], }); expect(() => faker.string.alphanumeric(input)).not.toThrow(); - expect(input.bannedChars).toEqual(['a', '0', '%']); + expect(input.exclude).toEqual(['a', '0', '%']); }); }); @@ -374,68 +374,68 @@ describe('string', () => { expect(actual).toMatch(/^[0-9]+$/); }); - it('should allow leading zeros via option and all other digits banned', () => { + it('should allow leading zeros via option and all other digits excluded', () => { const actual = faker.string.numeric({ length: 4, allowLeadingZeros: true, - bannedDigits: '123456789'.split(''), + exclude: '123456789'.split(''), }); expect(actual).toBe('0000'); }); - it('should allow leading zeros via option and all other digits banned via string', () => { + it('should allow leading zeros via option and all other digits excluded via string', () => { const actual = faker.string.numeric({ length: 4, allowLeadingZeros: true, - bannedDigits: '123456789', + exclude: '123456789', }); expect(actual).toBe('0000'); }); - it('should fail on leading zeros via option and all other digits banned', () => { + it('should fail on leading zeros via option and all other digits excluded', () => { expect(() => faker.string.numeric({ length: 4, allowLeadingZeros: false, - bannedDigits: '123456789'.split(''), + exclude: '123456789'.split(''), }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); - it('should fail on leading zeros via option and all other digits banned via string', () => { + it('should fail on leading zeros via option and all other digits excluded via string', () => { expect(() => faker.string.numeric({ length: 4, allowLeadingZeros: false, - bannedDigits: '123456789', + exclude: '123456789', }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); - it('should ban all digits passed via bannedDigits', () => { + it('should ban all digits passed via exclude', () => { const actual = faker.string.numeric({ length: 1000, - bannedDigits: 'c84U1'.split(''), + exclude: 'c84U1'.split(''), }); expect(actual).toHaveLength(1000); expect(actual).toMatch(/^[0235679]{1000}$/); }); - it('should ban all digits passed via bannedDigits via string', () => { + it('should ban all digits passed via exclude via string', () => { const actual = faker.string.numeric({ length: 1000, - bannedDigits: 'c84U1', + exclude: 'c84U1', }); expect(actual).toHaveLength(1000); |
