detached f02b08f

event_test.go RawHistoryFolder

1package wlturbo
2
3import (
4	"bytes"
5	"testing"
6)
7
8func TestEventDecoders(t *testing.T) {
9	tests := []struct {
10		name       string
11		data       []byte
12		offset     int
13		read       func(*Event) any
14		want       any
15		wantOffset int
16	}{
17		{"int32 negative", []byte{0xfe, 0xff, 0xff, 0xff}, 0,
18			func(e *Event) any { return e.Int32() }, int32(-2), 4},
19		{"int32 min", []byte{0, 0, 0, 0x80}, 0,
20			func(e *Event) any { return e.Int32() }, int32(-1 << 31), 4},
21		{"int32 at offset", []byte{9, 9, 9, 9, 7, 0, 0, 0}, 4,
22			func(e *Event) any { return e.Int32() }, int32(7), 8},
23		{"int32 truncated", []byte{1, 2, 3}, 0,
24			func(e *Event) any { return e.Int32() }, int32(0), 0},
25		{"fixed positive", []byte{0x80, 0x01, 0, 0}, 0, // 384/256 = 1.5
26			func(e *Event) any { return e.Fixed() }, Fixed(384), 4},
27		{"fixed negative", []byte{0x00, 0xff, 0xff, 0xff}, 0, // -256/256 = -1
28			func(e *Event) any { return e.Fixed() }, Fixed(-256), 4},
29		{"fixed zero", []byte{0, 0, 0, 0}, 0,
30			func(e *Event) any { return e.Fixed() }, Fixed(0), 4},
31		{"fixed truncated", []byte{1}, 0,
32			func(e *Event) any { return e.Fixed() }, Fixed(0), 0},
33		{"array aligned", []byte{4, 0, 0, 0, 1, 2, 3, 4, 0xee}, 0,
34			func(e *Event) any { return e.Array() }, []byte{1, 2, 3, 4}, 8},
35		{"array padded", []byte{5, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0xee}, 0,
36			func(e *Event) any { return e.Array() }, []byte{1, 2, 3, 4, 5}, 12},
37		{"array zero length", []byte{0, 0, 0, 0, 0xee}, 0,
38			func(e *Event) any { return e.Array() }, []byte(nil), 4},
39		{"array length past end", []byte{9, 0, 0, 0, 1, 2, 3, 4}, 0,
40			func(e *Event) any { return e.Array() }, []byte(nil), 4},
41		{"array truncated header", []byte{4, 0, 0}, 0,
42			func(e *Event) any { return e.Array() }, []byte(nil), 0},
43		{"array at offset", []byte{0xaa, 0xaa, 0xaa, 0xaa, 2, 0, 0, 0, 7, 8, 0, 0}, 4,
44			func(e *Event) any { return e.Array() }, []byte{7, 8}, 12},
45	}
46	for _, tt := range tests {
47		t.Run(tt.name, func(t *testing.T) {
48			e := &Event{data: tt.data, offset: tt.offset}
49			got := tt.read(e)
50			if b, ok := tt.want.([]byte); ok {
51				if !bytes.Equal(got.([]byte), b) || (got.([]byte) == nil) != (b == nil) {
52					t.Fatalf("got %v, want %v", got, b)
53				}
54			} else if got != tt.want {
55				t.Fatalf("got %v (%T), want %v (%T)", got, got, tt.want, tt.want)
56			}
57			if e.offset != tt.wantOffset {
58				t.Fatalf("offset %d, want %d", e.offset, tt.wantOffset)
59			}
60		})
61	}
62
63	t.Run("array is a copy", func(t *testing.T) {
64		data := []byte{4, 0, 0, 0, 1, 2, 3, 4}
65		e := &Event{data: data}
66		got := e.Array()
67		data[4] = 0xff
68		if got[0] != 1 {
69			t.Fatal("Array aliases the receive buffer")
70		}
71	})
72}

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 8

↑↓ moveenter openesc close