MCPcopy
hub / github.com/pocketbase/pocketbase / TestFileNameNormalizations

Function TestFileNameNormalizations

tools/filesystem/file_test.go:205–236  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

203}
204
205func TestFileNameNormalizations(t *testing.T) {
206 scenarios := []struct {
207 name string
208 pattern string
209 }{
210 {"", `^\w{10}_\w{10}\.txt$`},
211 {".png", `^\w{10}_\w{10}\.png$`},
212 {".tar.gz", `^\w{10}_\w{10}\.tar\.gz$`},
213 {"a.tar.gz", `^a\w{10}_\w{10}\.tar\.gz$`},
214 {"....abc", `^\w{10}_\w{10}\.abc$`},
215 {"a.b.c.?.?.?.2", `^a_b_c_\w{10}\.2$`},
216 {"a.b.c.d.tar.gz", `^a_b_c_d_\w{10}\.tar\.gz$`},
217 {"abcd", `^abcd_\w{10}\.txt$`},
218 {".abcd.123.", `^abcd_\w{10}\.123$`},
219 {"a b! c d . 456", `^a_b_c_d_\w{10}\.456$`}, // normalize spaces
220 {strings.Repeat("a", 101) + "." + strings.Repeat("b", 21), `^a{100}_\w{10}\.b{20}$`}, // name and extension length cut
221 {"abc" + strings.Repeat("d", 290) + "." + strings.Repeat("b", 9), `^d{100}_\w{10}\.b{9}$`}, // initial total length cut
222 }
223
224 for i, s := range scenarios {
225 t.Run(strconv.Itoa(i)+"_"+s.name, func(t *testing.T) {
226 f, err := filesystem.NewFileFromBytes([]byte("abc"), s.name)
227 if err != nil {
228 t.Fatal(err)
229 }
230 match, err := regexp.Match(s.pattern, []byte(f.Name))
231 if !match {
232 t.Fatalf("Expected Name to match %v, got %q (%v)", s.pattern, f.Name, err)
233 }
234 })
235 }
236}

Callers

nothing calls this directly

Calls 2

NewFileFromBytesFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…