diff --git a/test/src/formatters/cnpj_input_formatter_test.dart b/test/src/formatters/cnpj_input_formatter_test.dart index c3880bd..0ee3bfe 100644 --- a/test/src/formatters/cnpj_input_formatter_test.dart +++ b/test/src/formatters/cnpj_input_formatter_test.dart @@ -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'); @@ -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', ''), ''); + }); }); } diff --git a/test/util_brasil_fields_test.dart b/test/util_brasil_fields_test.dart index 8109b53..54f89bc 100644 --- a/test/util_brasil_fields_test.dart +++ b/test/util_brasil_fields_test.dart @@ -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', () { @@ -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'; @@ -249,6 +257,21 @@ 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'; @@ -256,6 +279,13 @@ void main() { 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'; @@ -263,6 +293,13 @@ void main() { 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;