fs_test.go 847 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2020 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package fs_test
  5. import (
  6. . "io/fs"
  7. "testing"
  8. )
  9. var isValidPathTests = []struct {
  10. name string
  11. ok bool
  12. }{
  13. {".", true},
  14. {"x", true},
  15. {"x/y", true},
  16. {"", false},
  17. {"..", false},
  18. {"/", false},
  19. {"x/", false},
  20. {"/x", false},
  21. {"x/y/", false},
  22. {"/x/y", false},
  23. {"./", false},
  24. {"./x", false},
  25. {"x/.", false},
  26. {"x/./y", false},
  27. {"../", false},
  28. {"../x", false},
  29. {"x/..", false},
  30. {"x/../y", false},
  31. {"x//y", false},
  32. {`x\`, true},
  33. {`x\y`, true},
  34. {`x:y`, true},
  35. {`\x`, true},
  36. }
  37. func TestValidPath(t *testing.T) {
  38. for _, tt := range isValidPathTests {
  39. ok := ValidPath(tt.name)
  40. if ok != tt.ok {
  41. t.Errorf("ValidPath(%q) = %v, want %v", tt.name, ok, tt.ok)
  42. }
  43. }
  44. }