tglistbot/glist/glist_test.go

36 lines
914 B
Go

package glist
import (
"fmt"
"testing"
)
func TestGList(t *testing.T) {
g := NewGList(4342, "foo")
data, err := g.GenSendListReq(NEWLIST)
if err != nil {
t.Fatal(err)
}
expected := `{"chat_id":4342,"text":"List:","disable_notification":true,"reply_markup":{"inline_keyboard":[[{"text":"foo","callback_data":"foo"}],[{"text":"clear checked","callback_data":"clear"}]]}}`
if expected != string(data) {
t.Fatalf("expected: %s\n got:%s\n", expected, string(data))
}
}
func TestSplit(t *testing.T) {
g := &GList{}
//This resets the channel, so test does not try to persist
persistReqC = make(chan *GList, 50)
g.Add("foo")
g.Add("bar\nfoo\nblah")
g.Add("foo")
g.Add("lskfj")
g.Toggle("foo")
expected := `&{0 {0 0} 0 <nil> [{foo true} {bar false} {blah false} {lskfj false}]}`
actual := fmt.Sprintf("%v", g)
if expected != actual {
t.Fatalf("expected: %s\n got:%s\n", expected, actual)
}
}