v0.35.2 80d5067

reference_test.go RawHistoryFolder

1package domain
2
3import (
4	"reflect"
5	"strings"
6	"testing"
7)
8
9func TestFindReferences(t *testing.T) {
10	tests := []struct {
11		text             string
12		mentions, closes []int64
13	}{
14		{"abc#3 a_b#3 1#3 ' ##3 #3abc #03 #0", nil, nil},
15		{"(#3) see #3, \"#3\"", []int64{3}, nil},
16		{"fixes #3.", []int64{3}, []int64{3}},
17		{"Fixes: #3", []int64{3}, []int64{3}},
18		{"fixes:#3", []int64{3}, []int64{3}},
19		{"Closes #3", []int64{3}, []int64{3}},
20		{"RESOLVED #3", []int64{3}, []int64{3}},
21		{"fix #3", []int64{3}, []int64{3}},
22		{"prefixes #3", []int64{3}, nil},
23		{"fixes 3 fixes#3", nil, nil},
24		{"fixes #3, #4 and #5", []int64{3, 4, 5}, []int64{3, 4, 5}},
25		{"fixes #3 #4", []int64{3, 4}, []int64{3}},
26		{"#5,#3,#5", []int64{3, 5}, nil},
27		{"#1234567890 #12345678901 !3 owner/repo#3", []int64{1234567890}, nil},
28		{"`fixes #3`\n```\ncloses #4\n```", []int64{3, 4}, []int64{3, 4}},
29		{"close #1 closed #2 fixes #3 fixed #4 resolve #5 resolves #6", []int64{1, 2, 3, 4, 5, 6}, []int64{1, 2, 3, 4, 5, 6}},
30	}
31	for _, tt := range tests {
32		t.Run(tt.text, func(t *testing.T) {
33			if got := FindReferences(tt.text); !reflect.DeepEqual(got, tt.mentions) {
34				t.Errorf("mentions = %v, want %v", got, tt.mentions)
35			}
36			if got := FindClosingReferences(tt.text); !reflect.DeepEqual(got, tt.closes) {
37				t.Errorf("closes = %v, want %v", got, tt.closes)
38			}
39		})
40	}
41}
42
43func TestScanMergeRequest(t *testing.T) {
44	got := ScanMergeRequest("fixes #3", "#2", []string{"closes #4"}, []string{"resolved #5", strings.Repeat(" ", MaxReferenceTextBytes) + "fixes #6"})
45	want := MergeRequestReferences{Mentions: []int64{2, 3, 4, 5}, Closes: []int64{3, 5}}
46	if !reflect.DeepEqual(got, want) {
47		t.Fatalf("got %+v, want %+v", got, want)
48	}
49	for _, scan := range []func(string) MergeRequestReferences{
50		func(s string) MergeRequestReferences { return ScanMergeRequest(s, "", nil, nil) },
51		func(s string) MergeRequestReferences { return ScanMergeRequest("", s, nil, nil) },
52		func(s string) MergeRequestReferences { return ScanMergeRequest("", "", []string{s}, nil) },
53		func(s string) MergeRequestReferences { return ScanMergeRequest("", "", nil, []string{s}) },
54	} {
55		if got := scan(strings.Repeat(" ", MaxReferenceTextBytes) + "#7"); len(got.Mentions) != 0 || len(got.Closes) != 0 {
56			t.Errorf("text beyond limit scanned: %+v", got)
57		}
58	}
59}
60
61func TestScanMergeRequestTruncationDropsPartialToken(t *testing.T) {
62	prefix := strings.Repeat(" ", MaxReferenceTextBytes-len("fixes #123"))
63	got := ScanMergeRequest("", "", nil, []string{prefix + "fixes #12345"})
64	if len(got.Mentions) != 0 || len(got.Closes) != 0 {
65		t.Errorf("split number reported: %+v", got)
66	}
67	// Fully before the limit, followed by a split token.
68	full := "fixes #7 " + strings.Repeat("a", MaxReferenceTextBytes)
69	got = ScanMergeRequest("", "", nil, []string{full})
70	if !reflect.DeepEqual(got, MergeRequestReferences{Mentions: []int64{7}, Closes: []int64{7}}) {
71		t.Errorf("got %+v", got)
72	}
73	// No whitespace at all: nothing scanned.
74	got = ScanMergeRequest("", "", nil, []string{strings.Repeat("a", MaxReferenceTextBytes-3) + " #1" + "2"})
75	if len(got.Mentions) != 0 {
76		t.Errorf("got %+v", got)
77	}
78}

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 2

Tags 45

↑↓ moveenter openesc close