feat/focused-dot 6314afc

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		"accent low":   "[bar]\naccent = -1\n",
41		"accent high":  "[bar]\naccent = 16\n",
42		"syntax error": "[bar\n",
43	} {
44		if _, err := Load(write(t, body), true); err == nil {
45			t.Errorf("%s: want error", name)
46		} else if !strings.Contains(err.Error(), "config") && !strings.Contains(err.Error(), "toml") {
47			t.Errorf("%s: unexpected error %v", name, err)
48		}
49	}
50}
51
52func TestMissingFile(t *testing.T) {
53	p := filepath.Join(t.TempDir(), "none.toml")
54	if _, err := Load(p, false); err != nil {
55		t.Fatalf("default path missing must be fine: %v", err)
56	}
57	if _, err := Load(p, true); err == nil {
58		t.Fatal("explicit path missing must fail")
59	}
60}
61
62func TestAccentDefaultsToBlue(t *testing.T) {
63	c, err := Load(write(t, "[bar]\nsize = 14\n"), true)
64	if err != nil || c.Bar.Accent != 4 {
65		t.Fatalf("accent = %d, err %v; want the default 4", c.Bar.Accent, err)
66	}
67	c, err = Load(write(t, "[bar]\naccent = 2\n"), true)
68	if err != nil || c.Bar.Accent != 2 {
69		t.Fatalf("accent = %d, err %v; want 2", c.Bar.Accent, err)
70	}
71}

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