forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_time_test.go
57 lines (53 loc) · 1.27 KB
/
segment_time_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
package main
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestTimeSegmentTemplate(t *testing.T) {
// set date for unit test
currentDate := time.Now()
cases := []struct {
Case string
ExpectedEnabled bool
ExpectedString string
Template string
}{
{
Case: "no template",
Template: "",
ExpectedString: currentDate.Format("15:04:05"),
ExpectedEnabled: true,
},
{
Case: "time only",
Template: "{{.CurrentDate | date \"15:04:05\"}}",
ExpectedString: currentDate.Format("15:04:05"),
ExpectedEnabled: true,
},
{
Case: "lowercase",
Template: "{{.CurrentDate | date \"January 02, 2006 15:04:05\" | lower }}",
ExpectedString: strings.ToLower(currentDate.Format("January 02, 2006 15:04:05")),
ExpectedEnabled: true,
},
}
for _, tc := range cases {
env := new(MockedEnvironment)
props := &properties{
values: map[Property]interface{}{
SegmentTemplate: tc.Template,
},
}
tempus := &tempus{
env: env,
props: props,
CurrentDate: currentDate,
}
assert.Equal(t, tc.ExpectedEnabled, tempus.enabled())
if tc.ExpectedEnabled {
assert.Equal(t, tc.ExpectedString, tempus.string(), tc.Case)
}
}
}