github.com/geraldss/go/src@v0.0.0-20210511222824-ac7d0ebfc235/io/fs/fs_test.go (about) 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 5 package fs_test 6 7 import ( 8 . "io/fs" 9 "testing" 10 ) 11 12 var isValidPathTests = []struct { 13 name string 14 ok bool 15 }{ 16 {".", true}, 17 {"x", true}, 18 {"x/y", true}, 19 20 {"", false}, 21 {"..", false}, 22 {"/", false}, 23 {"x/", false}, 24 {"/x", false}, 25 {"x/y/", false}, 26 {"/x/y", false}, 27 {"./", false}, 28 {"./x", false}, 29 {"x/.", false}, 30 {"x/./y", false}, 31 {"../", false}, 32 {"../x", false}, 33 {"x/..", false}, 34 {"x/../y", false}, 35 {"x//y", false}, 36 {`x\`, false}, 37 {`x\y`, false}, 38 {`\x`, false}, 39 } 40 41 func TestValidPath(t *testing.T) { 42 for _, tt := range isValidPathTests { 43 ok := ValidPath(tt.name) 44 if ok != tt.ok { 45 t.Errorf("ValidPath(%q) = %v, want %v", tt.name, ok, tt.ok) 46 } 47 } 48 }