main 5004296

options_test.go RawHistoryFolder

1package client
2
3import (
4	"strings"
5	"testing"
6)
7
8const optionsXML = `<protocol name="opt"><copyright>Copyright test
9SPDX-License-Identifier: MIT</copyright><interface name="opt_thing" version="1"/></protocol>`
10
11func generateOptions(t *testing.T, mutate func(*Scanner)) string {
12	t.Helper()
13	s := NewScanner()
14	if err := s.Load([]byte(optionsXML), "opt.xml"); err != nil {
15		t.Fatal(err)
16	}
17	if mutate != nil {
18		mutate(s)
19	}
20	b, err := s.Generate("opt")
21	if err != nil {
22		t.Fatal(err)
23	}
24	return string(b)
25}
26
27func TestToolNameInHeader(t *testing.T) {
28	if got := generateOptions(t, nil); !strings.HasPrefix(got, "// Code generated by wlbgen. DO NOT EDIT.\n") {
29		t.Fatalf("default header: %q", strings.SplitN(got, "\n", 2)[0])
30	}
31	got := generateOptions(t, func(s *Scanner) { s.Tool = "wlturbo-scanner" })
32	if !strings.HasPrefix(got, "// Code generated by wlturbo-scanner. DO NOT EDIT.\n") {
33		t.Fatalf("custom header: %q", strings.SplitN(got, "\n", 2)[0])
34	}
35}
36
37func TestSPDXLineOnlyWhenRequested(t *testing.T) {
38	const line = "// SPDX-License-Identifier: LGPL-2.1-or-later\n"
39	if got := generateOptions(t, nil); strings.Contains(got, line) {
40		t.Fatal("SPDX line emitted without request")
41	}
42	got := generateOptions(t, func(s *Scanner) { s.SPDXLicense = "LGPL-2.1-or-later" })
43	header, _, _ := strings.Cut(got, "\npackage opt")
44	if strings.Count(header, line) != 1 || !strings.Contains(header, "// Copyright test") {
45		t.Fatalf("header: %s", header)
46	}
47}
48
49func TestSPDXNotDuplicatedWhenCopyrightHasIt(t *testing.T) {
50	got := generateOptions(t, func(s *Scanner) { s.SPDXLicense = "MIT" })
51	if n := strings.Count(got, "SPDX-License-Identifier: MIT"); n != 1 {
52		t.Fatalf("SPDX line count = %d", n)
53	}
54}
55
56func TestCoreDetectionFollowsWlDisplay(t *testing.T) {
57	const xml = `<protocol name="x"><interface name="wl_display" version="1"/><interface name="wl_registry" version="1"/><interface name="wl_thing" version="1"/></protocol>`
58	for _, pkg := range []string{"wayland", "core", "anything"} {
59		s := NewScanner()
60		if err := s.Load([]byte(xml), "x.xml"); err != nil {
61			t.Fatal(err)
62		}
63		b, err := s.Generate(pkg)
64		if err != nil {
65			t.Fatal(err)
66		}
67		if strings.Contains(string(b), "type Display struct") || strings.Contains(string(b), "type Registry struct") || !strings.Contains(string(b), "type Thing struct") {
68			t.Fatalf("package %s: bootstrap types not skipped", pkg)
69		}
70	}
71	// A package named "core" that does not define wl_display is not core.
72	s := NewScanner()
73	if err := s.Load([]byte(`<protocol name="x"><interface name="wl_registry" version="1"/></protocol>`), "x.xml"); err != nil {
74		t.Fatal(err)
75	}
76	b, err := s.Generate("core")
77	if err != nil {
78		t.Fatal(err)
79	}
80	if !strings.Contains(string(b), "type Registry struct") {
81		t.Fatal("core name alone must not trigger core handling")
82	}
83}

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