Debian Codegraph @

internal/pathutil/hfs_test.go

raw
1 package pathutil
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestIsHFSDotGit(t *testing.T) {
10 t.Parallel()
11
12 tests := []struct {
13 part string
14 want bool
15 }{
16 {".git", true},
17 {".Git", true},
18 {".GIT", true},
19 {".gIt", true},
20 {".g\u200cit", true},
21 {".gi\u200dt", true},
22 {".gi\ufefft", true},
23 {"\u200e.git", true},
24 {".g\u200ci\u200dt", true},
25 {".gitmodules", false},
26 {".gitignore", false},
27 {".git2", false},
28 {"git", false},
29 {".gxt", false},
30 {"", false},
31 {".", false},
32 {".g\x80it", false},
33 }
34
35 for _, tc := range tests {
36 t.Run(tc.part, func(t *testing.T) {
37 t.Parallel()
38 assert.Equal(t, tc.want, IsHFSDotGit(tc.part))
39 })
40 }
41 }
42
43 func TestIsHFSDot(t *testing.T) {
44 t.Parallel()
45
46 tests := []struct {
47 name string
48 part string
49 needle string
50 want bool
51 }{
52 // .git \u2014 matches existing IsHFSDotGit semantics.
53 {"plain .git", ".git", "git", true},
54 {"zwj in .git", ".g\u200dit", "git", true},
55 {"zwnj in .git", ".g\u200cit", "git", true},
56 {"leading lrm", "\u200e.git", "git", true},
57 {".gitmodules is not .git", ".gitmodules", "git", false},
58 {"empty string for git", "", "git", false},
59
60 // .gitmodules \u2014 the parameterised needle.
61 {"plain .gitmodules", ".gitmodules", "gitmodules", true},
62 {"uppercase .GITMODULES", ".GITMODULES", "gitmodules", true},
63 {"zwnj in .gitmodules", ".g\u200citmodules", "gitmodules", true},
64 {"zwj in .gitmodules", ".gitmod\u200dules", "gitmodules", true},
65 {"trailing zwsp", ".gitmodules\ufeff", "gitmodules", true},
66 {"leading lrm", "\u200e.gitmodules", "gitmodules", true},
67 {".gitmodulesfoo", ".gitmodulesfoo", "gitmodules", false},
68 {".git is not .gitmodules", ".git", "gitmodules", false},
69 {"plain readme.md", "readme.md", "gitmodules", false},
70 {"empty string", "", "gitmodules", false},
71 {"only dot", ".", "gitmodules", false},
72 {"non-ascii in needle position", ".g\x80itmodules", "gitmodules", false},
73 }
74
75 for _, tc := range tests {
76 t.Run(tc.name, func(t *testing.T) {
77 t.Parallel()
78 got := IsHFSDot(tc.part, tc.needle)
79 assert.Equal(t, tc.want, got, "IsHFSDot(%q, %q)", tc.part, tc.needle)
80 })
81 }
82 }
83
84 func TestIsHFSDotGitmodules(t *testing.T) {
85 t.Parallel()
86
87 tests := []struct {
88 part string
89 want bool
90 }{
91 {".gitmodules", true},
92 {".GITMODULES", true},
93 {".g\u200citmodules", true},
94 {".gitmod\u200dules", true},
95 {"\u200e.gitmodules", true},
96 {".gitmodules\ufeff", true},
97 {".gitmodulesfoo", false},
98 {".git", false},
99 {"readme.md", false},
100 {"", false},
101 }
102
103 for _, tc := range tests {
104 t.Run(tc.part, func(t *testing.T) {
105 t.Parallel()
106 assert.Equal(t, tc.want, IsHFSDotGitmodules(tc.part))
107 })
108 }
109 }