-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpis_test.go
77 lines (66 loc) · 1.16 KB
/
pis_test.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package pisvalidatior
import (
"testing"
)
func TestValidate(t *testing.T) {
tests := []struct {
pis string
wantErr bool
}{
{
pis: "71115848273",
wantErr: false,
},
{
pis: "477.11617.27-5",
wantErr: false,
},
{
pis: "475.12417.27-5",
wantErr: true,
},
{
pis: "47311117177",
wantErr: true,
},
{
pis: "4731111717",
wantErr: true,
},
{
pis: "47a11117177",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.pis, func(t *testing.T) {
if _, err := ValidatePis(tt.pis); (err != nil) != tt.wantErr {
t.Errorf("Error on validate = %v, wantErr %v, pis %v", err, tt.wantErr, tt.pis)
}
})
}
}
func TestClean1(t *testing.T) {
s := clean("111.222.333-99")
if s != "11122233399" {
t.Errorf("Invalid result: %s", s)
}
}
func TestClean2(t *testing.T) {
s := clean("10.963.268/0001-82")
if s != "10963268000182" {
t.Errorf("Invalid result: %s", s)
}
}
func TestDigit1(t *testing.T) {
s := verifyDigit(11)
if s != 0 {
t.Errorf("Invalid result: %d", s)
}
}
func TestDigit2(t *testing.T) {
s := verifyDigit(9)
if s != 9 {
t.Errorf("Invalid result: %d", s)
}
}