main 5004296

server_test.go RawHistoryFolder

1package server
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/bnema/go-wayland-bindings/spec"
8)
9
10func TestUntypedNewIDEvent(t *testing.T) {
11	p := &spec.Protocol{Interfaces: []spec.Interface{{Name: "test_device", Version: 1, Events: []spec.Message{{Name: "created", Args: []spec.Arg{{Name: "id", Type: "new_id"}}}}}}}
12	b, err := Generate(p, Options{Package: "test"})
13	if err != nil {
14		t.Fatal(err)
15	}
16	s := string(b)
17	if !strings.HasPrefix(s, "// Code generated by wlbgen; DO NOT EDIT.\n") {
18		t.Fatalf("unexpected header:\n%s", s)
19	}
20	if !strings.Contains(s, `Signature: "sun"`) || !strings.Contains(s, `server.String(&p, id.Iface().Name, false), server.Uint(uint32(id.Version())), server.NewID(id)`) {
21		t.Fatalf("untyped new_id event missing wire args:\n%s", s)
22	}
23}
24
25func TestToolHeader(t *testing.T) {
26	p := &spec.Protocol{Interfaces: []spec.Interface{{Name: "test_device", Version: 1}}}
27	b, err := Generate(p, Options{Package: "test", Tool: "wlgen"})
28	if err != nil {
29		t.Fatal(err)
30	}
31	if !strings.HasPrefix(string(b), "// Code generated by wlgen; DO NOT EDIT.\n") {
32		t.Fatalf("unexpected header:\n%s", b)
33	}
34}
35
36func TestUnknownInterface(t *testing.T) {
37	p := &spec.Protocol{Interfaces: []spec.Interface{{Name: "a", Version: 1, Events: []spec.Message{{Name: "e", Args: []spec.Arg{{Name: "o", Type: "object", Interface: "missing"}}}}}}}
38	if _, err := Generate(p, Options{Package: "test"}); err == nil {
39		t.Fatal("expected error for unknown interface")
40	}
41}
42
43func TestSignature(t *testing.T) {
44	cases := []struct {
45		m    spec.Message
46		want string
47	}{
48		{spec.Message{Name: "bind", Args: []spec.Arg{{Type: "uint"}, {Type: "new_id"}}}, "usun"},
49		{spec.Message{Since: 2, Args: []spec.Arg{{Type: "object", AllowNull: true}, {Type: "fd"}, {Type: "fixed"}}}, "2?ohf"},
50		{spec.Message{Args: []spec.Arg{{Type: "new_id", Interface: "wl_surface"}}}, "n"},
51	}
52	for _, c := range cases {
53		if got := signature(c.m); got != c.want {
54			t.Errorf("signature(%+v)=%q, want %q", c.m, got, c.want)
55		}
56	}
57}
58
59func TestLicenseHeader(t *testing.T) {
60	p := &spec.Protocol{Interfaces: []spec.Interface{{Name: "test_device", Version: 1}}}
61	const copyright = "\n  Copyright 2024 Someone\n\n  Permission is hereby granted\n"
62	gen := func(o Options) string {
63		o.Package = "test"
64		b, err := Generate(p, o)
65		if err != nil {
66			t.Fatal(err)
67		}
68		return string(b)
69	}
70
71	got := gen(Options{Copyright: copyright, SPDX: "LGPL-2.1-or-later"})
72	want := "// Code generated by wlbgen; DO NOT EDIT.\n// SPDX-License-Identifier: LGPL-2.1-or-later\n\n" +
73		"// Upstream protocol copyright and license:\n// Copyright 2024 Someone\n//\n// Permission is hereby granted\n\npackage test\n"
74	if !strings.HasPrefix(got, want) {
75		t.Fatalf("header:\n%s\nwant prefix:\n%s", got, want)
76	}
77
78	// An SPDX line already inside the copyright text is not repeated.
79	got = gen(Options{Copyright: "Copyright X\nSPDX-License-Identifier: MIT\n", SPDX: "MIT"})
80	if n := strings.Count(got, "SPDX-License-Identifier: MIT"); n != 1 {
81		t.Fatalf("SPDX line appears %d times:\n%s", n, got)
82	}
83
84	// Copyright without SPDX.
85	got = gen(Options{Copyright: copyright})
86	if strings.Contains(got, "SPDX") || !strings.Contains(got, "// Copyright 2024 Someone\n") {
87		t.Fatalf("unexpected header:\n%s", got)
88	}
89
90	// Neither: the header stays minimal.
91	if got = gen(Options{}); !strings.HasPrefix(got, "// Code generated by wlbgen; DO NOT EDIT.\npackage test\n") {
92		t.Fatalf("unexpected header:\n%s", got)
93	}
94}

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