tglistbot/glist/glist_test.go

36 lines
879 B
Go
Raw Normal View History

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