Skip to content

Commit

Permalink
filename test
Browse files Browse the repository at this point in the history
  • Loading branch information
sayem314 committed Sep 27, 2024
1 parent 7215ebe commit 54f8584
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions utils/filename_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package utils

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestSanitizeFileName(t *testing.T) {
tests := []struct {
input string
expected string
}{
// Basic cases
{"normal_filename.txt", "normal_filename.txt"},
{"filename with spaces.txt", "filename with spaces.txt"},
// Invalid characters
{"file*name?.txt", "file_name_.txt"},
{"<>:\"/\\|?*\x00-\x1F", "__________-_"},
// Trailing periods and spaces
{"filename.", "filename"},
{"filename ", "filename"},
{"filename. ", "filename"},
// Combination
{"inva?lid:fi*le|name.txt", "inva_lid_fi_le_name.txt"},
// Unicode characters
{"ファイル名.txt", "ファイル名.txt"},
// Edge cases
{"", ""},
{".", ""},
{" ", ""},
{"...", ""},
{"..filename..", "..filename"},
}

for _, test := range tests {
t.Run(test.input, func(t *testing.T) {
result := SanitizeFileName(test.input)
assert.Equal(t, test.expected, result, "SanitizeFileName(%q)", test.input)
})
}
}

0 comments on commit 54f8584

Please sign in to comment.