File: collect_test.go

package info (click to toggle)
kitty 0.44.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,540 kB
  • sloc: ansic: 84,052; python: 57,643; objc: 5,365; sh: 1,319; xml: 364; makefile: 144; javascript: 78
file content (54 lines) | stat: -rw-r--r-- 1,418 bytes parent folder | download
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
47
48
49
50
51
52
53
54
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>

package diff

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"testing"

	"github.com/kovidgoyal/kitty/tools/utils"

	"github.com/google/go-cmp/cmp"
)

var _ = fmt.Print

func TestDiffCollectWalk(t *testing.T) {
	tdir := t.TempDir()
	j := func(x ...string) string { return filepath.Join(append([]string{tdir}, x...)...) }
	_ = os.MkdirAll(j("a", "b"), 0o700)
	_ = os.WriteFile(j("a/b/c"), nil, 0o600)
	_ = os.WriteFile(j("b"), nil, 0o600)
	_ = os.WriteFile(j("d"), nil, 0o600)
	_ = os.WriteFile(j("e"), nil, 0o600)
	_ = os.WriteFile(j("#d#"), nil, 0o600)
	_ = os.WriteFile(j("e~"), nil, 0o600)
	_ = os.MkdirAll(j("f"), 0o700)
	_ = os.WriteFile(j("f/g"), nil, 0o600)
	_ = os.WriteFile(j("h space"), nil, 0o600)

	expected_names := utils.NewSetWithItems("d", "e", "f/g", "h space")
	expected_pmap := map[string]string{
		"d":       j("d"),
		"e":       j("e"),
		"f/g":     j("f/g"),
		"h space": j("h space"),
	}
	names := utils.NewSet[string](16)
	pmap := make(map[string]string, 16)
	if err := walk(tdir, []string{"*~", "#*#", "b"}, names, pmap, map[string]string{}); err != nil {
		t.Fatal(err)
	}
	if diff := cmp.Diff(
		utils.Sort(expected_names.AsSlice(), strings.Compare),
		utils.Sort(names.AsSlice(), strings.Compare),
	); diff != "" {
		t.Fatal(diff)
	}
	if diff := cmp.Diff(expected_pmap, pmap); diff != "" {
		t.Fatal(diff)
	}
}