|
@@ -1,6 +1,7 @@
|
|
|
package ircclient
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"net"
|
|
|
"reflect"
|
|
@@ -10,6 +11,52 @@ import (
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
+func TestMarshal(t *testing.T) {
|
|
|
+ var config IRCConfig = IRCConfig{
|
|
|
+ Port: 6667,
|
|
|
+ Hostname: "irc.red.green.com",
|
|
|
+ UseTLS: false,
|
|
|
+ Nick: "test",
|
|
|
+ Username: "testuser",
|
|
|
+ Realname: "Marshal Test",
|
|
|
+ Password: "12345",
|
|
|
+ AutoJoin: []string{"#test", "#chat"},
|
|
|
+ RejoinDelay: 2000,
|
|
|
+ Version: "Test v3.14",
|
|
|
+ Debug_Output: true,
|
|
|
+ }
|
|
|
+ var buffer []byte
|
|
|
+ var err error
|
|
|
+ buffer, err = json.Marshal(&config)
|
|
|
+ if err != nil {
|
|
|
+ t.Error("json.Marshal:", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ var verify IRCConfig
|
|
|
+ err = json.Unmarshal(buffer, &verify)
|
|
|
+ if err != nil {
|
|
|
+ t.Error("json.Unmarshal:", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ var fields []reflect.StructField
|
|
|
+ fields = reflect.VisibleFields(reflect.TypeOf(config))
|
|
|
+ var config_value reflect.Value = reflect.ValueOf(config)
|
|
|
+ var verify_value reflect.Value = reflect.ValueOf(verify)
|
|
|
+
|
|
|
+ for _, field := range fields {
|
|
|
+ var name string = field.Name
|
|
|
+ var got string
|
|
|
+ var expect string
|
|
|
+
|
|
|
+ got = verify_value.FieldByName(name).String()
|
|
|
+ expect = config_value.FieldByName(name).String()
|
|
|
+
|
|
|
+ if got != expect {
|
|
|
+ t.Errorf("For %s Got %s, Expected %s", name, got, expect)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestParse(t *testing.T) {
|
|
|
var Msg IRCMsg
|
|
|
var Expect map[string]IRCMsg = map[string]IRCMsg{
|