cuelang.org/go@v0.13.0/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@v1.2.3", true},
    30  		{"foo.bar/baz@v1.2", true},
    31  		{"foo.bar/baz@v1.latest:foo", true},
    32  		{"foo.bar/foo", true},
    33  		{"./.foo", true},
    34  		{"./.foo.json", false},
    35  		{`C:\Users\somefile.cue`, false},
    36  		{`/foo.cue`, false},
    37  		{`C:somefile.cue`, false},
    38  		{`foo.cue:1234`, false},
    39  		{`foo.cue:12:13`, false},
    40  		// Not supported yet, but could be and isn't anything else valid.
    41  		{":foo", true},
    42  
    43  		{"foo.bar", false},
    44  		{"foo:", false},
    45  		{"foo:bar:baz", false},
    46  		{"-", false},
    47  		{"-:foo", false},
    48  	}
    49  	for _, tc := range testCases {
    50  		t.Run(tc.in, func(t *testing.T) {
    51  			got := IsPackage(tc.in)
    52  			if got != tc.out {
    53  				t.Errorf("%q; got %v; want %v", tc.in, got, tc.out)
    54  			}
    55  		})
    56  	}
    57  }