github.com/AndrewDeryabin/doublestar/v4@v4.0.0-20230123132908-d9476b7d41be/utils_test.go (about)

     1  package doublestar
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  )
     7  
     8  var filepathGlobTests = []string{
     9  	".",
    10  	"././.",
    11  	"..",
    12  	"../.",
    13  	".././././",
    14  	"../..",
    15  	"/",
    16  	"./",
    17  	"/.",
    18  	"/././././",
    19  	"nopermission/.",
    20  }
    21  
    22  func TestSpecialFilepathGlobCases(t *testing.T) {
    23  	for idx, pattern := range filepathGlobTests {
    24  		testSpecialFilepathGlobCasesWith(t, idx, pattern)
    25  	}
    26  }
    27  
    28  func testSpecialFilepathGlobCasesWith(t *testing.T, idx int, pattern string) {
    29  	defer func() {
    30  		if r := recover(); r != nil {
    31  			t.Errorf("#%v. FilepathGlob(%#q) panicked with: %#v", idx, pattern, r)
    32  		}
    33  	}()
    34  
    35  	pattern = filepath.FromSlash(pattern)
    36  	matches, err := FilepathGlob(pattern)
    37  	results, stdErr := filepath.Glob(pattern)
    38  
    39  	// doublestar.FilepathGlob Cleans the path
    40  	for idx, result := range results {
    41  		results[idx] = filepath.Clean(result)
    42  	}
    43  	if !compareSlices(matches, results) || !compareErrors(err, stdErr) {
    44  		t.Errorf("#%v. FilepathGlob(%#q) != filepath.Glob(%#q). Got %#v, %v want %#v, %v", idx, pattern, pattern, matches, err, results, stdErr)
    45  	}
    46  }