diff --git a/src/generate-cnpj/generate-cnpj.test.ts b/src/generate-cnpj/generate-cnpj.test.ts index caf865a..8c9504f 100644 --- a/src/generate-cnpj/generate-cnpj.test.ts +++ b/src/generate-cnpj/generate-cnpj.test.ts @@ -73,5 +73,20 @@ describe("generateCnpj", () => { expect(isValidCnpj(formatted, { version: 2 })).toBe(true); } }); + + test("should generate alphanumeric CNPJs spanning the full A-Z alphabet", () => { + const usedChars = new Set(); + for (let i = 0; i < 1000; i++) { + for (const char of generateCnpj(2)) { + usedChars.add(char); + } + } + // E, O, T and U were previously excluded by a restricted alphabet, even + // though isValidCnpj accepts them: the RFB alphanumeric CNPJ uses the full + // [A-Z0-9] base (official example "12.ABC.345/01DE-35" contains an "E"). + for (const char of ["E", "O", "T", "U"]) { + expect(usedChars.has(char)).toBe(true); + } + }); }); }); diff --git a/src/generate-cnpj/generate-cnpj.ts b/src/generate-cnpj/generate-cnpj.ts index 30ea86b..589912b 100644 --- a/src/generate-cnpj/generate-cnpj.ts +++ b/src/generate-cnpj/generate-cnpj.ts @@ -7,7 +7,7 @@ const FIRST_CHECK_DIGIT_WEIGHTS = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; const SECOND_CHECK_DIGIT_WEIGHTS = [6, ...FIRST_CHECK_DIGIT_WEIGHTS]; -const VALID_CNPJ_CHARS = "0123456789ABCDFGHIJKLMNPQRSVWXYZ"; +const VALID_CNPJ_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const generateRandomCnpjChar = (): string => VALID_CNPJ_CHARS[Math.floor(Math.random() * VALID_CNPJ_CHARS.length)];