Resolve develop and master conflicts
This commit is contained in:
commit
b40fac9202
13 changed files with 1927 additions and 1484 deletions
127
types_test.go
127
types_test.go
|
@ -1,14 +1,12 @@
|
|||
package tgbotapi_test
|
||||
package tgbotapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func TestUserStringWith(t *testing.T) {
|
||||
user := tgbotapi.User{
|
||||
user := User{
|
||||
ID: 0,
|
||||
FirstName: "Test",
|
||||
LastName: "Test",
|
||||
|
@ -23,7 +21,7 @@ func TestUserStringWith(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUserStringWithUserName(t *testing.T) {
|
||||
user := tgbotapi.User{
|
||||
user := User{
|
||||
ID: 0,
|
||||
FirstName: "Test",
|
||||
LastName: "Test",
|
||||
|
@ -37,7 +35,7 @@ func TestUserStringWithUserName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMessageTime(t *testing.T) {
|
||||
message := tgbotapi.Message{Date: 0}
|
||||
message := Message{Date: 0}
|
||||
|
||||
date := time.Unix(0, 0)
|
||||
if message.Time() != date {
|
||||
|
@ -46,33 +44,33 @@ func TestMessageTime(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMessageIsCommandWithCommand(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "/command"}
|
||||
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
message := Message{Text: "/command"}
|
||||
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
|
||||
if message.IsCommand() != true {
|
||||
if !message.IsCommand() {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsCommandWithText(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "some text"}
|
||||
message := Message{Text: "some text"}
|
||||
|
||||
if message.IsCommand() != false {
|
||||
if message.IsCommand() {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsCommandWithEmptyText(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: ""}
|
||||
message := Message{Text: ""}
|
||||
|
||||
if message.IsCommand() != false {
|
||||
if message.IsCommand() {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandWithCommand(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "/command"}
|
||||
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
message := Message{Text: "/command"}
|
||||
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
|
||||
if message.Command() != "command" {
|
||||
t.Fail()
|
||||
|
@ -80,7 +78,7 @@ func TestCommandWithCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommandWithEmptyText(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: ""}
|
||||
message := Message{Text: ""}
|
||||
|
||||
if message.Command() != "" {
|
||||
t.Fail()
|
||||
|
@ -88,7 +86,7 @@ func TestCommandWithEmptyText(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommandWithNonCommand(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "test text"}
|
||||
message := Message{Text: "test text"}
|
||||
|
||||
if message.Command() != "" {
|
||||
t.Fail()
|
||||
|
@ -96,8 +94,8 @@ func TestCommandWithNonCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommandWithBotName(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "/command@testbot"}
|
||||
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
||||
message := Message{Text: "/command@testbot"}
|
||||
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
||||
|
||||
if message.Command() != "command" {
|
||||
t.Fail()
|
||||
|
@ -105,8 +103,8 @@ func TestCommandWithBotName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommandWithAtWithBotName(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "/command@testbot"}
|
||||
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
||||
message := Message{Text: "/command@testbot"}
|
||||
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
|
||||
|
||||
if message.CommandWithAt() != "command@testbot" {
|
||||
t.Fail()
|
||||
|
@ -114,37 +112,37 @@ func TestCommandWithAtWithBotName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMessageCommandArgumentsWithArguments(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "/command with arguments"}
|
||||
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
message := Message{Text: "/command with arguments"}
|
||||
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
if message.CommandArguments() != "with arguments" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "/command-without argument space"}
|
||||
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
message := Message{Text: "/command-without argument space"}
|
||||
message.Entities = []MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
|
||||
if message.CommandArguments() != "without argument space" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageCommandArgumentsWithoutArguments(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "/command"}
|
||||
message := Message{Text: "/command"}
|
||||
if message.CommandArguments() != "" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageCommandArgumentsForNonCommand(t *testing.T) {
|
||||
message := tgbotapi.Message{Text: "test text"}
|
||||
message := Message{Text: "test text"}
|
||||
if message.CommandArguments() != "" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageEntityParseURLGood(t *testing.T) {
|
||||
entity := tgbotapi.MessageEntity{URL: "https://www.google.com"}
|
||||
entity := MessageEntity{URL: "https://www.google.com"}
|
||||
|
||||
if _, err := entity.ParseURL(); err != nil {
|
||||
t.Fail()
|
||||
|
@ -152,7 +150,7 @@ func TestMessageEntityParseURLGood(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMessageEntityParseURLBad(t *testing.T) {
|
||||
entity := tgbotapi.MessageEntity{URL: ""}
|
||||
entity := MessageEntity{URL: ""}
|
||||
|
||||
if _, err := entity.ParseURL(); err == nil {
|
||||
t.Fail()
|
||||
|
@ -160,31 +158,31 @@ func TestMessageEntityParseURLBad(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestChatIsPrivate(t *testing.T) {
|
||||
chat := tgbotapi.Chat{ID: 10, Type: "private"}
|
||||
chat := Chat{ID: 10, Type: "private"}
|
||||
|
||||
if chat.IsPrivate() != true {
|
||||
if !chat.IsPrivate() {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatIsGroup(t *testing.T) {
|
||||
chat := tgbotapi.Chat{ID: 10, Type: "group"}
|
||||
chat := Chat{ID: 10, Type: "group"}
|
||||
|
||||
if chat.IsGroup() != true {
|
||||
if !chat.IsGroup() {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatIsChannel(t *testing.T) {
|
||||
chat := tgbotapi.Chat{ID: 10, Type: "channel"}
|
||||
chat := Chat{ID: 10, Type: "channel"}
|
||||
|
||||
if chat.IsChannel() != true {
|
||||
if !chat.IsChannel() {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatIsSuperGroup(t *testing.T) {
|
||||
chat := tgbotapi.Chat{ID: 10, Type: "supergroup"}
|
||||
chat := Chat{ID: 10, Type: "supergroup"}
|
||||
|
||||
if !chat.IsSuperGroup() {
|
||||
t.Fail()
|
||||
|
@ -272,9 +270,64 @@ func TestMessageEntityIsTextLink(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileLink(t *testing.T) {
|
||||
file := tgbotapi.File{FilePath: "test/test.txt"}
|
||||
file := File{FilePath: "test/test.txt"}
|
||||
|
||||
if file.Link("token") != "https://api.telegram.org/file/bottoken/test/test.txt" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure all configs are sendable
|
||||
var (
|
||||
_ Chattable = AnimationConfig{}
|
||||
_ Chattable = AudioConfig{}
|
||||
_ Chattable = CallbackConfig{}
|
||||
_ Chattable = ChatAdministratorsConfig{}
|
||||
_ Chattable = ChatActionConfig{}
|
||||
_ Chattable = ChatInfoConfig{}
|
||||
_ Chattable = ChatInviteLinkConfig{}
|
||||
_ Chattable = ContactConfig{}
|
||||
_ Chattable = DeleteChatPhotoConfig{}
|
||||
_ Chattable = DeleteChatStickerSetConfig{}
|
||||
_ Chattable = DeleteMessageConfig{}
|
||||
_ Chattable = DocumentConfig{}
|
||||
_ Chattable = EditMessageCaptionConfig{}
|
||||
_ Chattable = EditMessageLiveLocationConfig{}
|
||||
_ Chattable = EditMessageMediaConfig{}
|
||||
_ Chattable = EditMessageReplyMarkupConfig{}
|
||||
_ Chattable = EditMessageTextConfig{}
|
||||
_ Chattable = FileConfig{}
|
||||
_ Chattable = ForwardConfig{}
|
||||
_ Chattable = GameConfig{}
|
||||
_ Chattable = GetChatMemberConfig{}
|
||||
_ Chattable = GetGameHighScoresConfig{}
|
||||
_ Chattable = InlineConfig{}
|
||||
_ Chattable = InvoiceConfig{}
|
||||
_ Chattable = KickChatMemberConfig{}
|
||||
_ Chattable = LeaveChatConfig{}
|
||||
_ Chattable = LocationConfig{}
|
||||
_ Chattable = MediaGroupConfig{}
|
||||
_ Chattable = MessageConfig{}
|
||||
_ Chattable = PhotoConfig{}
|
||||
_ Chattable = PinChatMessageConfig{}
|
||||
_ Chattable = PromoteChatMemberConfig{}
|
||||
_ Chattable = RemoveWebhookConfig{}
|
||||
_ Chattable = RestrictChatMemberConfig{}
|
||||
_ Chattable = SendPollConfig{}
|
||||
_ Chattable = SetChatDescriptionConfig{}
|
||||
_ Chattable = SetChatPhotoConfig{}
|
||||
_ Chattable = SetChatTitleConfig{}
|
||||
_ Chattable = SetGameScoreConfig{}
|
||||
_ Chattable = StickerConfig{}
|
||||
_ Chattable = StopPollConfig{}
|
||||
_ Chattable = StopMessageLiveLocationConfig{}
|
||||
_ Chattable = UnbanChatMemberConfig{}
|
||||
_ Chattable = UnpinChatMessageConfig{}
|
||||
_ Chattable = UpdateConfig{}
|
||||
_ Chattable = UserProfilePhotosConfig{}
|
||||
_ Chattable = VenueConfig{}
|
||||
_ Chattable = VideoConfig{}
|
||||
_ Chattable = VideoNoteConfig{}
|
||||
_ Chattable = VoiceConfig{}
|
||||
_ Chattable = WebhookConfig{}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue