From 651a194d17d94644bc3722d5d67f2699e0c0ea78 Mon Sep 17 00:00:00 2001 From: dilowagner Date: Thu, 11 May 2023 17:54:01 -0300 Subject: [PATCH] Ajustando validacao do estado de SP --- validator_test.go | 14 ++++++++++++++ validators/sp.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/validator_test.go b/validator_test.go index 5d52f6b..eda6806 100644 --- a/validator_test.go +++ b/validator_test.go @@ -1747,6 +1747,20 @@ func TestValidatorSPValid(t *testing.T) { assert.True(t, result) } +func TestValidatorSPValidWithMod10(t *testing.T) { + + validator := NewIEValidator() + + validator.IE = "330.062.780.110" // Valido + validator.UF = validators.SP + + result, err := validator.Validate() + if err != nil { + t.Error("Erro na validacao do estado de São Paulo") + } + assert.True(t, result) +} + func TestValidatorSPValidWithPLetter(t *testing.T) { validator := NewIEValidator() diff --git a/validators/sp.go b/validators/sp.go index cc2489b..4a24a2e 100644 --- a/validators/sp.go +++ b/validators/sp.go @@ -51,7 +51,7 @@ func (v SaoPaulo) IsValid(insc string) bool { weights = []int{3, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2} total = rule.CalculateTotal(firstBase+firstDigit+secondBase, 11, weights) mod = rule.CalculateMod(total, 11) - secondDigit := strconv.Itoa(mod) + secondDigit := strconv.Itoa(mod % 10) return insc == firstBase+firstDigit+secondBase+secondDigit }