forked from Unity-Technologies/go-ts3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
41 lines (35 loc) · 860 Bytes
/
helpers_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
package ts3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEncodeDecode(t *testing.T) {
str := "\\/ |\a\b\f\n\r\t\v"
assert.Equal(t, `\\\/\s\p\a\b\f\n\r\t\v`, encoder.Replace(str))
assert.Equal(t, str, Decode(encoder.Replace(str)))
}
type testResp struct {
Response string
ID int
Valid bool
}
func TestDecodeResponse(t *testing.T) {
r := &testResp{}
expected := &testResp{
Response: "test",
ID: 1,
Valid: false,
}
assert.NoError(t, DecodeResponse([]string{"response=test id=1 valid"}, r))
assert.Equal(t, expected, r)
input := []string{"line1", "line2"}
assert.EqualError(t,
DecodeResponse(input, r),
NewInvalidResponseError("too many lines", input).Error(),
)
input = []string{}
assert.EqualError(t,
DecodeResponse(input, r),
NewInvalidResponseError("no lines", input).Error(),
)
}