-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
205 lines (178 loc) · 5.83 KB
/
Copy pathutils_test.go
File metadata and controls
205 lines (178 loc) · 5.83 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package main
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestParseHex(t *testing.T) {
r, g, b := parseHex("#ff6b6b")
if r != 255 || g != 107 || b != 107 {
t.Errorf("Expected 255, 107, 107, got %d, %d, %d", r, g, b)
}
r, g, b = parseHex("000000")
if r != 0 || g != 0 || b != 0 {
t.Errorf("Expected 0, 0, 0, got %d, %d, %d", r, g, b)
}
}
func TestContrastColor(t *testing.T) {
// Dark background -> white text
r, g, b := contrastColor(0, 0, 0)
if r != 255 || g != 255 || b != 255 {
t.Errorf("Expected white text for dark bg, got %d, %d, %d", r, g, b)
}
// Light background -> black text
r, g, b = contrastColor(255, 255, 255)
if r != 0 || g != 0 || b != 0 {
t.Errorf("Expected black text for light bg, got %d, %d, %d", r, g, b)
}
}
func TestDetectTerminal(t *testing.T) {
os.Setenv("WT_SESSION", "1")
if detectTerminal() != termWindowsTerminal {
t.Errorf("Expected termWindowsTerminal")
}
os.Unsetenv("WT_SESSION")
os.Setenv("TERM_PROGRAM", "iTerm.app")
if detectTerminal() != termITerm2 {
t.Errorf("Expected termITerm2")
}
os.Unsetenv("TERM_PROGRAM")
if detectTerminal() != termStandard {
t.Errorf("Expected termStandard")
}
}
func TestColorSequences(t *testing.T) {
os.Setenv("TERM_PROGRAM", "iTerm.app")
seq := colorSequences(255, 0, 0, 255, 255, 255, "Test")
if !strings.Contains(seq, "bg;red;brightness;255") {
t.Errorf("Expected iTerm2 sequence, got %q", seq)
}
os.Unsetenv("TERM_PROGRAM")
os.Setenv("WT_SESSION", "1")
seq = colorSequences(255, 0, 0, 255, 255, 255, "Test")
if !strings.Contains(seq, "4;264;rgb:ff/00/00") {
t.Errorf("Expected WT palette 264 for tab bg, got %q", seq)
}
if !strings.Contains(seq, "4;263;rgb:ff/ff/ff") {
t.Errorf("Expected WT palette 263 for tab fg, got %q", seq)
}
os.Unsetenv("WT_SESSION")
seq = colorSequences(255, 0, 0, 255, 255, 255, "Test")
if !strings.Contains(seq, "11;rgb:ff/00/00") {
t.Errorf("Expected OSC 11 background sequence, got %q", seq)
}
if !strings.Contains(seq, "10;rgb:ff/ff/ff") {
t.Errorf("Expected OSC 10 foreground sequence, got %q", seq)
}
}
func TestResetSequences(t *testing.T) {
os.Setenv("TERM_PROGRAM", "iTerm.app")
seq := resetSequences()
if !strings.Contains(seq, "bg;*;default") {
t.Errorf("Expected iTerm2 reset, got %q", seq)
}
os.Unsetenv("TERM_PROGRAM")
os.Setenv("WT_SESSION", "1")
seq = resetSequences()
if !strings.Contains(seq, "104;263;264") {
t.Errorf("Expected WT palette reset, got %q", seq)
}
os.Unsetenv("WT_SESSION")
seq = resetSequences()
if !strings.Contains(seq, "110") {
t.Errorf("Expected OSC 110 foreground reset, got %q", seq)
}
if !strings.Contains(seq, "111") {
t.Errorf("Expected OSC 111 background reset, got %q", seq)
}
}
func TestDetectShell(t *testing.T) {
// We can't strictly test detectShell on Windows vs Linux completely because of runtime.GOOS,
// but we can test environment variable parsing if not windows
if runtimeOS := "linux"; runtimeOS == "linux" { // simulating non-windows behavior testing logic
os.Setenv("SHELL", "/bin/zsh")
if detectShell() != "zsh" && detectShell() != "powershell" { // powershell is forced on windows
t.Errorf("Expected zsh")
}
}
}
func TestDefaultProfilePath(t *testing.T) {
home, _ := os.UserHomeDir()
ps := defaultProfilePath("powershell")
if ps != filepath.Join(home, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1") {
t.Errorf("Unexpected powershell profile path: %s", ps)
}
zsh := defaultProfilePath("zsh")
if zsh != filepath.Join(home, ".zshrc") {
t.Errorf("Unexpected zsh profile path: %s", zsh)
}
bash := defaultProfilePath("bash")
if bash != filepath.Join(home, ".bashrc") {
t.Errorf("Unexpected bash profile path: %s", bash)
}
}
func TestHookSnippetVersion(t *testing.T) {
for _, shell := range []string{"powershell", "zsh", "bash"} {
snippet := hookSnippet(shell)
expected := "# ttag hook v" + version
if !strings.Contains(snippet, expected) {
t.Errorf("%s hook missing version line %q", shell, expected)
}
}
}
func TestInstalledHookVersion(t *testing.T) {
dir := t.TempDir()
profile := filepath.Join(dir, "profile")
// No file → empty
if v := installedHookVersion("bash", profile); v != "" {
t.Errorf("Expected empty version for missing profile, got %q", v)
}
// Write hook with version
snippet := hookSnippet("bash")
os.WriteFile(profile, []byte("# stuff\n"+snippet+"\n"), 0644)
if v := installedHookVersion("bash", profile); v != version {
t.Errorf("Expected %q, got %q", version, v)
}
// Write hook without version line (simulating old install)
old := hookMarkerStart + "\nsome old content\n" + hookMarkerEnd
os.WriteFile(profile, []byte(old), 0644)
if v := installedHookVersion("bash", profile); v != "" {
t.Errorf("Expected empty version for old hook, got %q", v)
}
}
func TestHookSnippet(t *testing.T) {
ps := hookSnippet("powershell")
if !strings.Contains(ps, "global:prompt") {
t.Errorf("Expected PowerShell hook")
}
if strings.Contains(ps, "__ttag_focused") {
t.Errorf("PowerShell hook should not contain focus tracking (PSReadLine cannot bind escape sequences)")
}
zsh := hookSnippet("zsh")
if !strings.Contains(zsh, "add-zsh-hook") {
t.Errorf("Expected Zsh hook")
}
if !strings.Contains(zsh, "?1004h") {
t.Errorf("Expected focus reporting enable in Zsh hook")
}
if !strings.Contains(zsh, "__ttag_focus_in") {
t.Errorf("Expected focus handlers in Zsh hook")
}
if !strings.Contains(zsh, "zshexit") {
t.Errorf("Expected exit cleanup in Zsh hook")
}
bash := hookSnippet("bash")
if !strings.Contains(bash, "PROMPT_COMMAND") {
t.Errorf("Expected Bash hook")
}
if !strings.Contains(bash, "?1004h") {
t.Errorf("Expected focus reporting enable in Bash hook")
}
if !strings.Contains(bash, "__ttag_focus_in") {
t.Errorf("Expected focus handlers in Bash hook")
}
if !strings.Contains(bash, "__ttag_cleanup") {
t.Errorf("Expected exit cleanup in Bash hook")
}
}