turbo-editors/turbo-corepublic Fork 0
v1.0.1
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

profile_test.go · 105 lines · 3.1 KBGo Blame HistoryRaw
🛟 Updated. 28d5985 k33g 14h ago1package profile
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9// goProfile is the identity Turbo Go builds itself with, which is what makes
10// the expectations below the real ones rather than invented.
11func goProfile() Profile {
12 return Profile{Name: "Turbo Go", Slug: "turbo-go", Language: "Go"}
13}
14
15func TestProjectDirIsTheSlugWithADotInFront(t *testing.T) {
16 if got := goProfile().ProjectDir(); got != ".turbo-go" {
17 t.Errorf("ProjectDir() = %q, want %q", got, ".turbo-go")
18 }
19}
20
21func TestTheEnvironmentVariableNamesAreTheOnesTurboGoAlreadyUsed(t *testing.T) {
22 // These three names are not free to change: a user who has set
23 // TURBO_GO_THEME_DIR did so against a released binary.
24 tests := []struct {
25 name string
26 got string
27 want string
28 }{
29 {"user directory", goProfile().DirEnvVar(), "TURBO_GO_DIR"},
30 {"theme directory", goProfile().ThemeDirEnvVar(), "TURBO_GO_THEME_DIR"},
31 {"snippet directory", goProfile().SnippetDirEnvVar(), "TURBO_GO_SNIPPET_DIR"},
32 }
33
34 for _, test := range tests {
35 t.Run(test.name, func(t *testing.T) {
36 if test.got != test.want {
37 t.Errorf("got %q, want %q", test.got, test.want)
38 }
39 })
40 }
41}
42
43func TestUserDirHonoursItsEnvironmentOverride(t *testing.T) {
44 dir := t.TempDir()
45 t.Setenv(goProfile().DirEnvVar(), dir)
46
47 if got := goProfile().UserDir(); got != dir {
48 t.Errorf("UserDir() = %q, want %q", got, dir)
49 }
50}
51
52func TestUserDirFallsBackToTheConfigDirectory(t *testing.T) {
53 t.Setenv(goProfile().DirEnvVar(), "")
54
55 got := goProfile().UserDir()
56 // A system with no configuration directory at all gives "", which is a
57 // state the editor handles rather than an error.
58 if got != "" && filepath.Base(got) != "turbo-go" {
59 t.Errorf("UserDir() = %q, want it to end in turbo-go", got)
60 }
61}
62
63func TestThemeDirSitsUnderTheUserDirectory(t *testing.T) {
64 dir := t.TempDir()
65 t.Setenv(goProfile().DirEnvVar(), dir)
66 t.Setenv(goProfile().ThemeDirEnvVar(), "")
67
68 want := filepath.Join(dir, "themes")
69 if got := goProfile().ThemeDir(); got != want {
70 t.Errorf("ThemeDir() = %q, want %q", got, want)
71 }
72}
73
74func TestTheThemeOverrideNamesTheThemeDirectoryItself(t *testing.T) {
75 // Not the directory above it: a test setting this wants to say exactly
76 // where its theme files are, without having to make a themes/ inside it.
77 dir := t.TempDir()
78 t.Setenv(goProfile().ThemeDirEnvVar(), dir)
79
80 if got := goProfile().ThemeDir(); got != dir {
81 t.Errorf("ThemeDir() = %q, want %q", got, dir)
82 }
83}
84
85func TestThemeDirIsEmptyWhenThereIsNowhereToPutIt(t *testing.T) {
86 t.Setenv(goProfile().ThemeDirEnvVar(), "")
87 t.Setenv(goProfile().DirEnvVar(), "")
88 // UserConfigDir reads these; emptying them is what makes it fail.
89 t.Setenv("XDG_CONFIG_HOME", "")
90 t.Setenv("HOME", "")
91 if os.Getenv("HOME") != "" {
92 t.Skip("this system does not take its configuration directory from HOME")
93 }
94
95 if got := goProfile().ThemeDir(); got != "" {
96 t.Errorf("ThemeDir() = %q, want %q", got, "")
97 }
98}
99
100func TestASlugWithDashesBecomesAnEnvironmentVariableWithUnderscores(t *testing.T) {
101 p := Profile{Slug: "turbo-rust"}
102 if got := p.ThemeDirEnvVar(); got != "TURBO_RUST_THEME_DIR" {
103 t.Errorf("ThemeDirEnvVar() = %q, want %q", got, "TURBO_RUST_THEME_DIR")
104 }
105}