feat/data-dnd e05cb15

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		CaptureIndicators: []CaptureIndicator{{Rect: Rect{W: 4, H: 4}}},
27	}
28}
29
30func TestSceneSameAs(t *testing.T) {
31	base := sameSceneBase()
32
33	same := sameSceneBase()
34	same.Seq = 99
35	assert.True(t, base.SameAs(same), "Seq alone must not matter")
36	assert.True(t, Scene{}.SameAs(Scene{Seq: 3}))
37
38	for name, edit := range map[string]func(*Scene){
39		"window rect":       func(s *Scene) { s.Windows[0].Rect.X++ },
40		"window fade":       func(s *Scene) { s.Windows[0].Fade = 0.5 },
41		"window zoom":       func(s *Scene) { s.Windows[0].Zoom = 0.9 },
42		"window count":      func(s *Scene) { s.Windows = nil },
43		"security":          func(s *Scene) { s.Security.Generation++ },
44		"background":        func(s *Scene) { s.Background = "#111111" },
45		"border":            func(s *Scene) { s.Border.Width++ },
46		"output":            func(s *Scene) { s.Output = "B" },
47		"size":              func(s *Scene) { s.OutputWidth++ },
48		"scale":             func(s *Scene) { s.Scale = 2 },
49		"off":               func(s *Scene) { s.Off = true },
50		"clip":              func(s *Scene) { s.WorkspaceClip.W = 1 },
51		"tile inset":        func(s *Scene) { s.TileInset.Bottom = 1 },
52		"dim":               func(s *Scene) { s.Dim = 0.5 },
53		"dim behind":        func(s *Scene) { s.DimBehind = true },
54		"separator":         func(s *Scene) { s.Separators[0].Active = true },
55		"drop hint":         func(s *Scene) { s.DropHints[0].W++ },
56		"layer":             func(s *Scene) { s.Layers[0].Rect.H++ },
57		"indicator":         func(s *Scene) { s.CaptureIndicators[0].Pill = true },
58		"excluded":          func(s *Scene) { s.Capture.Excluded[0] = 4 },
59		"transform":         func(s *Scene) { s.Transform = 1 },
60		"capture shown":     func(s *Scene) { s.Capture.Shown++ },
61		"capture session":   func(s *Scene) { s.Capture.Session++ },
62		"capture workspace": func(s *Scene) { s.Capture.Workspace++ },
63		"capture window":    func(s *Scene) { s.Capture.Window++ },
64		"capture revision":  func(s *Scene) { s.Capture.Revision++ },
65		"capture nil":       func(s *Scene) { s.Capture = nil },
66		"capture scene":     func(s *Scene) { s.CaptureScene = &Scene{} },
67	} {
68		t.Run(name, func(t *testing.T) {
69			o := sameSceneBase()
70			edit(&o)
71			assert.False(t, base.SameAs(o))
72			assert.False(t, o.SameAs(base))
73		})
74	}
75
76	both := sameSceneBase()
77	both.CaptureScene = &Scene{}
78	other := sameSceneBase()
79	other.CaptureScene = &Scene{}
80	assert.False(t, both.SameAs(other), "a capture scene is never the same")
81}
82
83// TestSceneSameAsCoversEveryField fails when Scene gains or loses a field:
84// update Scene.SameAs, then this count.
85func TestSceneSameAsCoversEveryField(t *testing.T) {
86	// 22 with Animating, which SameAs intentionally does not compare: it
87	// only schedules the next frame, it draws nothing.
88	const fields = 22
89	assert.Equal(t, fields, len(reflect.VisibleFields(reflect.TypeOf(Scene{}))),
90		"Scene fields changed: update Scene.SameAs (and TestSceneSameAs), then this count")
91}
92
93// TestSceneCaptureSameAsCoversEveryField fails when SceneCapture gains or
94// loses a field: update Scene.SameAs, then this count.
95func TestSceneCaptureSameAsCoversEveryField(t *testing.T) {
96	const fields = 6
97	assert.Equal(t, fields, len(reflect.VisibleFields(reflect.TypeOf(SceneCapture{}))),
98		"SceneCapture fields changed: update Scene.SameAs (and TestSceneSameAs), then this count")
99}

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 26

Tags 10

↑↓ moveenter openesc close