v0.2.0 c616855

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	} {
45		if _, err := Load(write(t, body), true); err == nil {
46			t.Errorf("%s: want error", name)
47		} else if !strings.Contains(err.Error(), "config") && !strings.Contains(err.Error(), "toml") {
48			t.Errorf("%s: unexpected error %v", name, err)
49		}
50	}
51}
52
53func TestMissingFile(t *testing.T) {
54	p := filepath.Join(t.TempDir(), "none.toml")
55	if _, err := Load(p, false); err != nil {
56		t.Fatalf("default path missing must be fine: %v", err)
57	}
58	if _, err := Load(p, true); err == nil {
59		t.Fatal("explicit path missing must fail")
60	}
61}
62
63func TestAccentDefaultsToBlue(t *testing.T) {
64	c, err := Load(write(t, "[bar]\nsize = 14\n"), true)
65	if err != nil || c.Bar.Accent != 4 {
66		t.Fatalf("accent = %d, err %v; want the default 4", c.Bar.Accent, err)
67	}
68	c, err = Load(write(t, "[bar]\naccent = 2\n"), true)
69	if err != nil || c.Bar.Accent != 2 {
70		t.Fatalf("accent = %d, err %v; want 2", c.Bar.Accent, err)
71	}
72}
73
74func TestPositionDefaultsToTop(t *testing.T) {
75	for config, want := range map[string]string{
76		"[bar]\nsize = 14\n":             "top",
77		"[bar]\nposition = \"top\"\n":    "top",
78		"[bar]\nposition = \"bottom\"\n": "bottom",
79	} {
80		c, err := Load(write(t, config), true)
81		if err != nil || c.Bar.Position != want {
82			t.Errorf("%q: position = %q, err %v; want %q", config, c.Bar.Position, err, want)
83		}
84	}
85}

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