-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_test.go
55 lines (49 loc) · 1.26 KB
/
message_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gonzo
import "testing"
var (
in = []byte("foobar")
out = [][]byte{[]byte("foobar")}
frame1 = []byte("raboof")
frame2 = []byte("")
frame3 = []byte{0x0a, 0xa0}
newMsg = [][]byte{[]byte("foobar"), []byte("raboof"),
[]byte(""), []byte{0x0a, 0xa0}}
newRevMsg = [][]byte{[]byte{0x0a, 0xa0}, []byte(""),
[]byte("raboof"), []byte("foobar")}
)
func TestCreateMessage(t *testing.T) {
x := CreateMessage(in)
for i, v := range x {
if string(v) != string(out[i]) {
t.Errorf("CreateMessage(%v) = %v, want %v", in, x, out)
}
}
}
func TestCreateMessageFromMultiple(t *testing.T) {
x := CreateMessage(in, frame1, frame2, frame3)
for i, v := range x {
if string(v) != string(newMsg[i]) {
t.Errorf("CreateMessage(%v) = %v, want %v", in, x, newMsg)
}
}
}
func TestAppend(t *testing.T) {
origMsg := CreateMessage(in)
x := origMsg.Append(frame1, frame2, frame3)
for i, v := range x {
if string(v) != string(newMsg[i]) {
t.Error("Append(%v) = %v, want %v", origMsg, x, newMsg)
break
}
}
}
func TestPrepend(t *testing.T) {
origMsg := CreateMessage(in)
x := origMsg.Prepend(frame3, frame2, frame1)
for i, v := range x {
if string(v) != string(newRevMsg[i]) {
t.Error("Prepend(%v) = %v, want %v", origMsg, x, newRevMsg)
break
}
}
}