main 602baa7

xerror_test.go RawHistoryFolder

1package xturbo
2
3import (
4	"encoding/binary"
5	"strings"
6	"testing"
7
8	"bnema.dev/xturbo/internal/xtest"
9)
10
11// Error goldens are Xvfb's answers to the capture script's GetAtomName(0x0dadbeef),
12// GetWindowAttributes(base|0x7777) and XFIXES DestroyRegion(base|0x8888). Error
13// codes are the X11 protocol's (BadAtom 5, BadWindow 3) and XFIXES's first error
14// plus BadRegion (0); the generated constants are checked in events_test.go.
15func TestErrorGoldens(t *testing.T) {
16	var ext ExtTable
17	ext.Set(ExtXFixes, 138, 87, 140)
18	for _, tc := range []struct {
19		name             string
20		code, rel, major uint8
21		minor            uint16
22		ext              ExtID
23		bad              uint32
24		badMask          uint32
25	}{
26		{"xproto/BadAtom", 5, 5, 17, 0, ExtCore, 0x0dadbeef, 0xffffffff},
27		{"xproto/BadWindow", 3, 3, 3, 0, ExtCore, 0x7777, 0x1fffff},
28		{"xfixes/BadRegion", 140, 0, 138, 10, ExtXFixes, 0x8888, 0x1fffff},
29	} {
30		raw, err := xtest.LoadHex("testdata/golden/" + tc.name + ".error.hex")
31		if err != nil {
32			t.Fatal(err)
33		}
34		var e XError
35		if !decodeError(raw, &ext, &e) {
36			t.Fatalf("%s: rejected", tc.name)
37		}
38		if e.Code != tc.code || e.Rel != tc.rel || e.Ext != tc.ext || e.Major != tc.major || e.Minor != tc.minor ||
39			e.Bad&tc.badMask != tc.bad || e.Seq != Seq(binary.LittleEndian.Uint16(raw[2:])) || e.Raw != [32]byte(raw) || e.Kind != 0 {
40			t.Fatalf("%s: %+v", tc.name, e)
41		}
42		if !strings.Contains(e.Error(), "X error code") {
43			t.Fatal(e.Error())
44		}
45		// Without a table the extension error stays unresolved.
46		if decodeError(raw, nil, &e); e.Ext != ExtCore || e.Rel != tc.code {
47			t.Fatalf("%s: nil table resolved", tc.name)
48		}
49	}
50	var e XError
51	if decodeError(make([]byte, 31), nil, &e) || decodeError(append([]byte{2}, make([]byte, 31)...), nil, &e) {
52		t.Fatal("non-error packet accepted")
53	}
54}
55
56func TestAllocXError(t *testing.T) {
57	raw, err := xtest.LoadHex("testdata/golden/xfixes/BadRegion.error.hex")
58	if err != nil {
59		t.Fatal(err)
60	}
61	var ext ExtTable
62	ext.Set(ExtXFixes, 138, 87, 140)
63	var e XError
64	if n := testing.AllocsPerRun(1000, func() { decodeError(raw, &ext, &e) }); n != 0 {
65		t.Fatalf("decodeError allocates %v times", n)
66	}
67}

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 1

Tags 1

↑↓ moveenter openesc close