-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil_test.go
72 lines (63 loc) · 1.46 KB
/
util_test.go
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
package main
import (
tb "github.com/go-telegram-bot-api/telegram-bot-api"
"testing"
)
func TestChatTitle(t *testing.T) {
var cases = []struct {
title string
firstName string
lastName string
expected string
}{
{"Grupo uno", "", "", "Grupo uno"},
{"Grupo dos", "Grupo", "last", "Grupo dos"},
{"", "Felipe", "Perez", "Felipe Perez"},
{"", "Felipe", "", "Felipe"},
{"", "", "Perez", "Perez"},
{"", "", "", ""},
}
for _, data := range cases {
msg := tb.Message{
Chat: &tb.Chat{
Title: data.title,
FirstName: data.firstName,
LastName: data.lastName,
},
}
title := getChatTitle(&msg)
if title != data.expected {
t.Fail()
t.Logf("Expected: %#v, got %#v from %+v", data.expected, title, data)
}
}
}
func TestSenderName(t *testing.T) {
var cases = []struct {
username string
firstName string
lastName string
expected string
}{
{"guad", "", "", "guad"},
{"guad", "Felipe", "Perez", "Felipe Perez (guad)"},
{"", "Felipe", "Perez", "Felipe Perez"},
{"", "Felipe", "", "Felipe"},
{"", "", "Perez", "Perez"},
{"", "", "", ""},
{"guad", "Felipe", "", "Felipe (guad)"},
{"guad", "", "Perez", "Perez (guad)"},
}
for _, data := range cases {
user := tb.User{
UserName: data.username,
FirstName: data.firstName,
LastName: data.lastName,
}
name := getSenderName(&user)
if name != data.expected {
t.Fail()
t.Logf("Expected: %#v, got %#v from %+v", data.expected, name, data)
}
}
}