tile_test.go RawHistoryFolder

1package hints
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/require"
7)
8
9func TestTileRegions(t *testing.T) {
10	whole := [][2]int{{3840, 2160}, {1920, 1080}, {2560, 1080}, {2560, 1440}, {1280, 720}}
11	for _, s := range whole {
12		require.Nil(t, tileRegions(s[0], s[1]), "%dx%d", s[0], s[1])
13	}
14	require.Equal(t, []region{{0, 0, 2560, 1440}, {1280, 0, 2560, 1440}, {2560, 0, 2560, 1440},
15		{0, 720, 2560, 1440}, {1280, 720, 2560, 1440}, {2560, 720, 2560, 1440}}, tileRegions(5120, 2160))
16	require.Equal(t, []region{{0, 0, 2560, 1440}, {880, 0, 2560, 1440}}, tileRegions(3440, 1440))
17
18	for _, s := range [][2]int{{5120, 2160}, {3440, 1440}, {5120, 1440}, {7680, 2160}, {3000, 2999}, {1000, 3000}, {5121, 2161}, {6000, 1001}} {
19		w, h := s[0], s[1]
20		rs := tileRegions(w, h)
21		require.NotEmpty(t, rs, "%dx%d", w, h)
22		require.LessOrEqual(t, len(rs), maxRegions)
23		covered := make([]bool, w*h)
24		for _, r := range rs {
25			require.Equal(t, r.h*16, r.w*9, "%dx%d tile %+v is not 16:9", w, h, r)
26			require.GreaterOrEqual(t, r.x, 0)
27			require.GreaterOrEqual(t, r.y, 0)
28			require.LessOrEqual(t, r.x+r.w, w)
29			require.LessOrEqual(t, r.y+r.h, h)
30			for y := r.y; y < r.y+r.h; y++ {
31				for x := r.x; x < r.x+r.w; x++ {
32					covered[y*w+x] = true
33				}
34			}
35		}
36		for i, c := range covered {
37			if !c {
38				t.Fatalf("%dx%d: pixel %d,%d not covered", w, h, i%w, i/w)
39			}
40		}
41	}
42}
43
44func TestTileStartsOverlap(t *testing.T) {
45	for _, l := range []int{2561, 3440, 5120, 7680, 10000} {
46		xs := tileStarts(l, 2560)
47		require.Equal(t, 0, xs[0])
48		require.Equal(t, l-2560, xs[len(xs)-1])
49		for i := 1; i < len(xs); i++ {
50			require.GreaterOrEqual(t, xs[i-1]+2560-xs[i], 256, "length %d", l) // >= 10 %
51		}
52	}
53}
54
55func TestTileRegionsTooMany(t *testing.T) {
56	require.Nil(t, tileRegions(60000, 20000))
57}
58
59func TestDropCutBoxes(t *testing.T) {
60	rs := tileRegions(5120, 2160) // tile 0: x 0..2560, tile 1: x 1280..3840
61	// A button at x 2500..2700 is cut at 2560 by tile 0 and whole in tile 1.
62	cutBox := detection{x1: 2500, y1: 100, x2: 2560, y2: 140, score: 0.6, region: 0}
63	whole := detection{x1: 2500, y1: 100, x2: 2700, y2: 140, score: 0.8, region: 1}
64	require.Equal(t, []detection{whole}, dropCutBoxes([]detection{cutBox, whole}, rs))
65	// Nobody saw it whole: the cut box stays.
66	require.Equal(t, []detection{cutBox}, dropCutBoxes([]detection{cutBox}, rs))
67	// An edge of the frame is not an inner edge.
68	edge := detection{x1: 0, y1: 0, x2: 60, y2: 30, score: 0.6, region: 0}
69	// Region 3 starts at y 720: its box at the frame's left edge is not cut
70	// either, so both stay though they sit in different regions.
71	other := detection{x1: 0, y1: 800, x2: 60, y2: 830, score: 0.5, region: 3}
72	require.Equal(t, []detection{edge, other}, dropCutBoxes([]detection{edge, other}, rs))
73	// No regions: unchanged.
74	require.Equal(t, []detection{cutBox}, dropCutBoxes([]detection{cutBox}, nil))
75}

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