2018-10-09 06:34:34 +02:00
|
|
|
package tgbotapi
|
2015-11-21 11:17:34 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserStringWith(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
user := User{
|
2017-11-09 19:51:50 +01:00
|
|
|
ID: 0,
|
|
|
|
FirstName: "Test",
|
|
|
|
LastName: "Test",
|
|
|
|
UserName: "",
|
|
|
|
LanguageCode: "en",
|
|
|
|
IsBot: false,
|
|
|
|
}
|
2015-11-21 11:17:34 +01:00
|
|
|
|
|
|
|
if user.String() != "Test Test" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserStringWithUserName(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
user := User{
|
2017-11-09 19:51:50 +01:00
|
|
|
ID: 0,
|
|
|
|
FirstName: "Test",
|
|
|
|
LastName: "Test",
|
|
|
|
UserName: "@test",
|
|
|
|
LanguageCode: "en",
|
|
|
|
}
|
2015-11-21 11:17:34 +01:00
|
|
|
|
|
|
|
if user.String() != "@test" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageTime(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Date: 0}
|
2015-11-21 11:17:34 +01:00
|
|
|
|
|
|
|
date := time.Unix(0, 0)
|
|
|
|
if message.Time() != date {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 18:31:59 +01:00
|
|
|
func TestMessageIsCommandWithCommand(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "/command"}
|
|
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
2015-12-13 18:31:59 +01:00
|
|
|
|
2018-03-26 19:39:07 +02:00
|
|
|
if !message.IsCommand() {
|
2015-12-13 18:31:59 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsCommandWithText(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "some text"}
|
2015-12-13 18:31:59 +01:00
|
|
|
|
2018-03-26 19:39:07 +02:00
|
|
|
if message.IsCommand() {
|
2015-12-13 18:31:59 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsCommandWithEmptyText(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: ""}
|
2015-12-13 18:31:59 +01:00
|
|
|
|
2018-03-26 19:39:07 +02:00
|
|
|
if message.IsCommand() {
|
2015-12-13 18:31:59 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandWithCommand(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "/command"}
|
|
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
2015-12-13 18:31:59 +01:00
|
|
|
|
2016-01-04 18:45:46 +01:00
|
|
|
if message.Command() != "command" {
|
2015-12-13 18:31:59 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandWithEmptyText(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: ""}
|
2015-12-13 18:31:59 +01:00
|
|
|
|
|
|
|
if message.Command() != "" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandWithNonCommand(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "test text"}
|
2015-12-13 18:31:59 +01:00
|
|
|
|
|
|
|
if message.Command() != "" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 18:45:46 +01:00
|
|
|
func TestCommandWithBotName(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "/command@testbot"}
|
|
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
2016-01-04 18:45:46 +01:00
|
|
|
|
|
|
|
if message.Command() != "command" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 18:06:20 +02:00
|
|
|
func TestCommandWithAtWithBotName(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "/command@testbot"}
|
|
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
2017-10-07 18:06:20 +02:00
|
|
|
|
|
|
|
if message.CommandWithAt() != "command@testbot" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 18:31:59 +01:00
|
|
|
func TestMessageCommandArgumentsWithArguments(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "/command with arguments"}
|
|
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
2015-12-13 18:31:59 +01:00
|
|
|
if message.CommandArguments() != "with arguments" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 18:06:20 +02:00
|
|
|
func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "/command-without argument space"}
|
|
|
|
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
2017-10-07 18:06:20 +02:00
|
|
|
if message.CommandArguments() != "without argument space" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 18:31:59 +01:00
|
|
|
func TestMessageCommandArgumentsWithoutArguments(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "/command"}
|
2015-12-13 18:31:59 +01:00
|
|
|
if message.CommandArguments() != "" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageCommandArgumentsForNonCommand(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
message := Message{Text: "test text"}
|
2015-12-13 18:31:59 +01:00
|
|
|
if message.CommandArguments() != "" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-14 00:06:18 +02:00
|
|
|
func TestMessageEntityParseURLGood(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
entity := MessageEntity{URL: "https://www.google.com"}
|
2016-04-14 00:06:18 +02:00
|
|
|
|
|
|
|
if _, err := entity.ParseURL(); err != nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityParseURLBad(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
entity := MessageEntity{URL: ""}
|
2016-04-14 00:06:18 +02:00
|
|
|
|
|
|
|
if _, err := entity.ParseURL(); err == nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 11:17:34 +01:00
|
|
|
func TestChatIsPrivate(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
chat := Chat{ID: 10, Type: "private"}
|
2015-11-21 11:17:34 +01:00
|
|
|
|
2018-03-26 19:39:07 +02:00
|
|
|
if !chat.IsPrivate() {
|
2015-11-21 11:17:34 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChatIsGroup(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
chat := Chat{ID: 10, Type: "group"}
|
2015-11-21 11:17:34 +01:00
|
|
|
|
2018-03-26 19:39:07 +02:00
|
|
|
if !chat.IsGroup() {
|
2015-11-21 11:17:34 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChatIsChannel(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
chat := Chat{ID: 10, Type: "channel"}
|
2015-11-21 11:17:34 +01:00
|
|
|
|
2018-03-26 19:39:07 +02:00
|
|
|
if !chat.IsChannel() {
|
2015-11-21 11:17:34 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 03:13:31 +01:00
|
|
|
func TestChatIsSuperGroup(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
chat := Chat{ID: 10, Type: "supergroup"}
|
2015-12-10 03:13:31 +01:00
|
|
|
|
|
|
|
if !chat.IsSuperGroup() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 12:40:12 +01:00
|
|
|
func TestMessageEntityIsMention(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "mention"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsMention() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsHashtag(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "hashtag"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsHashtag() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsBotCommand(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "bot_command"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsCommand() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsUrl(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "url"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
2020-07-21 21:20:12 +02:00
|
|
|
if !entity.IsURL() {
|
2019-01-10 12:40:12 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsEmail(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "email"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsEmail() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsBold(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "bold"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsBold() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsItalic(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "italic"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsItalic() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsCode(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "code"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsCode() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsPre(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "pre"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsPre() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageEntityIsTextLink(t *testing.T) {
|
2020-02-15 14:19:31 +01:00
|
|
|
entity := MessageEntity{Type: "text_link"}
|
2019-01-10 12:40:12 +01:00
|
|
|
|
|
|
|
if !entity.IsTextLink() {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 11:17:34 +01:00
|
|
|
func TestFileLink(t *testing.T) {
|
2018-10-09 06:34:34 +02:00
|
|
|
file := File{FilePath: "test/test.txt"}
|
2015-11-21 11:17:34 +01:00
|
|
|
|
|
|
|
if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
2015-11-21 12:22:08 +01:00
|
|
|
}
|
2018-10-09 01:21:29 +02:00
|
|
|
|
|
|
|
// Ensure all configs are sendable
|
|
|
|
var (
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = AnimationConfig{}
|
|
|
|
_ Chattable = AudioConfig{}
|
|
|
|
_ Chattable = CallbackConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = ChatAdministratorsConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = ChatActionConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = ChatInfoConfig{}
|
|
|
|
_ Chattable = ChatInviteLinkConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = ContactConfig{}
|
|
|
|
_ Chattable = DeleteChatPhotoConfig{}
|
|
|
|
_ Chattable = DeleteChatStickerSetConfig{}
|
|
|
|
_ Chattable = DeleteMessageConfig{}
|
|
|
|
_ Chattable = DocumentConfig{}
|
|
|
|
_ Chattable = EditMessageCaptionConfig{}
|
|
|
|
_ Chattable = EditMessageLiveLocationConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = EditMessageMediaConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = EditMessageReplyMarkupConfig{}
|
|
|
|
_ Chattable = EditMessageTextConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = FileConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = ForwardConfig{}
|
|
|
|
_ Chattable = GameConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = GetChatMemberConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = GetGameHighScoresConfig{}
|
|
|
|
_ Chattable = InlineConfig{}
|
|
|
|
_ Chattable = InvoiceConfig{}
|
|
|
|
_ Chattable = KickChatMemberConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = LeaveChatConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = LocationConfig{}
|
|
|
|
_ Chattable = MediaGroupConfig{}
|
|
|
|
_ Chattable = MessageConfig{}
|
|
|
|
_ Chattable = PhotoConfig{}
|
|
|
|
_ Chattable = PinChatMessageConfig{}
|
2020-11-06 05:29:48 +01:00
|
|
|
_ Chattable = PreCheckoutConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = PromoteChatMemberConfig{}
|
|
|
|
_ Chattable = RemoveWebhookConfig{}
|
|
|
|
_ Chattable = RestrictChatMemberConfig{}
|
|
|
|
_ Chattable = SendPollConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = SetChatDescriptionConfig{}
|
|
|
|
_ Chattable = SetChatPhotoConfig{}
|
|
|
|
_ Chattable = SetChatTitleConfig{}
|
|
|
|
_ Chattable = SetGameScoreConfig{}
|
2020-11-06 05:29:48 +01:00
|
|
|
_ Chattable = ShippingConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = StickerConfig{}
|
2020-01-06 08:44:13 +01:00
|
|
|
_ Chattable = StopPollConfig{}
|
|
|
|
_ Chattable = StopMessageLiveLocationConfig{}
|
|
|
|
_ Chattable = UnbanChatMemberConfig{}
|
2018-10-09 06:34:34 +02:00
|
|
|
_ Chattable = UnpinChatMessageConfig{}
|
|
|
|
_ Chattable = UpdateConfig{}
|
|
|
|
_ Chattable = UserProfilePhotosConfig{}
|
|
|
|
_ Chattable = VenueConfig{}
|
|
|
|
_ Chattable = VideoConfig{}
|
|
|
|
_ Chattable = VideoNoteConfig{}
|
|
|
|
_ Chattable = VoiceConfig{}
|
|
|
|
_ Chattable = WebhookConfig{}
|
2018-10-09 01:21:29 +02:00
|
|
|
)
|