From fce8723af0aa93f36eace87da4645dab373ac5d7 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Tue, 6 Dec 2011 00:21:57 +0000 Subject: [PATCH] Basic copy test, to verify expected behaviour. --- client/line_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 client/line_test.go diff --git a/client/line_test.go b/client/line_test.go new file mode 100644 index 0000000..582d83a --- /dev/null +++ b/client/line_test.go @@ -0,0 +1,42 @@ +package client + +import ( + "testing" +) + +func TestCopy(t *testing.T) { + l1 := &Line{ + Nick: "nick", + Ident: "ident", + Host: "host", + Src: "src", + Cmd: "cmd", + Raw: "raw", + Args: []string{"arg", "text"}, + Time: nil, + } + + l2 := l1.Copy() + + // Ugly. Couldn't be bothered to bust out reflect and actually think. + if l2.Nick != "nick" || l2.Ident != "ident" || l2.Host != "host" || + l2.Src != "src" || l2.Cmd != "cmd" || l2.Raw != "raw" || + l2.Args[0] != "arg" || l2.Args[1] != "text" { + t.Errorf("Line not copied correctly") + t.Errorf("l1: %#v\nl2: %#v", l1, l2) + } + + // Now, modify l2 and verify l1 not changed + l2.Nick = l2.Nick[1:] + l2.Ident = "foo" + l2.Host = "" + l2.Args[0] = l2.Args[0][1:] + l2.Args[1] = "bar" + + if l1.Nick != "nick" || l1.Ident != "ident" || l1.Host != "host" || + l1.Src != "src" || l1.Cmd != "cmd" || l1.Raw != "raw" || + l1.Args[0] != "arg" || l1.Args[1] != "text" { + t.Errorf("Original modified when copy changed") + t.Errorf("l1: %#v\nl2: %#v", l1, l2) + } +}