-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathmain_test.go
More file actions
78 lines (66 loc) · 2 KB
/
main_test.go
File metadata and controls
78 lines (66 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"path/filepath"
"strings"
"testing"
"unicode/utf8"
"github.com/floatpane/matcha/fetcher"
)
func TestSanitizeFilenameTruncatesCJKOnUTF8Boundary(t *testing.T) {
name := strings.Repeat("文", 100) + ".txt"
got := sanitizeFilename(name)
if !utf8.ValidString(got) {
t.Fatalf("sanitizeFilename returned invalid UTF-8: %q", got)
}
if len(got) > 255 {
t.Fatalf("sanitizeFilename returned %d bytes, want at most 255", len(got))
}
if filepath.Ext(got) != ".txt" {
t.Fatalf("sanitizeFilename lost extension: got %q", got)
}
}
func TestSanitizeFilenameTruncatesEmojiOnUTF8Boundary(t *testing.T) {
name := strings.Repeat("🚀", 80) + ".log"
got := sanitizeFilename(name)
if !utf8.ValidString(got) {
t.Fatalf("sanitizeFilename returned invalid UTF-8: %q", got)
}
if len(got) > 255 {
t.Fatalf("sanitizeFilename returned %d bytes, want at most 255", len(got))
}
if filepath.Ext(got) != ".log" {
t.Fatalf("sanitizeFilename lost extension: got %q", got)
}
}
func TestParseGlobalFlagsEnablesLogPanel(t *testing.T) {
args, _, show := parseGlobalFlags([]string{"matcha", "--debug", "--logs", "--version"})
if !show {
t.Fatal("expected log panel flag to be enabled")
}
if got := strings.Join(args, " "); got != "matcha --version" {
t.Fatalf("args = %q, want %q", got, "matcha --version")
}
}
func TestParseGlobalFlagsDoesNotConsumeSubcommandFlags(t *testing.T) {
args, _, show := parseGlobalFlags([]string{"matcha", "send", "--logs"})
if show {
t.Fatal("did not expect log panel flag after subcommand to be consumed")
}
if got := strings.Join(args, " "); got != "matcha send --logs" {
t.Fatalf("args = %q, want %q", got, "matcha send --logs")
}
}
func TestUnreadBadgeCountDeduplicatesOverlappingStores(t *testing.T) {
email := fetcher.Email{UID: 42, AccountID: "acct-a"}
got := unreadBadgeCount(
map[string][]fetcher.Email{
"acct-a": {email},
},
map[string][]fetcher.Email{
folderInbox: {email},
},
)
if got != 1 {
t.Fatalf("unreadBadgeCount() = %d, want 1", got)
}
}