Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(string): remove arbitrary limit from sample #2497

Merged
merged 9 commits into from
Nov 7, 2023
7 changes: 1 addition & 6 deletions src/modules/string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ export type NumericChar =
export type AlphaChar = LowerAlphaChar | UpperAlphaChar;
export type AlphaNumericChar = AlphaChar | NumericChar;

const SAMPLE_MAX_LENGTH = 2 ** 20;

/**
* Module to generate string related entries.
*
Expand Down Expand Up @@ -621,7 +619,7 @@ export class StringModule extends SimpleModuleBase {
/**
* Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).
*
* @param length Length of the generated string. Max length is `2^20`. Defaults to `10`.
* @param length Length of the generated string. Defaults to `10`.
* @param length.min The minimum number of characters to generate.
* @param length.max The maximum number of characters to generate.
*
Expand All @@ -647,9 +645,6 @@ export class StringModule extends SimpleModuleBase {
} = 10
): string {
length = this.faker.helpers.rangeToNumber(length);
if (length >= SAMPLE_MAX_LENGTH) {
length = SAMPLE_MAX_LENGTH;
}

const charCodeOption = {
min: 33,
Expand Down
6 changes: 0 additions & 6 deletions test/modules/datatype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,6 @@ describe('datatype', () => {
expect(generatedString).toBe('');
expect(generatedString).toHaveLength(0);
});

it('should return string with length of 2^20 if bigger length value is passed', () => {
const overMaxValue = Math.pow(2, 28);
const generatedString = faker.datatype.string(overMaxValue);
expect(generatedString).toHaveLength(Math.pow(2, 20));
});
});

describe('boolean', () => {
Expand Down
6 changes: 0 additions & 6 deletions test/modules/string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,6 @@ describe('string', () => {
expect(generatedString).toHaveLength(0);
});

it('should return string with length of 2^20 if bigger length value is passed', () => {
const overMaxValue = 2 ** 28;
const generatedString = faker.string.sample(overMaxValue);
expect(generatedString).toHaveLength(2 ** 20);
});

it('should return string with a specific length', () => {
const length = 1337;
const generatedString = faker.string.sample(length);
Expand Down