parse_test.gno
0.96 Kb ยท 47 lines
1package message_test
2
3import (
4 "testing"
5
6 "gno.land/p/demo/gnorkle/message"
7 "gno.land/p/demo/uassert"
8)
9
10func TestParseFunc(t *testing.T) {
11 tests := []struct {
12 name string
13 input string
14 expFuncType message.FuncType
15 expRemainder string
16 }{
17 {
18 name: "empty",
19 },
20 {
21 name: "func only",
22 input: "ingest",
23 expFuncType: message.FuncTypeIngest,
24 },
25 {
26 name: "func with short remainder",
27 input: "commit,asdf",
28 expFuncType: message.FuncTypeCommit,
29 expRemainder: "asdf",
30 },
31 {
32 name: "func with long remainder",
33 input: "request,hello,world,goodbye",
34 expFuncType: message.FuncTypeRequest,
35 expRemainder: "hello,world,goodbye",
36 },
37 }
38
39 for _, tt := range tests {
40 t.Run(tt.name, func(t *testing.T) {
41 funcType, remainder := message.ParseFunc(tt.input)
42
43 uassert.Equal(t, string(tt.expFuncType), string(funcType))
44 uassert.Equal(t, tt.expRemainder, remainder)
45 })
46 }
47}