package msmsg import ( "reflect" "testing" ) var TheTestObjects = map[string]Message{ "This message is opening this channel.": { Dialect: "dialect", ID: "0", Body: "This message is opening this channel.", }, "": { Dialect: "dialect", ID: "0", }, "": { Dialect: "dialect", ID: "0", ClosesChannel: true, }, "": { Dialect: "dialect", ID: "0", ClosesChannel: true, Parameters: map[string]string{ "ctrl": "shutdown", }, }, "Hello": {Dialect: "dialect", Body: "Hello"}, "this is chatter": { Body: "this is chatter", }, // these are malformed "": {Body: ""}, "Hello": {Body: "Hello"}, "Hello": {Body: "Hello"}, "Hello": {Body: "Hello"}, "Hello": {Body: "Hello"}, } func TestParseMessage(t *testing.T) { for input, wantOutput := range TheTestObjects { gotOutput := ParseMessage(input) if want, got := wantOutput.Dialect, gotOutput.Dialect; want != got { t.Fatalf("error parsing %s: wanted dialect %q; got %q\n", input, want, got) } else if want, got := wantOutput.ID, gotOutput.ID; want != got { t.Fatalf("error parsing %s: wanted ID %q; got %q\n", input, want, got) } else if want, got := wantOutput.Body, gotOutput.Body; want != got { t.Fatalf("error parsing %s: wanted body %q; got %q\n", input, want, got) } else if !reflect.DeepEqual(wantOutput.Parameters, gotOutput.Parameters) { t.Fatalf("error parsing %s: wanted parameters %+v; got %+v\n", input, wantOutput.Parameters, gotOutput.Parameters) } else if want, got := wantOutput.ClosesChannel, gotOutput.ClosesChannel; want != got { t.Fatalf("error parsing %s: wanted ClosesChannel=%v; got %v\n", input, want, got) } } }