-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhandlers_test.go
94 lines (77 loc) · 1.56 KB
/
handlers_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/obalunenko/advent-of-code/internal/puzzles"
)
func Test_makeMenuItemsList(t *testing.T) {
type args struct {
list []string
commands []string
}
tests := []struct {
name string
args args
want []string
}{
{
name: "without commands",
args: args{
list: []string{"1", "2", "3"},
commands: nil,
},
want: []string{"1", "2", "3"},
},
{
name: "with commands",
args: args{
list: []string{"1", "2", "3"},
commands: []string{"cmd1", "cmd2"},
},
want: []string{"1", "2", "3", "cmd1", "cmd2"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := makeMenuItemsList(tt.args.list, tt.args.commands...)
assert.Equal(t, tt.want, got)
})
}
}
func Test_searcher(t *testing.T) {
items := makeMenuItemsList([]string{"one", "two", "three"}, exit)
s := searcher(items)
assert.True(t, s("o", 0))
assert.Panics(t, func() {
s("o", 10)
})
assert.True(t, s("t", 2))
assert.False(t, s("1", 2))
}
func Test_getUrl(t *testing.T) {
type args struct {
year string
day string
}
tests := []struct {
name string
args args
want string
}{
{
name: "",
args: args{
year: puzzles.Year2022.String(),
day: puzzles.Day01.String(),
},
want: "https://adventofcode.com/2022/day/1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := getURL(tt.args.year, tt.args.day)
assert.Equalf(t, tt.want, got,
"getURL(%v, %v)", tt.args.year, tt.args.day)
})
}
}