Skip to content

Commit

Permalink
testes unitarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubens Melo authored and Rubens Melo committed Oct 1, 2023
1 parent 4c8fe3f commit 3379497
Show file tree
Hide file tree
Showing 43 changed files with 1,655 additions and 446 deletions.
673 changes: 673 additions & 0 deletions coverage/lcov.info

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class MyApp extends StatelessWidget {
label: 'Hora',
formatter: HoraInputFormatter(),
),
RowFormatters(
label: 'KM',
formatter: KmInputFormatter(),
),
RowFormatters(
label: 'Centavos', formatter: CentavosInputFormatter()),
RowFormatters(
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
46 changes: 23 additions & 23 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.2"
fake_async:
dependency: transitive
description:
Expand All @@ -65,10 +65,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.3"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -82,38 +82,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.18.1"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints:
dependency: transitive
description:
name: lints
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.1.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
Expand All @@ -139,10 +131,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -179,10 +171,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.0"
vector_math:
dependency: transitive
description:
Expand All @@ -191,5 +183,13 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
39 changes: 15 additions & 24 deletions lib/src/formatters/altura_input_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,29 @@ class AlturaInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
final newValueLength = newValue.text.length;
// verifica o tamanho máximo do campo
if (newValue.text.length > 3) return oldValue;

// Verifica o tamanho máximo do campo.
if (newValueLength > 3) {
return oldValue;
}

if (newValueLength > 0) {
final numNovo = int.tryParse(newValue.text.substring(0, 1));
if (numNovo != null) {
if (numNovo > 2) {
return oldValue;
}
// evita que o primeiro digito seja > 2
if (newValue.text.isNotEmpty) {
final primeiroDigito = int.tryParse(newValue.text[0]);
if (primeiroDigito == null || primeiroDigito > 2) {
return oldValue;
}
}

var selectionIndex = newValue.selection.end;
var substrIndex = 0;
final newText = StringBuffer();

if (newValueLength > 2) {
newText.write('${newValue.text.substring(0, substrIndex = 1)},');
if (newValue.selection.end > 2) selectionIndex++;
}
String valorFinal = newValue.text;

if (newValueLength >= substrIndex) {
newText.write(newValue.text.substring(substrIndex));
// adiciona ","
if (newValue.text.length == 3) {
valorFinal = '${newValue.text[0]},${newValue.text[1]}${newValue.text[2]}';
} else if (newValue.text.length == 2) {
valorFinal = '${newValue.text[0]},${newValue.text[1]}';
}

return TextEditingValue(
text: newText.toString(),
selection: TextSelection.collapsed(offset: selectionIndex),
text: valorFinal.toString(),
selection: TextSelection.collapsed(offset: valorFinal.length),
);
}
}
39 changes: 14 additions & 25 deletions lib/src/formatters/cartao_bancario_input_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,25 @@ class CartaoBancarioInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
final newValueLength = newValue.text.length;
// verifica o tamanho máximo do campo
if (newValue.text.length > 16) return oldValue;

// Verifica o tamanho máximo do campo.
if (newValueLength > 16) {
return oldValue;
}

var selectionIndex = newValue.selection.end;
var substrIndex = 0;
final newText = StringBuffer();
int posicaoCursor = newValue.selection.end;
final valorFinal = StringBuffer();
for (int i = 0; i < newValue.text.length; i++) {
// adiciona espaco em branco a cada 4 digitos
if (i % 4 == 0 && i != 0) {
valorFinal.write(' ');
// incrementa a posicao do cursor
if (posicaoCursor >= i) posicaoCursor++;
}

if (newValueLength >= 4) {
newText.write('${newValue.text.substring(0, substrIndex = 4)} ');
if (newValue.selection.end >= 5) selectionIndex++;
}
if (newValueLength >= 8) {
newText.write('${newValue.text.substring(4, substrIndex = 8)} ');
if (newValue.selection.end >= 9) selectionIndex++;
}
if (newValueLength >= 12) {
newText.write('${newValue.text.substring(8, substrIndex = 12)} ');
if (newValue.selection.end >= 13) selectionIndex++;
}
if (newValueLength >= substrIndex) {
newText.write(newValue.text.substring(substrIndex));
valorFinal.write(newValue.text[i]);
}

return TextEditingValue(
text: newText.toString(),
selection: TextSelection.collapsed(offset: selectionIndex),
text: valorFinal.toString(),
selection: TextSelection.collapsed(offset: posicaoCursor),
);
}
}
71 changes: 31 additions & 40 deletions lib/src/formatters/centavos_input_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,37 @@ class CentavosInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
final newValueLength = newValue.text.length;
if (newValue.text.isEmpty || newValue.text.length > 12) return oldValue;

// Verifica o tamanho máximo do campo.
if (newValueLength > 12) {
return oldValue;
}

if (newValueLength == 0) {
return newValue;
}

const simbolo = 'R\$ ';
final newText = StringBuffer();
var centsValue = "";
var valorFinal = newValue.text;
var numero = int.parse(newValue.text);
var centavos = "";
var textoFinal = newValue.text;
var reais = int.parse(newValue.text);

var textValue = newValue.text.padLeft(
newValue.text.length == 1 ? casasDecimais + 1 : casasDecimais, "");
if (textValue.length >= casasDecimais) {
centsValue = textValue.substring(
centavos = textValue.substring(
textValue.length - casasDecimais, textValue.length);
valorFinal = textValue.substring(0, textValue.length - casasDecimais);
textoFinal = textValue.substring(0, textValue.length - casasDecimais);
}
// apaga o campo quando os valores forem zero (inteiro e decimais).
if (reais == 0 && int.tryParse(centavos) == 0) {
return TextEditingValue.empty;
}

// apaga o campo quando os valores foram zero.
if (numero == 0 && int.tryParse(centsValue) == 0) {
return const TextEditingValue(
text: "",
selection: TextSelection.collapsed(offset: 0),
);
// apaga o campo quando novo valor for 0 e o valor anterior tambem era 0.
if (reais == 0 && (oldValue.text == '0,' || oldValue.text == 'R\$ 0,')) {
return TextEditingValue.empty;
}

// retorna apenas o valor decimal, após o 0
if (textValue.length == casasDecimais) {
valorFinal = "0,$centsValue";
textoFinal = "0,$centavos";
if (moeda) {
valorFinal = simbolo + valorFinal;
textoFinal = 'R\$ $textoFinal';
}
newText.write(valorFinal);
newText.write(textoFinal);

return TextEditingValue(
text: newText.toString(),
Expand All @@ -64,38 +55,38 @@ class CentavosInputFormatter extends TextInputFormatter {
}

// formata o número com 0, + centavos
if (numero > 0 && numero <= 9) {
if (reais > 0 && reais <= 9) {
if (casasDecimais == 3) {
centsValue = "00$numero";
centavos = "00$reais";
} else {
centsValue = "0$numero";
centavos = "0$reais";
}

numero = 0;
} else if (numero >= 10 && numero < 100) {
reais = 0;
} else if (reais >= 10 && reais < 100) {
if (casasDecimais == 3) {
centsValue = "0$numero";
centavos = "0$reais";
} else {
centsValue = numero.toString();
centavos = reais.toString();
}

numero = 0;
} else if (valorFinal.isNotEmpty) {
numero = int.parse(valorFinal);
reais = 0;
} else if (textoFinal.isNotEmpty) {
reais = int.parse(textoFinal);
}

// adiciona

if (numero > 999) {
valorFinal = "${adicionarSeparador(numero.toString())},$centsValue";
if (reais > 999) {
textoFinal = "${adicionarSeparador(reais.toString())},$centavos";
} else {
valorFinal = "$numero,$centsValue";
textoFinal = "$reais,$centavos";
}

if (moeda) {
valorFinal = simbolo + valorFinal;
textoFinal = 'R\$ $textoFinal';
}
newText.write(valorFinal);
newText.write(textoFinal);

return TextEditingValue(
text: newText.toString(),
Expand Down
Loading

0 comments on commit 3379497

Please sign in to comment.