main 602baa7

lists_test.go RawHistoryFolder

1package xturbo_test
2
3import (
4	"bytes"
5	"encoding/binary"
6	"strings"
7	"testing"
8
9	"bnema.dev/xturbo"
10	"bnema.dev/xturbo/internal/xtest"
11	"bnema.dev/xturbo/render"
12	"bnema.dev/xturbo/res"
13	"bnema.dev/xturbo/xproto"
14)
15
16func TestListGoldens(t *testing.T) {
17	for _, name := range []string{"xproto/InternAtom", "xproto/ChangeProperty", "res/QueryClientIds"} {
18		t.Run(name, func(t *testing.T) {
19			want, err := xtest.LoadHex("testdata/golden/" + name + ".req.hex")
20			if err != nil {
21				t.Fatal(err)
22			}
23			b := xturbo.NewBuf(0)
24			switch name {
25			case "xproto/InternAtom":
26				xproto.InternAtom(b, false, "XTURBO_")
27			case "xproto/ChangeProperty":
28				xproto.ChangeProperty(b, xproto.PropModeReplace, xproto.Window(binary.LittleEndian.Uint32(want[4:])), xproto.Atom(binary.LittleEndian.Uint32(want[8:])), xproto.AtomString, 8, 3, []byte("abc"))
29			case "res/QueryClientIds":
30				var ext xturbo.ExtTable
31				ext.Set(xturbo.ExtRes, want[0], 0, 0)
32				b.Ext = &ext
33				res.QueryClientIds(b, []res.ClientIdSpec{{Client: 0, Mask: res.ClientIdMaskClientXID}})
34			}
35			if b.Err() != nil || !bytes.Equal(b.Bytes(), want) {
36				t.Fatalf("err %v got %x want %x", b.Err(), b.Bytes(), want)
37			}
38		})
39	}
40}
41func TestListLengths(t *testing.T) {
42	b := xturbo.NewBuf(0)
43	if xproto.ChangeProperty(b, 0, 1, 1, 1, 16, 2, []byte{1, 2}) != 0 || b.Err() != xturbo.ErrBadLength || b.Len() != 0 {
44		t.Fatal("expression length mismatch")
45	}
46	b = xturbo.NewBuf(0)
47	if xproto.InternAtom(b, false, strings.Repeat("x", 65536)) != 0 || b.Err() != xturbo.ErrBadLength {
48		t.Fatal("derived length truncation")
49	}
50	b = xturbo.NewBuf(0)
51	xproto.SetFontPath(b, []xproto.Str{{NameLen: 3, Name: "abc"}, {NameLen: 1, Name: "d"}})
52	want := []byte{51, 0, 4, 0, 2, 0, 0, 0, 3, 'a', 'b', 'c', 1, 'd', 0, 0}
53	if b.Err() != nil || !bytes.Equal(b.Bytes(), want) {
54		t.Fatalf("variable structs: %x err %v", b.Bytes(), b.Err())
55	}
56	b = xturbo.NewBuf(0)
57	xproto.QueryTextExtents(b, 1, []xproto.Char2b{{Byte1: 0, Byte2: 'a'}})
58	if b.Bytes()[1] != 1 {
59		t.Fatal("implicit list length exprfield")
60	}
61	var ext xturbo.ExtTable
62	ext.Set(xturbo.ExtRender, 140, 0, 0)
63	b = xturbo.NewBuf(0)
64	b.Ext = &ext
65	if render.AddGlyphs(b, 1, 2, []uint32{1}, nil, nil) != 0 || b.Err() != xturbo.ErrBadLength {
66		t.Fatal("shared length must remain explicit")
67	}
68}
69func TestAllocListRequests(t *testing.T) {
70	b := xturbo.NewBuf(0)
71	data := make([]byte, 4096)
72	specs := []res.ClientIdSpec{{Client: 1, Mask: res.ClientIdMaskClientXID}}
73	var ext xturbo.ExtTable
74	ext.Set(xturbo.ExtRes, 141, 0, 0)
75	b.Ext = &ext
76	if n := testing.AllocsPerRun(1000, func() {
77		b.Reset()
78		xproto.InternAtom(b, false, "WM_CLASS")
79		xproto.ChangeProperty(b, 0, 1, 1, 1, 8, 4096, data)
80		res.QueryClientIds(b, specs)
81	}); n != 0 {
82		t.Fatal(n)
83	}
84	if b.Err() != nil {
85		t.Fatal(b.Err())
86	}
87}

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