-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_test.go
102 lines (97 loc) · 2.08 KB
/
bot_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
package main_test
import (
"testing"
"time"
bot "grol.io/grol-discord-bot"
)
func TestUptime(t *testing.T) {
delta := 100*time.Millisecond + 26*time.Hour + 42*time.Minute
startTime := time.Now().Add(-delta)
actual := bot.UptimeString(startTime)
expected := "1d2h42m0.1s"
if actual != expected {
t.Errorf("Expected %v, but got %v", expected, actual)
}
delta = 23*time.Hour + 5*time.Minute
actual = bot.DurationString(delta)
expected = "23h5m0s"
if actual != expected {
t.Errorf("Expected %v, but got %v", expected, actual)
}
delta = 96*time.Hour - 100*time.Millisecond
actual = bot.DurationString(delta)
expected = "3d23h59m59.9s"
if actual != expected {
t.Errorf("Expected %v, but got %v", expected, actual)
}
}
func TestRemoveBackticks(t *testing.T) {
// table driven inpute,expected
tests := []struct {
input, expected string
}{
{" foo \n bar ", "foo \n bar"},
{
`
this is before code
` + "```go" + `
a=1
b=2
` + "```" + `
some stuff after code`,
"a=1\nb=2",
},
{
`
this is before code
` + "```go" + `
a=1
b=2
` + "```" + `
some stuff after code
` + "```c=3``` and ```d=4```",
"a=1\nb=2\nc=3\nd=4",
},
}
for _, test := range tests {
actual := bot.RemoveTripleBackticks(test.input)
if actual != test.expected {
t.Errorf("---For---\n%s\n---Expected %q, but got %q", test.input, test.expected, actual)
}
}
}
func TestSmartQuotesToRegular(t *testing.T) {
// table driven inpute,expected
tests := []struct {
input, expected string
}{
{`abc“def`, `abc"def`},
{" no quotes ", " no quotes "},
{
"“this is a quote”",
`"this is a quote"`,
},
{
`\“”`,
`\“”`,
},
{
`len("“")`,
`len("“")`,
},
{
`load(“”)`,
`load("")`,
},
{
"println(“this is a quote”); println(“this is another quote”)",
`println("this is a quote"); println("this is another quote")`,
},
}
for _, test := range tests {
actual := bot.SmartQuotesToRegular(test.input)
if actual != test.expected {
t.Errorf("---For---\n%s\n---Expected %q, but got %q", test.input, test.expected, actual)
}
}
}