feat/data-dnd e05cb15

outputrouting_test.go RawHistoryFolder

1package app
2
3import (
4	"context"
5	"os"
6	"testing"
7
8	"github.com/bnema/neferwl/internal/ports"
9)
10
11func TestOutputRouting(t *testing.T) {
12	ctx, cancel := context.WithCancel(context.Background())
13	defer cancel()
14	replies := make(chan ports.CaptureDone, 2)
15	set := newOutputSet(ctx, replies)
16	for _, name := range []string{"A", "B"} {
17		set.start(ctx, name, func(ctx context.Context, _ <-chan ports.Scene, _ <-chan *ports.ContentBatch, _ ports.ContentReturn, _ <-chan ports.CursorChange, _ <-chan ports.CaptureRequest, _ <-chan ports.SecurityState, _ ports.OutputInstance) error {
18			<-ctx.Done()
19			return nil
20		})
21		<-set.outs[name].cursor // initial cursor
22	}
23	set.scenes([]ports.Scene{{Output: "A", Seq: 1}, {Output: "B", Seq: 2}})
24	set.scenes([]ports.Scene{{Output: "A", Seq: 3}})
25	if got := <-set.outs["A"].scenes; got.Seq != 3 {
26		t.Fatalf("A scene: %+v", got)
27	}
28	if got := <-set.outs["B"].scenes; got.Seq != 2 {
29		t.Fatalf("B scene: %+v", got)
30	}
31	set.setCursor(ports.CursorChange{Shape: "text"})
32	set.setCursor(ports.CursorChange{Shape: "pointer"})
33	for _, name := range []string{"A", "B"} {
34		if got := <-set.outs[name].cursor; got.Shape != "pointer" {
35			t.Fatalf("%s cursor: %+v", name, got)
36		}
37	}
38	f, err := os.CreateTemp(t.TempDir(), "capture")
39	if err != nil {
40		t.Fatal(err)
41	}
42	set.routeCapture(ports.CaptureRequest{ID: 7, Output: "B", Dst: ports.SHMBuffer{File: f}})
43	if got := <-set.outs["B"].captures; got.ID != 7 {
44		t.Fatalf("B capture: %+v", got)
45	}
46	if err := f.Close(); err != nil {
47		t.Fatal(err)
48	}
49	set.outs["A"].stop()
50	if err := set.finish("A"); err != nil {
51		t.Fatal(err)
52	}
53	set.scenes([]ports.Scene{{Output: "A", Seq: 4}})
54	if _, ok := set.outs["A"]; ok {
55		t.Fatal("removed output retained")
56	}
57	set.routeCapture(ports.CaptureRequest{ID: 8, Output: "A"})
58	if got := <-replies; got.ID != 8 || got.Err == nil {
59		t.Fatalf("removed output capture: %+v", got)
60	}
61	if err := set.wait(); err != nil {
62		t.Fatal(err)
63	}
64}
65
66// The set remembers which outputs scenes turned off, also once they are
67// gone: drm starts an output that reconnects off (Output.StartOff).
68func TestOutputSetRemembersOff(t *testing.T) {
69	set := newOutputSet(context.Background(), nil)
70	set.scenes([]ports.Scene{{Output: "A", Off: true}, {Output: "B"}})
71	if !set.off["A"] || set.off["B"] {
72		t.Fatal(set.off)
73	}
74	set.scenes([]ports.Scene{{Output: "A"}})
75	if len(set.off) != 0 {
76		t.Fatal(set.off)
77	}
78}
79
80func TestOutputRoutingAllocations(t *testing.T) {
81	set := newOutputSet(context.Background(), nil)
82	ctx, cancel := context.WithCancel(context.Background())
83	defer cancel()
84	set.start(ctx, "A", func(ctx context.Context, _ <-chan ports.Scene, _ <-chan *ports.ContentBatch, _ ports.ContentReturn, _ <-chan ports.CursorChange, _ <-chan ports.CaptureRequest, _ <-chan ports.SecurityState, _ ports.OutputInstance) error {
85		<-ctx.Done()
86		return nil
87	})
88	scenes := []ports.Scene{{Output: "A"}}
89	cursor := ports.CursorChange{Shape: "pointer"}
90	capture := ports.CaptureRequest{Output: "A"}
91	if got := testing.AllocsPerRun(100, func() {
92		set.scenes(scenes)
93		set.setCursor(cursor)
94		set.routeCapture(capture)
95		<-set.outs["A"].captures
96	}); got != 0 {
97		t.Fatalf("routing: %g allocations per run, want 0", got)
98	}
99	if err := set.wait(); err != nil {
100		t.Fatal(err)
101	}
102}

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