v0.1.0 7deb448

snapshot_test.go RawHistoryFolder

1package vt
2
3import (
4	"testing"
5
6	"github.com/bnema/vev/pkg/renderer"
7	"github.com/stretchr/testify/require"
8)
9
10func TestHistorySnapshotViewDoesNotSealTailAndCopiesIt(t *testing.T) {
11	history := NewHistory(HistoryConfig{MaxRows: 8, ChunkRows: 2})
12	requireHistoryAppend(t, history, historyRow("AAAA"))
13	requireHistoryAppend(t, history, historyRow("BBBB"))
14	requireHistoryAppend(t, history, historyRow("CCCC"))
15	sealed := history.View().Chunk(0)
16
17	view := history.SnapshotView()
18	if got, want := view.ChunkCount(), 1; got != want {
19		t.Fatalf("sealed chunks = %d, want %d", got, want)
20	}
21	if view.Chunk(0) != sealed {
22		t.Fatal("snapshot copied an immutable sealed chunk")
23	}
24	if got, want := len(history.tail), 1; got != want {
25		t.Fatalf("live tail rows = %d, want %d; snapshot sealed it", got, want)
26	}
27	history.tail[0][0].Rune = 'X'
28	if got, want := rowText(view.Tail().Row(0)), "CCCC"; got != want {
29		t.Fatalf("snapshot tail = %q, want %q", got, want)
30	}
31	if got, want := view.Len(), 3; got != want {
32		t.Fatalf("snapshot rows = %d, want %d", got, want)
33	}
34	if got, want := view.Cells(), 12; got != want {
35		t.Fatalf("snapshot cells = %d, want %d", got, want)
36	}
37
38	tail, err := MarshalHistoryTail(view)
39	require.NoError(t, err)
40	decoded, err := UnmarshalHistory(tail)
41	require.NoError(t, err)
42	require.Equal(t, []string{"CCCC"}, historyViewTexts(decoded))
43}
44
45func TestHistoryFromBlobsNormalizesFullTailBeforeAppend(t *testing.T) {
46	fullTail, err := MarshalHistory(HistoryView{
47		chunks: []*HistoryChunk{{rows: [][]renderer.Cell{historyRow("AAAA"), historyRow("BBBB")}}},
48		rows:   2,
49	})
50	require.NoError(t, err)
51
52	restored, err := HistoryFromBlobs(HistoryConfig{MaxRows: 4, ChunkRows: 2}, nil, fullTail)
53	require.NoError(t, err)
54	requireHistoryAppend(t, restored, historyRow("CCCC"))
55
56	require.Equal(t, []string{"AAAA", "BBBB", "CCCC"}, historyViewTexts(restored.View()))
57	require.Len(t, restored.chunks, 1, "a full restored tail must become sealed")
58	require.Len(t, restored.tail, 1, "the appended row must be the mutable tail")
59}
60
61func TestHistoryFromBlobsRestoresCellAccountingAndEvictsToBothBudgets(t *testing.T) {
62	history := NewHistory(HistoryConfig{MaxRows: 4, MaxCells: 10, ChunkRows: 2})
63	for _, text := range []string{"a", "b", "cc"} {
64		requireHistoryAppend(t, history, historyRow(text))
65	}
66	view := history.SnapshotView()
67	sealed := make([][]byte, view.ChunkCount())
68	for i := range sealed {
69		var err error
70		sealed[i], err = MarshalHistoryChunk(view.Chunk(i))
71		require.NoError(t, err)
72	}
73	tail, err := MarshalHistoryTail(view)
74	require.NoError(t, err)
75
76	restored, err := HistoryFromBlobs(HistoryConfig{MaxRows: 4, MaxCells: 2, ChunkRows: 2}, sealed, tail)
77	require.NoError(t, err)
78	require.Equal(t, []string{"cc"}, historyViewTexts(restored.View()))
79	require.Equal(t, 2, restored.Cells())
80}

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 12

Tags 11

↑↓ moveenter openesc close