Skip to content

Commit

Permalink
adds CNPJ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Emanuel committed Dec 20, 2024
1 parent a80c9c8 commit 7611b4d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
40 changes: 37 additions & 3 deletions test/src/formatters/cnpj_input_formatter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ void main() {
}

group('CnpjInputFormatter', () {
test('padrao',
() => expect(evaluate('', '99999999999999'), '99.999.999/9999-99'));
test(
'limite 14 digitos', () => expect(evaluate('', '199999999999999'), ''));
'padrao',
() => expect(evaluate('', '99999999999999'), '99.999.999/9999-99'),
);

test(
'padrao alfanumérico',
() => expect(evaluate('', 'AAAAAAAAAAAA99'), 'AA.AAA.AAA/AAAA-99'),
);

test(
'limite 14 digitos',
() => expect(evaluate('', '199999999999999'), ''),
);

test(
'limite 14 digitos alfanumérico',
() => expect(evaluate('', 'ABBBBBBBBBBBB99'), ''),
);

test('backspace', () {
expect(
evaluate('99.999.999/9999-99', '9999999999999'), '99.999.999/9999-9');
Expand All @@ -33,5 +49,23 @@ void main() {
expect(evaluate('99', '9'), '9');
expect(evaluate('9', ''), '');
});

test('backspace alfanumérico', () {
expect(
evaluate('AA.BBB.CCC/DDDD-99', 'AABBBCCCDDDD9'), 'AA.BBB.CCC/DDDD-9');
expect(evaluate('AA.BBB.CCC/DDDD-9', 'AABBBCCCDDDD'), 'AA.BBB.CCC/DDDD');
expect(evaluate('AA.BBB.CCC/DDDD', 'AABBBCCCDDD'), 'AA.BBB.CCC/DDD');
expect(evaluate('AA.BBB.CCC/DDD', 'AABBBCCCDD'), 'AA.BBB.CCC/DD');
expect(evaluate('AA.BBB.CCC/DD', 'AABBBCCCD'), 'AA.BBB.CCC/D');
expect(evaluate('AA.BBB.CCC/D', 'AABBBCCC'), 'AA.BBB.CCC');
expect(evaluate('AA.BBB.CCC', 'AABBBCC'), 'AA.BBB.CC');
expect(evaluate('AA.BBB.CC', 'AABBBC'), 'AA.BBB.C');
expect(evaluate('AA.BBB.C', 'AABBB'), 'AA.BBB');
expect(evaluate('AA.BBB', 'AABB'), 'AA.BB');
expect(evaluate('AA.BB', 'AAB'), 'AA.B');
expect(evaluate('AA.B', 'AA'), 'AA');
expect(evaluate('AA', 'A'), 'A');
expect(evaluate('A', ''), '');
});
});
}
37 changes: 37 additions & 0 deletions test/util_brasil_fields_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ void main() {

test('CNPJ', () {
const cnpj = '11.222.333/4444-55';
const cnpj2 = 'U7.YHQ.1HJ/1MQY-56';
expect(UtilBrasilFields.removeCaracteres(cnpj), '11222333444455');
expect(UtilBrasilFields.removeCaracteres(cnpj2), 'U7YHQ1HJ1MQY56');
});

test('CEP', () {
Expand Down Expand Up @@ -234,6 +236,12 @@ void main() {
expect(UtilBrasilFields.obterCnpj(cpnjSemMascara), cpnjComMascara);
});

test('Obter CNPJ Alfanumérico', () {
const cpnjSemMascara = 'E2X05ZR982XN04';
const cpnjComMascara = 'E2.X05.ZR9/82XN-04';
expect(UtilBrasilFields.obterCnpj(cpnjSemMascara), cpnjComMascara);
});

test('Obter inscrição CNPJ', () {
const cpnjSemMascara = '34318733000190';
const cpnjComMascara = '34.318.733/0001-90';
Expand All @@ -249,20 +257,49 @@ void main() {
);
});

test('Obter inscrição CNPJ Alfanumérico', () {
const cpnjSemMascara = 'BIK52V87H70I33';
const cpnjComMascara = 'BI.K52.V87/H70I-33';
expect(UtilBrasilFields.obterCnpjInscricao(cpnjSemMascara), 'BIK52V87');
expect(UtilBrasilFields.obterCnpjInscricao(cpnjComMascara), 'BIK52V87');
expect(
UtilBrasilFields.obterCnpjInscricao(cpnjSemMascara, useFormat: true),
'BI.K52.V87',
);
expect(
UtilBrasilFields.obterCnpjInscricao(cpnjComMascara, useFormat: true),
'BI.K52.V87',
);
});

test('Obter Ordem do CNPJ', () {
const cpnjSemMascara = '34318733000190';
const cpnjComMascara = '34.318.733/0001-90';
expect(UtilBrasilFields.obterCnpjOrdem(cpnjSemMascara), '0001');
expect(UtilBrasilFields.obterCnpjOrdem(cpnjComMascara), '0001');
});

test('Obter Ordem do CNPJ Alfanumérico', () {
const cpnjSemMascara = 'X5QK1398N10862';
const cpnjComMascara = 'X5.QK1.398/N108-62';
expect(UtilBrasilFields.obterCnpjOrdem(cpnjSemMascara), 'N108');
expect(UtilBrasilFields.obterCnpjOrdem(cpnjComMascara), 'N108');
});

test('Obter dígitos verificadores do CNPJ', () {
const cpnjSemMascara = '34318733000190';
const cpnjComMascara = '34.318.733/0001-90';
expect(UtilBrasilFields.obterCnpjDiv(cpnjSemMascara), '90');
expect(UtilBrasilFields.obterCnpjDiv(cpnjComMascara), '90');
});

test('Obter dígitos verificadores do CNPJ Alfanumérico', () {
const cpnjSemMascara = 'S653N1793ADL37';
const cpnjComMascara = 'S6.53N.179/3ADL-37';
expect(UtilBrasilFields.obterCnpjDiv(cpnjSemMascara), '37');
expect(UtilBrasilFields.obterCnpjDiv(cpnjComMascara), '37');
});

group('Obter Real', () {
test('com moeda (R\$)', () {
const real = 85437107.04;
Expand Down

0 comments on commit 7611b4d

Please sign in to comment.