feat/hints a471fa4

scene_same_test.go RawHistoryFolder

1package ports
2
3import (
4	"reflect"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8)
9
10func sameSceneBase() Scene {
11	return Scene{
12		Security:     SecurityState{Generation: 1},
13		Output:       "A",
14		Seq:          1,
15		OutputWidth:  100,
16		OutputHeight: 50,
17		Scale:        1,
18		Background:   "#000000",
19		Border:       Border{Width: 2, Active: "#ffffff", Inactive: "#222222"},
20		Windows:      []SceneWindow{{ID: 1, Rect: Rect{X: 1, W: 10, H: 10}}},
21		Separators:   []Separator{{Rect: Rect{W: 1, H: 10}}},
22		DropHints:    []Rect{{W: 5, H: 5}},
23		Layers:       []SceneLayer{{ID: 9, Rect: Rect{W: 100, H: 5}}},
24		Capture:      &SceneCapture{Shown: 1, Excluded: []WindowID{3}},
25
26		Flash:             &FocusFlash{Rect: Rect{W: 20, H: 10}, Width: 2, Color: "#ff0000", Alpha: 0.6},
27		CaptureIndicators: []CaptureIndicator{{Rect: Rect{W: 4, H: 4}}},
28		HintLabels:        []HintLabel{{Rect: Rect{X: 3, Y: 4}, Text: "fj", Typed: 1}},
29	}
30}
31
32func TestSceneSameAs(t *testing.T) {
33	base := sameSceneBase()
34
35	same := sameSceneBase()
36	same.Seq = 99
37	assert.True(t, base.SameAs(same), "Seq alone must not matter")
38	assert.True(t, Scene{}.SameAs(Scene{Seq: 3}))
39
40	for name, edit := range map[string]func(*Scene){
41		"flash nil":         func(s *Scene) { s.Flash = nil },
42		"flash rect":        func(s *Scene) { s.Flash.Rect.X++ },
43		"flash width":       func(s *Scene) { s.Flash.Width++ },
44		"flash color":       func(s *Scene) { s.Flash.Color = "#ffffff" },
45		"flash alpha":       func(s *Scene) { s.Flash.Alpha = 0.2 },
46		"window rect":       func(s *Scene) { s.Windows[0].Rect.X++ },
47		"window fade":       func(s *Scene) { s.Windows[0].Fade = 0.5 },
48		"window zoom":       func(s *Scene) { s.Windows[0].Zoom = 0.9 },
49		"window count":      func(s *Scene) { s.Windows = nil },
50		"security":          func(s *Scene) { s.Security.Generation++ },
51		"background":        func(s *Scene) { s.Background = "#111111" },
52		"border":            func(s *Scene) { s.Border.Width++ },
53		"output":            func(s *Scene) { s.Output = "B" },
54		"size":              func(s *Scene) { s.OutputWidth++ },
55		"scale":             func(s *Scene) { s.Scale = 2 },
56		"off":               func(s *Scene) { s.Off = true },
57		"clip":              func(s *Scene) { s.WorkspaceClip.W = 1 },
58		"tile inset":        func(s *Scene) { s.TileInset.Bottom = 1 },
59		"dim":               func(s *Scene) { s.Dim = 0.5 },
60		"dim behind":        func(s *Scene) { s.DimBehind = true },
61		"separator":         func(s *Scene) { s.Separators[0].Active = true },
62		"drop hint":         func(s *Scene) { s.DropHints[0].W++ },
63		"layer":             func(s *Scene) { s.Layers[0].Rect.H++ },
64		"indicator":         func(s *Scene) { s.CaptureIndicators[0].Pill = true },
65		"hint style":        func(s *Scene) { s.HintStyle.Size = 24 },
66		"excluded":          func(s *Scene) { s.Capture.Excluded[0] = 4 },
67		"transform":         func(s *Scene) { s.Transform = 1 },
68		"capture shown":     func(s *Scene) { s.Capture.Shown++ },
69		"capture session":   func(s *Scene) { s.Capture.Session++ },
70		"capture workspace": func(s *Scene) { s.Capture.Workspace++ },
71		"capture window":    func(s *Scene) { s.Capture.Window++ },
72		"capture revision":  func(s *Scene) { s.Capture.Revision++ },
73		"capture nil":       func(s *Scene) { s.Capture = nil },
74		"capture scene":     func(s *Scene) { s.CaptureScene = &Scene{} },
75	} {
76		t.Run(name, func(t *testing.T) {
77			o := sameSceneBase()
78			edit(&o)
79			assert.False(t, base.SameAs(o))
80			assert.False(t, o.SameAs(base))
81		})
82	}
83
84	both := sameSceneBase()
85	both.CaptureScene = &Scene{}
86	other := sameSceneBase()
87	other.CaptureScene = &Scene{}
88	assert.False(t, both.SameAs(other), "a capture scene is never the same")
89}
90
91// TestSceneSameAsCoversEveryField fails when Scene gains or loses a field:
92// update Scene.SameAs, then this count.
93func TestSceneSameAsCoversEveryField(t *testing.T) {
94	// 25 with Animating, which SameAs intentionally does not compare: it
95	// only schedules the next frame, it draws nothing.
96	const fields = 25
97	assert.Equal(t, fields, len(reflect.VisibleFields(reflect.TypeOf(Scene{}))),
98		"Scene fields changed: update Scene.SameAs (and TestSceneSameAs), then this count")
99}
100
101// TestSceneCaptureSameAsCoversEveryField fails when SceneCapture gains or
102// loses a field: update Scene.SameAs, then this count.
103func TestSceneCaptureSameAsCoversEveryField(t *testing.T) {
104	const fields = 6
105	assert.Equal(t, fields, len(reflect.VisibleFields(reflect.TypeOf(SceneCapture{}))),
106		"SceneCapture fields changed: update Scene.SameAs (and TestSceneSameAs), then this count")
107}

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 25

Tags 10

↑↓ moveenter openesc close