aboutsummaryrefslogtreecommitdiffstats
path: root/utils/binary/writer_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-10-31 14:56:38 +0000
committerGitHub <noreply@github.com>2016-10-31 14:56:38 +0000
commit659386309f36c482ddc0bb9e854ebda3da216491 (patch)
treeeb156bfbfad599f3dd88e184a7f690f67c64337d /utils/binary/writer_test.go
parent5944d8a185ff1f91e0e108dab1d756fd88692c3b (diff)
downloadgo-git-659386309f36c482ddc0bb9e854ebda3da216491.tar.gz
utils: binary, new package that collect all the spare helper functions about binary operations (#102)
Diffstat (limited to 'utils/binary/writer_test.go')
-rw-r--r--utils/binary/writer_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/utils/binary/writer_test.go b/utils/binary/writer_test.go
new file mode 100644
index 0000000..88140a1
--- /dev/null
+++ b/utils/binary/writer_test.go
@@ -0,0 +1,43 @@
+package binary
+
+import (
+ "bytes"
+ "encoding/binary"
+
+ . "gopkg.in/check.v1"
+)
+
+func (s *BinarySuite) TestWrite(c *C) {
+ expected := bytes.NewBuffer(nil)
+ err := binary.Write(expected, binary.BigEndian, int64(42))
+ c.Assert(err, IsNil)
+ err = binary.Write(expected, binary.BigEndian, int32(42))
+ c.Assert(err, IsNil)
+
+ buf := bytes.NewBuffer(nil)
+ err = Write(buf, int64(42), int32(42))
+ c.Assert(err, IsNil)
+ c.Assert(buf, DeepEquals, expected)
+}
+
+func (s *BinarySuite) TestWriteUint32(c *C) {
+ expected := bytes.NewBuffer(nil)
+ err := binary.Write(expected, binary.BigEndian, int32(42))
+ c.Assert(err, IsNil)
+
+ buf := bytes.NewBuffer(nil)
+ err = WriteUint32(buf, 42)
+ c.Assert(err, IsNil)
+ c.Assert(buf, DeepEquals, expected)
+}
+
+func (s *BinarySuite) TestWriteUint16(c *C) {
+ expected := bytes.NewBuffer(nil)
+ err := binary.Write(expected, binary.BigEndian, int16(42))
+ c.Assert(err, IsNil)
+
+ buf := bytes.NewBuffer(nil)
+ err = WriteUint16(buf, 42)
+ c.Assert(err, IsNil)
+ c.Assert(buf, DeepEquals, expected)
+}