-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposix_test.go
More file actions
97 lines (92 loc) · 2.36 KB
/
posix_test.go
File metadata and controls
97 lines (92 loc) · 2.36 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package patterns_test
import (
"snekcheck/internal/patterns"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func BenchmarkPosix(b *testing.B) {
b.Run("IsPosixFileName()", func(b *testing.B) {
for range b.N {
patterns.IsPosixFileName("Bench mark")
}
})
b.Run("ToPosixFileName()", func(b *testing.B) {
for range b.N {
patterns.ToPosixFileName("Bench mark")
}
})
}
func FuzzPosix(f *testing.F) {
f.Fuzz(func(t *testing.T, input string) {
output := patterns.ToPosixFileName(input)
assert.True(t, patterns.IsPosixFileName(output))
if patterns.IsPosixFileName(input) {
assert.Equal(t, input, output)
}
})
}
func TestPosix(t *testing.T) {
t.Parallel()
t.Run("IsPosixFileName()", func(t *testing.T) {
t.Parallel()
t.Run("identifies valid POSIX filenames", func(t *testing.T) {
t.Parallel()
testCases := []string{
"posix",
"POSIX_FILE",
"_POSIX__FILE_.md",
"012_345",
"FILE1.txt",
}
for _, input := range testCases {
assert.True(t, patterns.IsPosixFileName(input))
}
})
t.Run("identifies invalid POSIX filenames", func(t *testing.T) {
t.Parallel()
testCases := []string{
"-TEST",
"lol@email",
"invalid%",
"file(12).pdf",
}
for _, input := range testCases {
assert.False(t, patterns.IsPosixFileName(input))
}
})
})
t.Run("ToPosixFileName()", func(t *testing.T) {
t.Parallel()
t.Run("does not change valid POSIX filenames", func(t *testing.T) {
t.Parallel()
testCases := []string{
"POSIX",
".POSIX_123_.md",
"_DO_NOT_CHANGE_THIS_PLEASE___",
}
for _, input := range testCases {
require.True(t, patterns.IsPosixFileName(input))
assert.Equal(t, input, patterns.ToPosixFileName(input))
}
})
t.Run("converts invalid POSIX filenames to valid POSIX filenames", func(t *testing.T) {
t.Parallel()
testCases := []struct {
input string
output string
}{
{input: "lol#$", output: "lol"},
{input: "spaced name", output: "spaced__name"},
{input: "__012 345.md", output: "__012_345.md"},
}
for _, tc := range testCases {
require.False(t, patterns.IsPosixFileName(tc.input))
require.True(t, patterns.IsPosixFileName(tc.output))
actual := patterns.ToPosixFileName(tc.input)
assert.Equal(t, tc.output, actual)
assert.True(t, patterns.IsPosixFileName(actual))
}
})
})
}