2023-03-06 22:49:16 +00:00
|
|
|
package common
|
|
|
|
|
2024-02-06 15:13:53 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
2023-03-06 22:49:16 +00:00
|
|
|
|
|
|
|
func TestSkipFile(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
file string
|
|
|
|
want bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a test case for each ignored extension.
|
2024-02-06 15:13:53 +00:00
|
|
|
testCases := make([]testCase, 0, (len(ignoredExtensions)+1)*2)
|
|
|
|
for ext := range ignoredExtensions {
|
2023-03-06 22:49:16 +00:00
|
|
|
testCases = append(testCases, testCase{
|
|
|
|
file: "test." + ext,
|
|
|
|
want: true,
|
|
|
|
})
|
2024-02-06 15:13:53 +00:00
|
|
|
|
|
|
|
testCases = append(testCases, testCase{
|
|
|
|
file: "test." + strings.ToUpper(ext),
|
|
|
|
want: true,
|
|
|
|
})
|
2023-03-06 22:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a test case for a file that should not be skipped.
|
|
|
|
testCases = append(testCases, testCase{file: "test.txt", want: false})
|
|
|
|
|
|
|
|
for _, tt := range testCases {
|
|
|
|
t.Run(tt.file, func(t *testing.T) {
|
|
|
|
if got := SkipFile(tt.file); got != tt.want {
|
|
|
|
t.Errorf("SkipFile(%v) got %v, want %v", tt.file, got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkSkipFile(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
SkipFile("test.mp4")
|
|
|
|
}
|
|
|
|
}
|
2023-12-15 19:46:27 +00:00
|
|
|
|
|
|
|
func TestIsBinary(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
file string
|
|
|
|
want bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a test case for each binary extension.
|
|
|
|
testCases := make([]testCase, 0, len(binaryExtensions)+1)
|
|
|
|
for ext := range binaryExtensions {
|
|
|
|
testCases = append(testCases, testCase{
|
|
|
|
file: "test." + ext,
|
|
|
|
want: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a test case for a file that should not be skipped.
|
|
|
|
testCases = append(testCases, testCase{file: "test.txt", want: false})
|
|
|
|
|
|
|
|
for _, tt := range testCases {
|
|
|
|
t.Run(tt.file, func(t *testing.T) {
|
|
|
|
if got := IsBinary(tt.file); got != tt.want {
|
|
|
|
t.Errorf("IsBinary(%v) got %v, want %v", tt.file, got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIsBinary(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
IsBinary("test.exe")
|
|
|
|
}
|
|
|
|
}
|