v0.4.0 b6be3a8

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		"dim":               func(s *Scene) { s.Dim = 0.5 },
52		"dim behind":        func(s *Scene) { s.DimBehind = true },
53		"separator":         func(s *Scene) { s.Separators[0].Active = true },
54		"drop hint":         func(s *Scene) { s.DropHints[0].W++ },
55		"layer":             func(s *Scene) { s.Layers[0].Rect.H++ },
56		"indicator":         func(s *Scene) { s.CaptureIndicators[0].Pill = true },
57		"excluded":          func(s *Scene) { s.Capture.Excluded[0] = 4 },
58		"transform":         func(s *Scene) { s.Transform = 1 },
59		"capture shown":     func(s *Scene) { s.Capture.Shown++ },
60		"capture session":   func(s *Scene) { s.Capture.Session++ },
61		"capture workspace": func(s *Scene) { s.Capture.Workspace++ },
62		"capture window":    func(s *Scene) { s.Capture.Window++ },
63		"capture revision":  func(s *Scene) { s.Capture.Revision++ },
64		"capture nil":       func(s *Scene) { s.Capture = nil },
65		"capture scene":     func(s *Scene) { s.CaptureScene = &Scene{} },
66	} {
67		t.Run(name, func(t *testing.T) {
68			o := sameSceneBase()
69			edit(&o)
70			assert.False(t, base.SameAs(o))
71			assert.False(t, o.SameAs(base))
72		})
73	}
74
75	both := sameSceneBase()
76	both.CaptureScene = &Scene{}
77	other := sameSceneBase()
78	other.CaptureScene = &Scene{}
79	assert.False(t, both.SameAs(other), "a capture scene is never the same")
80}
81
82// TestSceneSameAsCoversEveryField fails when Scene gains or loses a field:
83// update Scene.SameAs, then this count.
84func TestSceneSameAsCoversEveryField(t *testing.T) {
85	const fields = 20
86	assert.Equal(t, fields, len(reflect.VisibleFields(reflect.TypeOf(Scene{}))),
87		"Scene fields changed: update Scene.SameAs (and TestSceneSameAs), then this count")
88}
89
90// TestSceneCaptureSameAsCoversEveryField fails when SceneCapture gains or
91// loses a field: update Scene.SameAs, then this count.
92func TestSceneCaptureSameAsCoversEveryField(t *testing.T) {
93	const fields = 6
94	assert.Equal(t, fields, len(reflect.VisibleFields(reflect.TypeOf(SceneCapture{}))),
95		"SceneCapture fields changed: update Scene.SameAs (and TestSceneSameAs), then this count")
96}

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