File: encoder_test.go

package info (click to toggle)
golang-github-cupcake-rdb 0.0~git20161107.0.43ba341-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 460 kB
  • sloc: makefile: 4
file content (43 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (3)
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
package rdb_test

import (
	"bytes"
	"encoding/base64"

	"github.com/cupcake/rdb"
	. "gopkg.in/check.v1"
)

type EncoderSuite struct{}

var _ = Suite(&EncoderSuite{})

var stringEncodingTests = []struct {
	str string
	res string
}{
	{"0", "AMAABgAOrc/4DQU/mw=="},
	{"127", "AMB/BgCbWIOxpwH5hw=="},
	{"-128", "AMCABgAPi1rt2llnSg=="},
	{"128", "AMGAAAYAfZfbNeWad/Y="},
	{"-129", "AMF//wYAgY3qqKHVuBM="},
	{"32767", "AMH/fwYA37dfWuKh6bg="},
	{"-32768", "AMEAgAYAI61ux6buJl0="},
	{"-32768", "AMEAgAYAI61ux6buJl0="},
	{"2147483647", "AML///9/BgC6mY0eFXuRMg=="},
	{"-2147483648", "AMIAAACABgBRou++xgC9FA=="},
	{"a", "AAFhBgApE4cbemNBJw=="},
}

func (e *EncoderSuite) TestStringEncoding(c *C) {
	buf := &bytes.Buffer{}
	for _, t := range stringEncodingTests {
		e := rdb.NewEncoder(buf)
		e.EncodeType(rdb.TypeString)
		e.EncodeString([]byte(t.str))
		e.EncodeDumpFooter()
		expected, _ := base64.StdEncoding.DecodeString(t.res)
		c.Assert(buf.Bytes(), DeepEquals, expected, Commentf("%s - expected: %x, actual: %x", t.str, expected, buf.Bytes()))
		buf.Reset()
	}
}