cuelang.org/go@v0.10.1/internal/filetypes/util_test.go (about) 1 // Copyright 2020 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package filetypes 16 17 import "testing" 18 19 func TestIsPackage(t *testing.T) { 20 testCases := []struct { 21 in string 22 out bool 23 }{ 24 {".", true}, 25 {"..", true}, 26 {"../.../foo", true}, 27 {".../foo", true}, 28 {"./:foo", true}, 29 {"foo.bar/foo", true}, 30 {"./.foo", true}, 31 {"./.foo.json", false}, 32 33 // Not supported yet, but could be and isn't anything else valid. 34 {":foo", true}, 35 36 {"foo.bar", false}, 37 {"foo:", false}, 38 {"foo:bar:baz", false}, 39 {"-", false}, 40 {"-:foo", false}, 41 } 42 for _, tc := range testCases { 43 t.Run(tc.in, func(t *testing.T) { 44 got := IsPackage(tc.in) 45 if got != tc.out { 46 t.Errorf("got %v; want %v", got, tc.out) 47 } 48 }) 49 } 50 }