github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/gnorkle/message/parse_test.gno (about) 1 package message_test 2 3 import ( 4 "testing" 5 6 "gno.land/p/demo/gnorkle/message" 7 ) 8 9 func TestParseFunc(t *testing.T) { 10 tests := []struct { 11 name string 12 input string 13 expFuncType message.FuncType 14 expRemainder string 15 }{ 16 { 17 name: "empty", 18 }, 19 { 20 name: "func only", 21 input: "ingest", 22 expFuncType: message.FuncTypeIngest, 23 }, 24 { 25 name: "func with short remainder", 26 input: "commit,asdf", 27 expFuncType: message.FuncTypeCommit, 28 expRemainder: "asdf", 29 }, 30 { 31 name: "func with long remainder", 32 input: "request,hello,world,goodbye", 33 expFuncType: message.FuncTypeRequest, 34 expRemainder: "hello,world,goodbye", 35 }, 36 } 37 38 for _, tt := range tests { 39 t.Run(tt.name, func(t *testing.T) { 40 funcType, remainder := message.ParseFunc(tt.input) 41 if funcType != tt.expFuncType { 42 t.Errorf("expected func type %s, got %s", tt.expFuncType, funcType) 43 } 44 45 if remainder != tt.expRemainder { 46 t.Errorf("expected remainder of %s, got %s", tt.expRemainder, remainder) 47 } 48 }) 49 } 50 }