-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidgen_test.go
More file actions
41 lines (35 loc) · 1012 Bytes
/
validgen_test.go
File metadata and controls
41 lines (35 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package validgen
import (
"testing"
)
func TestGenerateCpf(t *testing.T) {
cpf, err := GenerateCPF()
if err != nil {
t.Errorf("GenerateCpf() error = %v", err)
}
if len(cpf) != 11 {
t.Errorf("GenerateCpf() = %v; want length 11", cpf)
}
}
func TestValidateCpf(t *testing.T) {
validCpf := "12345678909"
invalidCpf := "12345678900"
if err := ValidateCPF(validCpf); err != nil {
t.Errorf("ValidateCpf(%v) error = %v; want nil", validCpf, err)
}
if err := ValidateCPF(invalidCpf); err == nil {
t.Errorf("ValidateCpf(%v) error = nil; want error", invalidCpf)
}
}
func TestFormatGeneratedCpf(t *testing.T) {
formattedCpf, err := FormatGeneratedCPF()
if err != nil {
t.Errorf("FormatGeneratedCpf() error = %v", err)
}
if len(formattedCpf) != 14 {
t.Errorf("FormatGeneratedCpf() = %v; want length 14", formattedCpf)
}
if formattedCpf[3] != '.' || formattedCpf[7] != '.' || formattedCpf[11] != '-' {
t.Errorf("FormatGeneratedCpf() = %v; want format XXX.XXX.XXX-XX", formattedCpf)
}
}