-
Notifications
You must be signed in to change notification settings - Fork 7
/
document_test.go
103 lines (93 loc) · 2.13 KB
/
document_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
94
95
96
97
98
99
100
101
102
103
package internal_test
import (
"github.com/brazanation/go-documents/internal"
"github.com/brazanation/go-documents/internal/test"
"testing"
)
const (
testDocument internal.DocumentType = "Test"
validatorRegex string = `^([\d]{3})([\d]{3})([\d]{3})([\d]{2})$`
formatterRegex string = "$1.$2.$3-$4"
)
type CalculatorStub struct {
result string
}
func (c CalculatorStub) CalculateDigit(base string) string {
return c.result
}
func TestDocumentShouldBeValid(t *testing.T) {
d, err := internal.NewDocument(
testDocument,
"06843273173",
11,
2,
formatterRegex,
validatorRegex,
CalculatorStub{"73"},
)
internal_test.AssertValidDocument(t, d, err)
}
func TestDocumentShouldBeSameType(t *testing.T) {
d, _ := internal.NewDocument(
testDocument,
"06843273173",
11,
2,
formatterRegex,
validatorRegex,
CalculatorStub{"73"},
)
internal_test.AssertDocumentType(t, d, testDocument)
}
func TestDocumentShouldBeFormatted(t *testing.T) {
d, err := internal.NewDocument(
testDocument,
"068.432.731-73",
11,
2,
formatterRegex,
validatorRegex,
CalculatorStub{"73"},
)
internal_test.AssertValidDocument(t, d, err)
internal_test.AssertDocumentFormatted(t, d, "068.432.731-73")
}
func TestDocumentShouldReturnErrorForRepeatedNumber(t *testing.T) {
number := "11111111111111"
_, err := internal.NewDocument(
testDocument,
number,
11,
2,
formatterRegex,
validatorRegex,
CalculatorStub{""},
)
internal_test.AssertNotValidDocument(t, number, err, "Test(11111111111111) is invalid")
}
func TestDocumentShouldReturnErrorForInvalidNumber(t *testing.T) {
number := "00111222100099"
_, err := internal.NewDocument(
testDocument,
number,
11,
2,
formatterRegex,
validatorRegex,
CalculatorStub{""},
)
internal_test.AssertNotValidDocument(t, number, err, "Test(00111222100099) is invalid")
}
func TestDocumentShouldReturnErrorForEmptyNumber(t *testing.T) {
number := ``
_, err := internal.NewDocument(
testDocument,
number,
11,
2,
formatterRegex,
validatorRegex,
CalculatorStub{""},
)
internal_test.AssertNotValidDocument(t, number, err, "Test must not be empty")
}