-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathmain_test.go
48 lines (42 loc) · 1.54 KB
/
main_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
package main
import (
"testing"
"time"
)
func TestStripANSICodes(t *testing.T) {
tests := []struct {
give string
want string
}{
{"\x1B[0m", ""},
{"some text \x1B[23m\x1B[2;13m", "some text "},
{"no code", "no code"},
{"\x1B[13m\x1B[23m\x1B[3m", ""},
}
for _, tt := range tests {
got := stripANSICodes(tt.give)
if got != tt.want {
t.Errorf("stripANSICodes(%q) got %q, want %q", tt.give, got, tt.want)
}
}
}
var now = time.Now()
var formatTimeTests = []struct {
t time.Time
want string
}{
{time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC), "Nov 10, 2009 at 11:00pm (UTC)"},
{time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()-1, 0, now.Location()), "1 second ago"},
{time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()-30, 0, now.Location()), "30 seconds ago"},
{time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-1, now.Second(), 0, now.Location()), "1 minute ago"},
{time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-30, now.Second(), 0, now.Location()), "30 minutes ago"},
{time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-1, now.Minute(), now.Second(), 0, now.Location()), "1 hour ago"},
{time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-3, now.Minute(), now.Second(), 0, now.Location()), "3 hours ago"},
}
func TestFormatTime(t *testing.T) {
for _, tt := range formatTimeTests {
if got := formatTime(tt.t); got != tt.want {
t.Errorf("formatTime(%s) = %s, want %s", tt.t, got, tt.want)
}
}
}