v0.11.5 c4261b5

util_test.go RawHistoryFolder

1package bot
2
3import (
4	"strings"
5	"testing"
6	"unicode/utf8"
7)
8
9func TestChunkMessageShort(t *testing.T) {
10	got := ChunkMessage("hello", 10)
11	if len(got) != 1 || got[0] != "hello" {
12		t.Fatalf("got %#v", got)
13	}
14}
15
16func TestChunkMessageSplitsOnLines(t *testing.T) {
17	in := strings.Repeat("aaaa\n", 5) + "bbbb"
18	for _, c := range ChunkMessage(in, 10) {
19		if utf8.RuneCountInString(c) > 10 {
20			t.Fatalf("chunk too long: %q", c)
21		}
22	}
23}
24
25func TestChunkMessageHardSplitsLongLine(t *testing.T) {
26	in := strings.Repeat("x", 25)
27	got := ChunkMessage(in, 10)
28	if len(got) != 3 {
29		t.Fatalf("want 3 chunks, got %d: %#v", len(got), got)
30	}
31}
32
33// Ported from telegram/bot_test.go to preserve rune-boundary coverage.
34func TestChunkMessageUsesRuneLimit(t *testing.T) {
35	s := strings.Repeat("界", 4001)
36	chunks := ChunkMessage(s, 4000)
37	if len(chunks) != 2 {
38		t.Fatalf("len(chunks) = %d, want 2", len(chunks))
39	}
40	if got := utf8.RuneCountInString(chunks[0]); got != 4000 {
41		t.Fatalf("first chunk runes = %d, want 4000", got)
42	}
43	if got := utf8.RuneCountInString(chunks[1]); got != 1 {
44		t.Fatalf("second chunk runes = %d, want 1", got)
45	}
46}
47
48func TestChunkMessageDoesNotSplitMultiByteRune(t *testing.T) {
49	chunks := ChunkMessage("🙂🙂🙂", 2)
50	if len(chunks) != 2 {
51		t.Fatalf("len(chunks) = %d, want 2", len(chunks))
52	}
53	if chunks[0] != "🙂🙂" || chunks[1] != "🙂" {
54		t.Fatalf("chunks = %#v", chunks)
55	}
56}
57
58func TestIsImageMIME(t *testing.T) {
59	if !IsImageMIME("image/PNG") || IsImageMIME("application/pdf") {
60		t.Fatal("mime gate wrong")
61	}
62}
63
64func TestGuessImageMIME(t *testing.T) {
65	if GuessImageMIME("a/b.webp") != "image/webp" {
66		t.Fatal("webp")
67	}
68	if GuessImageMIME("photos/file") != "image/jpeg" {
69		t.Fatal("fallback should be jpeg (telegram re-encodes photos)")
70	}
71}

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 477

↑↓ moveenter openesc close