FILE / ScuroNeko/Laniakea

tgrich/input_fmt_test.go

Исходный файл и его история в репозитории.
FILE 24040fe164649c3e4a7ef2f9d37b9747957b0cc1
Files
Laniakea/tgrich/input_fmt_test.go
T
ScuroNeko f03a081ed6
Golang lint / lint (pull_request) Successful in 1m20s
Golang lint / lint (push) Successful in 4m8s
(new): rich message support
(fix): runtime reliability
(tests): regression coverage
(doc): v1.1 release notes
2026-08-12 16:34:44 +03:00

45 lines
1.6 KiB
Go

package tgrich
import (
"testing"
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
)
func TestMediaConstructorsSetTypes(t *testing.T) {
cases := []struct {
name string
blockType tgapi.InputRichType
mediaType tgapi.InputMediaType
}{
{"animation", Animation(tgapi.InputMedia{Media: "animation"}).Type, Animation(tgapi.InputMedia{Media: "animation"}).Animation.Type},
{"audio", Audio(tgapi.InputMedia{Media: "audio"}).Type, Audio(tgapi.InputMedia{Media: "audio"}).Audio.Type},
{"photo", Photo(tgapi.InputMedia{Media: "photo"}).Type, Photo(tgapi.InputMedia{Media: "photo"}).Photo.Type},
{"video", Video(tgapi.InputMedia{Media: "video"}).Type, Video(tgapi.InputMedia{Media: "video"}).Video.Type},
{"voice note", VoiceNote(tgapi.InputMedia{Media: "voice"}).Type, VoiceNote(tgapi.InputMedia{Media: "voice"}).VoiceNote.Type},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
if string(tt.blockType) != string(tt.mediaType) {
t.Errorf("block type = %q, media type = %q", tt.blockType, tt.mediaType)
}
})
}
}
func TestMediaConstructorWithCaption(t *testing.T) {
caption := tgapi.RichBlockCaption{Text: tgapi.RichTextPlain("caption")}
if block := AnimationWithCaption(tgapi.InputMedia{Media: "animation"}, caption); block.Caption == nil || *block.Caption != caption {
t.Fatal("AnimationWithCaption did not preserve the caption")
}
}
func TestOlPreservesCheckboxState(t *testing.T) {
item := NewListItem(P(Text("item"))).SetCheckbox().SetChecked().Build()
list := Ol(OlOpts{}, item)
if len(list.Items) != 1 || !list.Items[0].HasCheckbox || !list.Items[0].IsChecked {
t.Fatalf("Ol() item = %#v", list.Items)
}
}