github.com/blend/go-sdk@v1.20220411.3/stringutil/glob_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stringutil
     9  
    10  import (
    11  	"fmt"
    12  	"testing"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  )
    16  
    17  func Test_Glob(t *testing.T) {
    18  	its := assert.New(t)
    19  
    20  	testCases := [...]struct {
    21  		Subj     string
    22  		Pattern  string
    23  		Expected bool
    24  	}{
    25  		{"", "", true},
    26  		{"test", "", false},
    27  		{"", "false", false},
    28  		{"", "*", true},
    29  		{"foo", "*", true},
    30  		{"bar", "*", true},
    31  
    32  		{"bar/foo", "bar/*", true},
    33  		{"foo/bar", "bar/*", false},
    34  
    35  		{"bar/loo/foo", "bar/*", true},
    36  		{"foo/bar/loo", "bar/*", false},
    37  
    38  		{"foo/bar/baz/buzz", "*/bar/*", true},
    39  		{"/foo/bar/baz/buzz", "*/bar/*", true},
    40  		{"foo/bar/baz/buzz", "*/foo/*", false},
    41  		{"foo/bar/baz/buzz", "foo/*", true},
    42  		{"/foo/bar/baz/buzz", "*foo/*", true},
    43  		{"test", "te*", true},
    44  		{"test", "*st", true},
    45  		{"test", "foo", false},
    46  		{"test", "foo*", false},
    47  		{"test", "*foo*", false},
    48  	}
    49  
    50  	for _, testCase := range testCases {
    51  		its.Equal(testCase.Expected, Glob(testCase.Subj, testCase.Pattern), fmt.Sprint(testCase.Subj, " => ", testCase.Pattern))
    52  	}
    53  }