-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths_test.go
More file actions
128 lines (112 loc) · 4.22 KB
/
Copy pathpaths_test.go
File metadata and controls
128 lines (112 loc) · 4.22 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
package contexting
import (
"path/filepath"
"runtime"
"testing"
)
func testAbsolutePath(parts ...string) string {
root := string(filepath.Separator)
if runtime.GOOS == "windows" {
root = `C:\`
}
return filepath.Join(append([]string{root}, parts...)...)
}
func TestResolveConfigPath_EmptyPath(t *testing.T) {
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), "")
if got != "" {
t.Errorf("empty path should return empty, got %q", got)
}
}
func TestResolveConfigPath_AbsolutePath(t *testing.T) {
target := testAbsolutePath("abs", "path")
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), target)
if got != target {
t.Errorf("absolute path should return as-is, got %q", got)
}
}
func TestResolveConfigPath_EmptyConfigFile(t *testing.T) {
got := resolveConfigPath("", "some/path")
if got != "some/path" {
t.Errorf("empty configFile should return path as-is, got %q", got)
}
}
func TestResolveConfigPath_ConfigNotInDotCtx(t *testing.T) {
got := resolveConfigPath(testAbsolutePath("root", "config.toml"), "sub/path")
want := filepath.Join(testAbsolutePath("root"), "sub/path")
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}
func TestResolveConfigPath_ConfigInDotCtx_NoPrefix(t *testing.T) {
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), "sub/path")
want := filepath.Join(testAbsolutePath("root", ".ctxt"), "sub/path")
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}
func TestResolveConfigPath_ConfigInDotCtx_UnixPrefix(t *testing.T) {
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), ".ctxt/sub/path")
want := filepath.Join(testAbsolutePath("root", ".ctxt"), "sub/path")
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}
func TestResolveConfigPath_ConfigInDotCtx_BackslashPrefix(t *testing.T) {
// Backslash paths should work on all platforms, not just Windows.
// On Unix, filepath.Clean preserves \ as literals, so we must normalize first.
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), ".ctxt\\sub\\path")
want := filepath.Join(testAbsolutePath("root", ".ctxt"), "sub/path")
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}
func TestResolveConfigPath_ConfigInDotCtx_JustDotCtx(t *testing.T) {
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), ".ctxt")
want := testAbsolutePath("root", ".ctxt")
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}
func TestResolveConfigPath_ConfigInDotCtx_NestedDotCtx(t *testing.T) {
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), ".ctxt/.ctxt/sub/path")
want := filepath.Join(testAbsolutePath("root", ".ctxt"), ".ctxt/sub/path")
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}
func TestResolveConfigPath_ConfigInDotCtx_MixedSeparators(t *testing.T) {
// Path containing both / and \ separators — must work on all platforms.
// Use a literal string with both separators: .ctxt\sub/path
// After normalization, .ctxt prefix is stripped, yielding sub/path joined with config dir.
got := resolveConfigPath(testAbsolutePath("root", ".ctxt", "config.toml"), ".ctxt\\sub/path")
want := filepath.Join(testAbsolutePath("root", ".ctxt"), "sub/path")
if got != want {
t.Errorf("resolveConfigPath(.ctxt\\\\sub/path) = %q, want %q", got, want)
}
}
func TestResolveProjectPath_EmptyPath(t *testing.T) {
got := resolveProjectPath(testAbsolutePath("root"), "")
if got != "" {
t.Errorf("empty path should return empty, got %q", got)
}
}
func TestResolveProjectPath_AbsolutePath(t *testing.T) {
target := testAbsolutePath("abs", "path")
got := resolveProjectPath(testAbsolutePath("root"), target)
if got != target {
t.Errorf("absolute path should return as-is, got %q", got)
}
}
func TestResolveProjectPath_EmptyProjectRoot(t *testing.T) {
got := resolveProjectPath("", "sub/path")
if got != "sub/path" {
t.Errorf("empty projectRoot should return path as-is, got %q", got)
}
}
func TestResolveProjectPath_RelativePath(t *testing.T) {
got := resolveProjectPath(testAbsolutePath("root"), "sub/path")
want := filepath.Join(testAbsolutePath("root"), "sub/path")
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}