forked from naggie/dstask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
116 lines (105 loc) · 1.71 KB
/
util_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
114
115
116
package dstask
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMakeTempFilename(t *testing.T) {
type testCase struct {
id int
summary string
expected string
}
var testCases = []testCase{
{
1,
`& &`,
`dstask.*.1-.md`,
},
{
2147483647, // max int32
`J's $100, != €100`,
`dstask.*.2147483647-js-100-100.md`,
},
{
-2147483648, // min int32
`J's $100, != €100`,
`dstask.*.-2147483648-js-100-100.md`,
},
{
99,
`A simple summary!`,
`dstask.*.99-a-simple-summary.md`,
},
{
1,
`& that's that.`,
`dstask.*.1-thats-that.md`,
},
}
for _, tc := range testCases {
tf := MakeTempFilename(tc.id, tc.summary, "md")
assert.Equal(t, tc.expected, tf)
f, err := os.CreateTemp("", tf)
assert.Nil(t, err)
assert.Nil(t, f.Close())
assert.Nil(t, os.Remove(f.Name()))
}
}
func TestStrSliceContainsAll(t *testing.T) {
type testCase struct {
subset []string
superset []string
expected bool
}
var testCases = []testCase{
{
[]string{},
[]string{},
true,
},
{
[]string{"one"},
[]string{"one"},
true,
},
{
[]string{"one"},
[]string{"two"},
false,
},
{
[]string{"one"},
[]string{},
false,
},
{
[]string{"one"},
[]string{"one", "two"},
true,
},
{
[]string{"one", "two"},
[]string{"one", "two"},
true,
},
{
[]string{"two", "one"},
[]string{"three", "one", "two"},
true,
},
{
[]string{"apple", "two", "one"},
[]string{"three", "one", "two"},
false,
},
{
[]string{},
[]string{"three", "one", "two"},
true,
},
}
for _, tc := range testCases {
assert.Equal(t, tc.expected, StrSliceContainsAll(tc.subset, tc.superset))
}
}