-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_test.go
66 lines (58 loc) · 1.52 KB
/
types_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
package rnokpp_test
import (
"testing"
"time"
"github.com/fre5h/rnokpp"
)
func TestNewDetails(t *testing.T) {
details := rnokpp.NewDetails(true, rnokpp.Male, "01.01.2000")
baseLocation, _ := time.LoadLocation("Europe/Kiev")
expectedDate, _ := time.ParseInLocation("02.01.2006", "01.01.2000", baseLocation)
if details.Birthday.Unix() != expectedDate.Unix() {
t.Errorf(
"wrong timestamp for birthday, expected: %s%d%s, actual: %s%d%s.",
green, expectedDate.Unix(), reset,
red, details.Birthday.Unix(), reset,
)
}
}
func TestNewDetailsWithPanic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
rnokpp.NewDetails(true, rnokpp.Male, "not date")
}
var testVariantsTestDetailsString = []struct {
string string
details rnokpp.Details
}{
{
string: "valid, male, 01.01.2000",
details: *rnokpp.NewDetails(true, rnokpp.Male, "01.01.2000"),
},
{
string: "valid, female, 01.01.2001",
details: *rnokpp.NewDetails(true, rnokpp.Female, "01.01.2001"),
},
{
string: "invalid",
details: *rnokpp.NewDetails(false, rnokpp.Male, "01.01.2002"),
},
{
string: "invalid",
details: *rnokpp.NewDetails(false, rnokpp.Female, "01.01.2003"),
},
}
func TestDetailsString(t *testing.T) {
for _, data := range testVariantsTestDetailsString {
if data.string != data.details.String() {
t.Errorf(
"invalid string representation of details, expected: %s%s%s, actual: %s%s%s.",
green, data.string, reset,
red, data.details.String(), reset,
)
}
}
}