v0.30.0 eb3068f

diff_formatter_test.go RawHistoryFolder

1package config
2
3import (
4	"testing"
5
6	"github.com/bnema/dumber/internal/application/port"
7)
8
9func TestConfigDiffFormatter_FormatChangesAsDiff(t *testing.T) {
10	f := NewDiffFormatter()
11
12	t.Run("no changes", func(t *testing.T) {
13		got := f.FormatChangesAsDiff(nil)
14		want := noChangesMsg
15		if got != want {
16			t.Errorf("got %q, want %q", got, want)
17		}
18	})
19
20	t.Run("empty slice", func(t *testing.T) {
21		got := f.FormatChangesAsDiff([]port.KeyChange{})
22		want := noChangesMsg
23		if got != want {
24			t.Errorf("got %q, want %q", got, want)
25		}
26	})
27
28	t.Run("added change", func(t *testing.T) {
29		changes := []port.KeyChange{
30			{Type: port.KeyChangeAdded, NewKey: "update.enable", NewValue: "true"},
31		}
32		got := f.FormatChangesAsDiff(changes)
33		want := "Config migration changes:\n\n  + update.enable = true\n"
34		if got != want {
35			t.Errorf("got %q, want %q", got, want)
36		}
37	})
38
39	t.Run("removed change", func(t *testing.T) {
40		changes := []port.KeyChange{
41			{Type: port.KeyChangeRemoved, OldKey: "old.key", OldValue: "42"},
42		}
43		got := f.FormatChangesAsDiff(changes)
44		want := "Config migration changes:\n\n  - old.key = 42 (deprecated)\n"
45		if got != want {
46			t.Errorf("got %q, want %q", got, want)
47		}
48	})
49
50	t.Run("renamed change", func(t *testing.T) {
51		changes := []port.KeyChange{
52			{Type: port.KeyChangeRenamed, OldKey: "old.name", NewKey: "new.name", OldValue: "hello"},
53		}
54		got := f.FormatChangesAsDiff(changes)
55		want := "Config migration changes:\n\n  ~ old.name -> new.name\n    (value: hello)\n"
56		if got != want {
57			t.Errorf("got %q, want %q", got, want)
58		}
59	})
60
61	t.Run("all change types combined", func(t *testing.T) {
62		changes := []port.KeyChange{
63			{Type: port.KeyChangeAdded, NewKey: "feature.flag", NewValue: "false"},
64			{Type: port.KeyChangeRemoved, OldKey: "legacy.opt", OldValue: "1"},
65			{Type: port.KeyChangeRenamed, OldKey: "foo.bar", NewKey: "foo.baz", OldValue: "qux"},
66		}
67		got := f.FormatChangesAsDiff(changes)
68		want := "Config migration changes:\n\n" +
69			"  + feature.flag = false\n" +
70			"  - legacy.opt = 1 (deprecated)\n" +
71			"  ~ foo.bar -> foo.baz\n" +
72			"    (value: qux)\n"
73		if got != want {
74			t.Errorf("got %q, want %q", got, want)
75		}
76	})
77}

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 8

Tags 42

↑↓ moveenter openesc close