File: utils_test.go

package info (click to toggle)
golang-github-bmatcuk-doublestar 4.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 212 kB
  • sloc: makefile: 6
file content (46 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package doublestar

import (
	"path/filepath"
	"testing"
)

var filepathGlobTests = []string{
	".",
	"././.",
	"..",
	"../.",
	".././././",
	"../..",
	"/",
	"./",
	"/.",
	"/././././",
	"nopermission/.",
}

func TestSpecialFilepathGlobCases(t *testing.T) {
	for idx, pattern := range filepathGlobTests {
		testSpecialFilepathGlobCasesWith(t, idx, pattern)
	}
}

func testSpecialFilepathGlobCasesWith(t *testing.T, idx int, pattern string) {
	defer func() {
		if r := recover(); r != nil {
			t.Errorf("#%v. FilepathGlob(%#q) panicked with: %#v", idx, pattern, r)
		}
	}()

	pattern = filepath.FromSlash(pattern)
	matches, err := FilepathGlob(pattern)
	results, stdErr := filepath.Glob(pattern)

	// doublestar.FilepathGlob Cleans the path
	for idx, result := range results {
		results[idx] = filepath.Clean(result)
	}
	if !compareSlices(matches, results) || !compareErrors(err, stdErr) {
		t.Errorf("#%v. FilepathGlob(%#q) != filepath.Glob(%#q). Got %#v, %v want %#v, %v", idx, pattern, pattern, matches, err, results, stdErr)
	}
}