feat/data-dnd e05cb15

frames_test.go RawHistoryFolder

1package headless
2
3import (
4	"context"
5	"testing"
6	"time"
7
8	"github.com/bnema/neferwl/internal/ports"
9	"github.com/stretchr/testify/require"
10)
11
12// runWithFrames runs an output with a frames channel of the given size and
13// returns what it needs to feed scenes and stop it.
14func runWithFrames(t *testing.T, size int) (scenes chan ports.Scene, frames chan ports.OutputFrame, f *frames, stop func()) {
15	t.Helper()
16	scenes = make(chan ports.Scene, 8)
17	frames = make(chan ports.OutputFrame, size)
18	r, rec := recordingRenderer(t, nil)
19	sink, _ := presentedSink(t, 16)
20	ctx, cancel := context.WithCancel(context.Background())
21	done := make(chan error, 1)
22	go func() {
23		done <- Run(ctx, Options{Width: 2, Height: 2, Name: "HEADLESS-1", Presented: sink, Frames: frames,
24			NewRenderer: func(int, int) (ports.Renderer, error) { return r, nil }}, scenes, nil, nil, nil, nil)
25	}()
26	return scenes, frames, rec, func() {
27		cancel()
28		require.NoError(t, <-done)
29	}
30}
31
32// The presentation of an animating scene tells core the next frame is due;
33// the one of a settled scene does not.
34func TestAnimatingSceneSendsFrame(t *testing.T) {
35	scenes, frames, rec, stop := runWithFrames(t, 4)
36	defer stop()
37
38	scenes <- ports.Scene{Seq: 1, OutputWidth: 2, OutputHeight: 2, Animating: true}
39	select {
40	case got := <-frames:
41		require.Equal(t, ports.OutputFrame{Output: "HEADLESS-1"}, got)
42	case <-time.After(3 * time.Second):
43		t.Fatal("no frame for an animating scene")
44	}
45
46	// The scene an animation settles on: drawn, nobody woken.
47	scenes <- ports.Scene{Seq: 2, OutputWidth: 2, OutputHeight: 2}
48	waitFrames(t, rec, 2)
49	// A third scene is drawn after the settled one (the owner handles scenes
50	// in order): had the settled frame woken core, its frame precedes the
51	// third's in the channel.
52	scenes <- ports.Scene{Seq: 3, OutputWidth: 2, OutputHeight: 2}
53	waitFrames(t, rec, 3)
54	require.Empty(t, frames)
55}
56
57// A frames channel core has not read stays full: the owner never waits.
58func TestAnimatingFramesNeverBlock(t *testing.T) {
59	scenes, frames, rec, stop := runWithFrames(t, 1)
60	defer stop()
61	for seq := uint64(1); seq <= 3; seq++ {
62		scenes <- ports.Scene{Seq: seq, OutputWidth: 2, OutputHeight: 2, Animating: true}
63		waitFrames(t, rec, int(seq))
64	}
65	require.Len(t, frames, 1)
66}

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 23

Tags 10

↑↓ moveenter openesc close