detached 7a3b92c

config_test.go RawHistoryFolder

1package config
2
3import (
4	"os"
5	"path/filepath"
6	"strings"
7	"testing"
8)
9
10func write(t *testing.T, body string) string {
11	t.Helper()
12	p := filepath.Join(t.TempDir(), "c.toml")
13	if err := os.WriteFile(p, []byte(body), 0o600); err != nil {
14		t.Fatal(err)
15	}
16	return p
17}
18
19func TestLoadDefaultsAndModules(t *testing.T) {
20	c, err := Load(write(t, "[bar]\nsize = 16\n[[module]]\nzone = \"left\"\nexec = \"date\"\n"), true)
21	if err != nil {
22		t.Fatal(err)
23	}
24	if c.Bar.Size != 16 || c.Bar.Scale != 1 || c.Bar.Font == "" {
25		t.Fatalf("defaults not kept: %+v", c.Bar)
26	}
27	if c.Module[0].Name != "module1" {
28		t.Fatalf("module name = %q", c.Module[0].Name)
29	}
30}
31
32func TestLoadErrors(t *testing.T) {
33	for name, body := range map[string]string{
34		"unknown key":       "[bar]\nfnot = 1\n",
35		"bad zone":          "[[module]]\nzone = \"top\"\nexec = \"x\"\n",
36		"no exec":           "[[module]]\nzone = \"left\"\n",
37		"bad size":          "[bar]\nsize = 1\n",
38		"bad scale":         "[bar]\nscale = 20\n",
39		"bad color":         "[bar]\nbackground = \"red\"\n",
40		"position":          "[bar]\nposition = \"middle\"\n",
41		"accent low":        "[bar]\naccent = -1\n",
42		"accent high":       "[bar]\naccent = 16\n",
43		"syntax error":      "[bar\n",
44		"tray icon newline": "[tray.icons]\nsteam = \"a\\nb\"\n",
45	} {
46		if _, err := Load(write(t, body), true); err == nil {
47			t.Errorf("%s: want error", name)
48		} else if !strings.Contains(err.Error(), "config") && !strings.Contains(err.Error(), "toml") {
49			t.Errorf("%s: unexpected error %v", name, err)
50		}
51	}
52}
53
54func TestMissingFile(t *testing.T) {
55	p := filepath.Join(t.TempDir(), "none.toml")
56	if _, err := Load(p, false); err != nil {
57		t.Fatalf("default path missing must be fine: %v", err)
58	}
59	if _, err := Load(p, true); err == nil {
60		t.Fatal("explicit path missing must fail")
61	}
62}
63
64func TestAccentDefaultsToBlue(t *testing.T) {
65	c, err := Load(write(t, "[bar]\nsize = 14\n"), true)
66	if err != nil || c.Bar.Accent != 4 {
67		t.Fatalf("accent = %d, err %v; want the default 4", c.Bar.Accent, err)
68	}
69	c, err = Load(write(t, "[bar]\naccent = 2\n"), true)
70	if err != nil || c.Bar.Accent != 2 {
71		t.Fatalf("accent = %d, err %v; want 2", c.Bar.Accent, err)
72	}
73}
74
75func TestPositionDefaultsToTop(t *testing.T) {
76	for config, want := range map[string]string{
77		"[bar]\nsize = 14\n":             "top",
78		"[bar]\nposition = \"top\"\n":    "top",
79		"[bar]\nposition = \"bottom\"\n": "bottom",
80	} {
81		c, err := Load(write(t, config), true)
82		if err != nil || c.Bar.Position != want {
83			t.Errorf("%q: position = %q, err %v; want %q", config, c.Bar.Position, err, want)
84		}
85	}
86}
87
88func TestInteractiveKey(t *testing.T) {
89	c, err := Load(write(t, "[[module]]\nzone = \"left\"\nexec = \"a\"\ninteractive = true\n[[module]]\nzone = \"left\"\nexec = \"b\"\n"), true)
90	if err != nil {
91		t.Fatal(err)
92	}
93	if !c.Module[0].Interactive || c.Module[1].Interactive {
94		t.Fatalf("interactive = %v, %v; want true, false", c.Module[0].Interactive, c.Module[1].Interactive)
95	}
96}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 5

Tags 4

↑↓ moveenter openesc close