github.com/ali-iotechsys/cli@v20.10.0+incompatible/cli/compose/loader/windows_path_test.go (about) 1 package loader 2 3 // Copyright 2010 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 // https://github.com/golang/go/blob/master/LICENSE 7 8 // The code in this file was copied from the Golang filepath package with some 9 // small modifications to run it on non-Windows platforms. 10 // https://github.com/golang/go/blob/1d0e94b1e13d5e8a323a63cd1cc1ef95290c9c36/src/path/filepath/path_test.go#L711-L763 11 12 import "testing" 13 14 type IsAbsTest struct { 15 path string 16 isAbs bool 17 } 18 19 var isabstests = []IsAbsTest{ 20 {"", false}, 21 {"/", true}, 22 {"/usr/bin/gcc", true}, 23 {"..", false}, 24 {"/a/../bb", true}, 25 {".", false}, 26 {"./", false}, 27 {"lala", false}, 28 } 29 30 var winisabstests = []IsAbsTest{ 31 {`C:\`, true}, 32 {`c\`, false}, 33 {`c::`, false}, 34 {`c:`, false}, 35 {`/`, false}, 36 {`\`, false}, 37 {`\Windows`, false}, 38 {`c:a\b`, false}, 39 {`c:\a\b`, true}, 40 {`c:/a/b`, true}, 41 {`\\host\share\foo`, true}, 42 {`//host/share/foo/bar`, true}, 43 } 44 45 func TestIsAbs(t *testing.T) { 46 tests := winisabstests 47 48 // All non-windows tests should fail, because they have no volume letter. 49 for _, test := range isabstests { 50 tests = append(tests, IsAbsTest{test.path, false}) 51 } 52 // All non-windows test should work as intended if prefixed with volume letter. 53 for _, test := range isabstests { 54 tests = append(tests, IsAbsTest{"c:" + test.path, test.isAbs}) 55 } 56 57 for _, test := range tests { 58 if r := isAbs(test.path); r != test.isAbs { 59 t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs) 60 } 61 } 62 }