main 3d41bc5

grid_physical_test.go RawHistoryFolder

1package core_test
2
3import (
4	"image"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8	"github.com/stretchr/testify/require"
9
10	"github.com/bnema/nefercap/internal/core"
11	"github.com/bnema/nefercap/internal/ports"
12)
13
14func TestMonitorGridPhysicalUsesTheGivenPixels(t *testing.T) {
15	// An odd 901x601 output mode: the lines are its own thirds, one pixel each.
16	g, err := core.MonitorGridPhysical(901, 601)
17	require.NoError(t, err)
18	assert.Equal(t, gridWant(901, 601, [3]int{300, 450, 600}, [3]int{200, 300, 400}), g)
19
20	same, err := core.MonitorGridPhysical(1920, 1080)
21	require.NoError(t, err)
22	fromScale, err := core.MonitorGrid(1600, 900, 1.2)
23	require.NoError(t, err)
24	assert.Equal(t, fromScale, same, "an exact-fit buffer and mode agree")
25}
26
27func TestMonitorGridPhysicalSpansItsOwnSize(t *testing.T) {
28	g, err := core.MonitorGridPhysical(901, 601)
29	require.NoError(t, err)
30	for i, r := range g {
31		assert.True(t, r.In(image.Rect(0, 0, 901, 601)), "line %d %v", i, r)
32		if i < 3 {
33			assert.Equal(t, image.Rect(r.Min.X, 0, r.Min.X+1, 601), r)
34		} else {
35			assert.Equal(t, image.Rect(0, r.Min.Y, 901, r.Min.Y+1), r)
36		}
37	}
38}
39
40func TestMonitorGridPhysicalValidation(t *testing.T) {
41	const limit = ports.MaxDimension * core.MaxGridScale
42	for name, c := range map[string]struct{ w, h int }{
43		"zero width":      {0, 600},
44		"zero height":     {900, 0},
45		"negative width":  {-1, 600},
46		"negative height": {900, -5},
47		"width too large": {limit + 1, 600},
48		"height too high": {900, limit + 1},
49	} {
50		t.Run(name, func(t *testing.T) {
51			g, err := core.MonitorGridPhysical(c.w, c.h)
52			assert.ErrorIs(t, err, core.ErrInvalidGrid)
53			assert.Equal(t, core.GridLines{}, g)
54		})
55	}
56	// A physical mode may exceed MaxDimension when the scale is above 1.
57	g, err := core.MonitorGridPhysical(limit, limit)
58	require.NoError(t, err)
59	assert.Equal(t, limit, g[3].Dx())
60	_, err = core.MonitorGridPhysical(1, 1)
61	assert.NoError(t, err)
62}
63
64func TestMonitorGridPhysicalAllocations(t *testing.T) {
65	var g core.GridLines
66	n := testing.AllocsPerRun(200, func() {
67		g, _ = core.MonitorGridPhysical(901, 601)
68		_, _ = core.MonitorGridPhysical(0, 601)
69	})
70	assert.Zero(t, n)
71	_ = g
72}
73
74func BenchmarkMonitorGridPhysical(b *testing.B) {
75	b.ReportAllocs()
76	var g core.GridLines
77	for i := 0; b.Loop(); i++ {
78		g, _ = core.MonitorGridPhysical(901+i%3, 601)
79	}
80	_ = g
81}

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 2

Tags 9

↑↓ moveenter openesc close