-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc_test.go
More file actions
73 lines (62 loc) · 1.45 KB
/
misc_test.go
File metadata and controls
73 lines (62 loc) · 1.45 KB
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
package utils
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/akfaew/utils/fixture"
)
func TestSlash(t *testing.T) {
tests := []struct {
input string
ret1 string
ret2 string
}{
{"", "", ""},
{"test", "test", ""},
{"test/", "test", ""},
{"test///", "test", "//"},
{"test/case", "test", "case"},
{"test/case/a/b/c", "test", "case/a/b/c"},
{"/case/a/b/c", "", "case/a/b/c"},
}
for _, tc := range tests {
ret1, ret2 := Slash(tc.input)
require.Equal(t, ret1, tc.ret1)
require.Equal(t, ret2, tc.ret2)
}
}
func TestRandEmail(t *testing.T) {
val := RandEmail()
require.Len(t, val, 16)
}
func TestCrc32(t *testing.T) {
for _, s := range []string{"a", "", "://!%$"} {
t.Run(Crc32(s), func(t *testing.T) {
fixture.Fixture(t, fmt.Sprintf("%s -> %s\n", s, Crc32(s)))
})
}
}
func TestUniq(t *testing.T) {
t.Run("int", func(t *testing.T) {
input := []int{5, 3, 2, 3, 1, 2, 5}
original := append([]int(nil), input...)
output := Uniq(input)
require.Equal(t, []int{1, 2, 3, 5}, output)
require.Equal(t, original, input)
})
t.Run("string", func(t *testing.T) {
input := []string{"b", "a", "b", "c", "a"}
output := Uniq(input)
require.Equal(t, []string{"a", "b", "c"}, output)
})
t.Run("nil", func(t *testing.T) {
var input []int
output := Uniq(input)
require.Nil(t, output)
})
t.Run("empty", func(t *testing.T) {
input := []int{}
output := Uniq(input)
require.Len(t, output, 0)
})
}