-
Notifications
You must be signed in to change notification settings - Fork 5
/
cnpj_test.go
93 lines (70 loc) · 1.69 KB
/
cnpj_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package cpfcnpj
import "testing"
func TestValidCNPJWithInvalidNumber1(t *testing.T) {
r := ValidateCNPJ("73687174000158")
if r {
t.Errorf("Invalid result: %v", r)
}
}
func TestValidCNPJWithInvalidNumber2(t *testing.T) {
r := ValidateCNPJ("62009392000103")
if r {
t.Errorf("Invalid result: %v", r)
}
}
func TestValidCNPJWithInvalidNumber3(t *testing.T) {
r := ValidateCNPJ("22796729000145")
if r {
t.Errorf("Invalid result: %v", r)
}
}
func TestValidCNPJWithValidNumber1(t *testing.T) {
r := ValidateCNPJ("73687174000148")
if !r {
t.Errorf("Invalid result: %v", r)
}
}
func TestValidCNPJWithValidNumber2(t *testing.T) {
r := ValidateCNPJ("62009392000107")
if !r {
t.Errorf("Invalid result: %v", r)
}
}
func TestValidCNPJWithValidNumber3(t *testing.T) {
r := ValidateCNPJ("22796729000159")
if !r {
t.Errorf("Invalid result: %v", r)
}
}
func TestCNPJTypeIsValidWithValidNumber(t *testing.T) {
var cnpj CNPJ = "22796729000159"
if !cnpj.IsValid() {
t.Errorf("Invalid result: false")
}
}
func TestCNPJTypeIsValidWithInvalidNumber(t *testing.T) {
var cnpj CNPJ = "62009392000103"
if cnpj.IsValid() {
t.Errorf("Invalid result: true")
}
}
func TestCNPJTypeStringFormattingWithValidNumber(t *testing.T) {
var cnpj CNPJ = "22796729000159"
r := cnpj.String()
if r != "22.796.729/0001-59" {
t.Errorf("Invalid result: %v", r)
}
}
func TestCNPJTypeStringFormattingWithInvalidNumber(t *testing.T) {
var cnpj CNPJ = "62009392000103"
r := cnpj.String()
if r != "62009392000103" {
t.Errorf("Invalid result: %v", r)
}
}
func TestCNPJNewCNPJ(t *testing.T) {
cnpj := NewCNPJ("22.796.729/0001-59")
if cnpj != "22796729000159" {
t.Errorf("Invalid result: %v", cnpj)
}
}