tglistbot/glist/glist_test.go

37 lines
862 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
"sync"
"testing"
)
func TestGList(t *testing.T) {
var ti int
var m sync.Mutex
g := GList{ti, m, 4342, nil, []Entry{{"foo", true}}}
data, err := g.GenSendListReq()
if err != nil {
t.Fatal(err)
}
2022-12-26 21:48:01 -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) {
g := GList{}
reqs = make(chan *GList, 50)
g.Add("foo")
g.Add("bar\nfoo\nblah")
g.Add("foo")
g.Add("lskfj")
expected := `{0 {0 0} 0 <nil> [{foo false} {bar false} {blah false} {lskfj false}]}`
actual := fmt.Sprintf("%v", g)
if expected != actual {
t.Fatalf("expected: %s\n got:%s\n", expected, actual)
}
}