-
Notifications
You must be signed in to change notification settings - Fork 1
/
calendar_test.go
113 lines (91 loc) · 3.72 KB
/
calendar_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
package main
import (
"fmt"
"strings"
"testing"
"time"
)
func TestGenerate(t *testing.T) {
var calendar Calendar
date, _ := time.Parse("2006-01-02", "2016-09-01")
calendar.Generate(date)
expect := " 2016年 09月 "
if calendar.DateHeader != expect {
t.Errorf("Expect calendar.DateHeader is %s, but %s", expect, calendar.DateHeader)
}
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", red("日"), "月", "火", "水", "木", "金", blue("土"))
if calendar.WeekHeader != expect {
t.Errorf("Expect calendar.WeekHeader is %s, but %s", expect, calendar.WeekHeader)
}
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", " ", " ", " ", " ", "1", "2", blue("3"))
if calendar.Body[0] != expect {
t.Errorf("Expect calendar.Body[0] is %s, but %s", expect, calendar.Body[0])
}
expect = fmt.Sprintf(" %s %s %s %s %s %s %s ", red("4"), "5", "6", "7", "8", "9", blue("10"))
if calendar.Body[1] != expect {
t.Errorf("Expect calendar.Body[1] is %s, but %s", expect, calendar.Body[1])
}
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", red("11"), "12", "13", "14", "15", "16", blue("17"))
if calendar.Body[2] != expect {
t.Errorf("Expect calendar.Body[2] is %s, but %s", expect, calendar.Body[2])
}
// 2016-09-19 and 09-22 is holiday
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", red("18"), red("19"), "20", "21", red("22"), "23", blue("24"))
if calendar.Body[3] != expect {
t.Errorf("Expect calendar.Body[3] is %s, but %s", expect, calendar.Body[3])
}
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", red("25"), "26", "27", "28", "29", "30", " ")
if calendar.Body[4] != expect {
t.Errorf("Expect calendar.Body[4] is %s, but %s", expect, calendar.Body[4])
}
}
func TestGenerate_fitsOnFourLines(t *testing.T) {
var calendar Calendar
date, _ := time.Parse("2006-01-02", "2026-02-01")
calendar.Generate(date)
expect := " 2026年 02月 "
if calendar.DateHeader != expect {
t.Errorf("Expect calendar.DateHeader is %s, but %s", expect, calendar.DateHeader)
}
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", red("日"), "月", "火", "水", "木", "金", blue("土"))
if calendar.WeekHeader != expect {
t.Errorf("Expect calendar.WeekHeader is %s, but %s", expect, calendar.WeekHeader)
}
expect = fmt.Sprintf(" %s %s %s %s %s %s %s ", red("1"), "2", "3", "4", "5", "6", blue("7"))
if calendar.Body[0] != expect {
t.Errorf("Expect calendar.Body[0] is %s, but %s", expect, calendar.Body[0])
}
expect = fmt.Sprintf(" %s %s %s %s %s %s %s ", red("8"), "9", "10", red("11"), "12", "13", blue("14"))
if calendar.Body[1] != expect {
t.Errorf("Expect calendar.Body[1] is %s, but %s", expect, calendar.Body[1])
}
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", red("15"), "16", "17", "18", "19", "20", blue("21"))
if calendar.Body[2] != expect {
t.Errorf("Expect calendar.Body[2] is %s, but %s", expect, calendar.Body[2])
}
expect = fmt.Sprintf("%s %s %s %s %s %s %s ", red("22"), "23", "24", "25", "26", "27", blue("28"))
if calendar.Body[3] != expect {
t.Errorf("Expect calendar.Body[3] is %s, but %s", expect, calendar.Body[3])
}
expect = strings.Repeat(" ", 23)
if calendar.Body[4] != expect {
t.Errorf("Expect calendar.Body[4] is %s, but %s", expect, calendar.Body[4])
}
}
func TestClear(t *testing.T) {
var calendar Calendar
date, _ := time.Parse("2006-01-02", "2016-10-08")
calendar.Generate(date)
calendar.Clear()
if len(calendar.DateHeader) > 0 {
t.Errorf("Expect calendar.DateHeader is empty, but %s", calendar.DateHeader)
}
if len(calendar.WeekHeader) > 0 {
t.Errorf("Expect calendar.WeekHeader is empty, but %s", calendar.WeekHeader)
}
for _, element := range calendar.Body {
if len(element) > 0 {
t.Errorf("Expect calendar.Body is empty, but %s", element)
}
}
}