aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'telegram/utils_test.go')
-rw-r--r--telegram/utils_test.go155
1 files changed, 148 insertions, 7 deletions
diff --git a/telegram/utils_test.go b/telegram/utils_test.go
index f0140ae..e54ddb5 100644
--- a/telegram/utils_test.go
+++ b/telegram/utils_test.go
@@ -146,10 +146,13 @@ func TestFormatFile(t *testing.T) {
},
}
- content := c.formatFile(&file, false)
+ content, link := c.formatFile(&file, false)
if content != ". (23 kbytes) | " {
t.Errorf("Wrong file label: %v", content)
}
+ if link != "" {
+ t.Errorf("Wrong file link: %v", link)
+ }
}
func TestFormatPreview(t *testing.T) {
@@ -168,10 +171,13 @@ func TestFormatPreview(t *testing.T) {
},
}
- content := c.formatFile(&file, true)
+ content, link := c.formatFile(&file, true)
if content != "" {
t.Errorf("Wrong preview label: %v", content)
}
+ if link != "" {
+ t.Errorf("Wrong preview link: %v", link)
+ }
}
func TestMessageToTextSticker(t *testing.T) {
@@ -363,6 +369,53 @@ func TestMessageAnimation(t *testing.T) {
}
}
+func TestMessageTtl1(t *testing.T) {
+ ttl := client.Message{
+ Content: &client.MessageChatSetMessageAutoDeleteTime{},
+ }
+ text := (&Client{}).messageToText(&ttl, false)
+ if text != "The self-destruct timer was disabled" {
+ t.Errorf("Wrong anonymous off ttl label: %v", text)
+ }
+}
+
+func TestMessageTtl2(t *testing.T) {
+ ttl := client.Message{
+ Content: &client.MessageChatSetMessageAutoDeleteTime{
+ MessageAutoDeleteTime: 3,
+ },
+ }
+ text := (&Client{}).messageToText(&ttl, false)
+ if text != "The self-destruct timer was set to 3 seconds" {
+ t.Errorf("Wrong anonymous ttl label: %v", text)
+ }
+}
+
+func TestMessageTtl3(t *testing.T) {
+ ttl := client.Message{
+ Content: &client.MessageChatSetMessageAutoDeleteTime{
+ FromUserId: 3,
+ },
+ }
+ text := (&Client{}).messageToText(&ttl, false)
+ if text != "unknown contact: TDlib instance is offline disabled the self-destruct timer" {
+ t.Errorf("Wrong off ttl label: %v", text)
+ }
+}
+
+func TestMessageTtl4(t *testing.T) {
+ ttl := client.Message{
+ Content: &client.MessageChatSetMessageAutoDeleteTime{
+ FromUserId: 3,
+ MessageAutoDeleteTime: 3,
+ },
+ }
+ text := (&Client{}).messageToText(&ttl, false)
+ if text != "unknown contact: TDlib instance is offline set the self-destruct timer to 3 seconds" {
+ t.Errorf("Wrong ttl label: %v", text)
+ }
+}
+
func TestMessageUnknown(t *testing.T) {
unknown := client.Message{
Content: &client.MessageExpiredPhoto{},
@@ -383,10 +436,16 @@ func TestMessageToPrefix1(t *testing.T) {
},
},
}
- prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "", "")
+ prefix, replyStart, replyEnd := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "", "", nil)
if prefix != "➡ 42 | fwd: ziz" {
t.Errorf("Wrong prefix: %v", prefix)
}
+ if replyStart != 0 {
+ t.Errorf("Wrong replyStart: %v", replyStart)
+ }
+ if replyEnd != 0 {
+ t.Errorf("Wrong replyEnd: %v", replyEnd)
+ }
}
func TestMessageToPrefix2(t *testing.T) {
@@ -398,10 +457,16 @@ func TestMessageToPrefix2(t *testing.T) {
},
},
}
- prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "y.jpg", "")
+ prefix, replyStart, replyEnd := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "y.jpg", "", nil)
if prefix != "⬅ 56 | fwd: (zaz) | preview: y.jpg" {
t.Errorf("Wrong prefix: %v", prefix)
}
+ if replyStart != 0 {
+ t.Errorf("Wrong replyStart: %v", replyStart)
+ }
+ if replyEnd != 0 {
+ t.Errorf("Wrong replyEnd: %v", replyEnd)
+ }
}
func TestMessageToPrefix3(t *testing.T) {
@@ -413,10 +478,16 @@ func TestMessageToPrefix3(t *testing.T) {
},
},
}
- prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "a.jpg")
+ prefix, replyStart, replyEnd := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "a.jpg", nil)
if prefix != "< 56 | fwd: (zuz) | file: a.jpg" {
t.Errorf("Wrong prefix: %v", prefix)
}
+ if replyStart != 0 {
+ t.Errorf("Wrong replyStart: %v", replyStart)
+ }
+ if replyEnd != 0 {
+ t.Errorf("Wrong replyEnd: %v", replyEnd)
+ }
}
func TestMessageToPrefix4(t *testing.T) {
@@ -424,10 +495,16 @@ func TestMessageToPrefix4(t *testing.T) {
Id: 23,
IsOutgoing: true,
}
- prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "")
+ prefix, replyStart, replyEnd := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "", nil)
if prefix != "> 23" {
t.Errorf("Wrong prefix: %v", prefix)
}
+ if replyStart != 0 {
+ t.Errorf("Wrong replyStart: %v", replyStart)
+ }
+ if replyEnd != 0 {
+ t.Errorf("Wrong replyEnd: %v", replyEnd)
+ }
}
func TestMessageToPrefix5(t *testing.T) {
@@ -439,8 +516,72 @@ func TestMessageToPrefix5(t *testing.T) {
},
},
}
- prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "h.jpg", "a.jpg")
+ prefix, replyStart, replyEnd := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "h.jpg", "a.jpg", nil)
if prefix != "< 560 | fwd: (zyz) | preview: h.jpg | file: a.jpg" {
t.Errorf("Wrong prefix: %v", prefix)
}
+ if replyStart != 0 {
+ t.Errorf("Wrong replyStart: %v", replyStart)
+ }
+ if replyEnd != 0 {
+ t.Errorf("Wrong replyEnd: %v", replyEnd)
+ }
+}
+
+func TestMessageToPrefix6(t *testing.T) {
+ message := client.Message{
+ Id: 23,
+ IsOutgoing: true,
+ ReplyToMessageId: 42,
+ }
+ reply := client.Message{
+ Id: 42,
+ Content: &client.MessageText{
+ Text: &client.FormattedText{
+ Text: "tist",
+ },
+ },
+ }
+ prefix, replyStart, replyEnd := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "", &reply)
+ if prefix != "> 23 | reply: 42 | | tist" {
+ t.Errorf("Wrong prefix: %v", prefix)
+ }
+ if replyStart != 4 {
+ t.Errorf("Wrong replyStart: %v", replyStart)
+ }
+ if replyEnd != 26 {
+ t.Errorf("Wrong replyEnd: %v", replyEnd)
+ }
+}
+
+func GetSenderIdEmpty(t *testing.T) {
+ message := client.Message{}
+ senderId := (&Client{}).getSenderId(&message)
+ if senderId != 0 {
+ t.Errorf("Wrong sender id: %v", senderId)
+ }
+}
+
+func GetSenderIdUser(t *testing.T) {
+ message := client.Message{
+ SenderId: &client.MessageSenderUser{
+ UserId: 42,
+ },
+ }
+ senderId := (&Client{}).getSenderId(&message)
+ if senderId != 42 {
+ t.Errorf("Wrong sender id: %v", senderId)
+ }
+}
+
+func GetSenderIdChat(t *testing.T) {
+ message := client.Message{
+ SenderId: &client.MessageSenderChat{
+ ChatId: -42,
+ },
+ }
+ senderId := (&Client{}).getSenderId(&message)
+ if senderId != -42 {
+ t.Errorf("Wrong sender id: %v", senderId)
+ }
}