-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathifc_test.go
142 lines (127 loc) · 3.33 KB
/
ifc_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2020 Stefano Cotta Ramusino. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ifc
import (
"strings"
"testing"
"time"
)
var p Person
func TestEncode(t *testing.T) {
_, err := Encode("", "", 0, "--", "Andria")
if err == nil {
t.Fatalf("no error generated: expected '%s'", errSex)
} else {
if !strings.Contains(err.Error(), errSex) {
t.Fatalf("unexpected error: got '%s', expected '%s'", err, errSex)
}
}
}
func TestEncode2(t *testing.T) {
_, err := Encode("", "", 'f', "--", "Andria")
if err == nil {
t.Fatalf("no error generated: expected '%s'", `cannot parse "--" as "2006"`)
} else {
if !strings.Contains(err.Error(), `cannot parse "--" as "2006"`) {
t.Fatalf("unexpected error: got '%s', expected '%s'", err, `cannot parse "--" as "2006"`)
}
}
}
func TestEncode3(t *testing.T) {
_, err := Encode("", "", 'f', "1999-12-13", "Andria")
if err != nil {
t.Fatal(err)
}
}
func TestPerson_Ifc(t *testing.T) {
p = Person{}
_, err := p.Ifc()
if err == nil {
t.Fatalf("no error generated: expected '%s'", errSex)
} else {
if !strings.Contains(err.Error(), errSex) {
t.Fatalf("unexpected error: got '%s', expected '%s'", err, errSex)
}
}
}
func TestPerson_Ifc2(t *testing.T) {
p.Sex = 'm'
_, err := p.Ifc()
if err == nil {
t.Fatalf("no error generated: expected '%s'", `cannot parse "" as "2006"`)
} else {
if !strings.Contains(err.Error(), `cannot parse "" as "2006"`) {
t.Fatalf("unexpected error: got '%s', expected '%s'", err, `cannot parse "" as "2006"`)
}
}
}
func TestPerson_Ifc3(t *testing.T) {
p.BirthDate = time.Now().AddDate(-30, 0, 0).Format("2006-01-02")
_, err := p.Ifc()
if err == nil {
t.Fatalf("no error generated: expected '%s'", errPlace)
} else {
if !strings.Contains(err.Error(), errPlace) {
t.Fatalf("unexpected error: got '%s', expected '%s'", err, errPlace)
}
}
}
func TestPerson_Ifc4(t *testing.T) {
p.BirthPlace = "Lucca "
_, err := p.Ifc()
if err != nil {
t.Fatal(err)
}
}
func TestPerson_Ifc5(t *testing.T) {
p.Surname = "Doe"
_, err := p.Ifc()
if err != nil {
t.Fatal(err)
}
}
func TestPerson_Ifc6(t *testing.T) {
p.Name = "Jane"
_, err := p.Ifc()
if err != nil {
t.Fatal(err)
}
}
func TestPerson_Ifc7(t *testing.T) {
p.Sex = 'F'
_, err := p.Ifc()
if err != nil {
t.Fatal(err)
}
}
func TestDecode(t *testing.T) {
person, err := Decode("RSSMRA99T13H501A")
if err != nil {
t.Fatal(err)
}
if person.Sex != strings.ToUpper(string(male))[0] {
t.Fatalf(errSex+": got '%c', expected '%c'", person.Sex, strings.ToUpper(string(male))[0])
}
if person.BirthDate != "1999-12-13" {
t.Fatalf("wrong birth date: got '%s', expected '%s'", person.BirthDate, "1999-12-13")
}
if person.BirthPlace != "Roma" {
t.Fatalf("wrong birth place: got '%s', expected '%s'", person.BirthPlace, "Roma")
}
}
func TestPerson_CheckIfc(t *testing.T) {
err := p.CheckIfc("DOEJHN99T13Z121S")
if err != nil {
t.Fatal(err)
}
if p.Sex != strings.ToUpper(string(male))[0] {
t.Fatalf(errSex+": got '%c', expected '%c'", p.Sex, strings.ToUpper(string(male))[0])
}
if p.BirthDate != "1999-12-13" {
t.Fatalf("wrong birth date: got '%s', expected '%s'", p.BirthDate, "1999-12-13")
}
if p.BirthPlace != "Malta" {
t.Fatalf("wrong birth place: got '%s', expected '%s'", p.BirthPlace, "Malta")
}
}