| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package memory | |
| 6 | |
| 7 import ( | |
| 8 "bytes" | |
| 9 "testing" | |
| 10 | |
| 11 . "github.com/smartystreets/goconvey/convey" | |
| 12 ) | |
| 13 | |
| 14 func TestBinutils(t *testing.T) { | |
| 15 t.Parallel() | |
| 16 | |
| 17 Convey("Binary utilities", t, func() { | |
| 18 b := &bytes.Buffer{} | |
| 19 | |
| 20 Convey("bytes", func() { | |
| 21 t := []byte("this is a test") | |
| 22 writeBytes(b, t) | |
| 23 Convey("good", func() { | |
| 24 r, err := readBytes(b) | |
| 25 So(err, ShouldBeNil) | |
| 26 So(r, ShouldResemble, t) | |
| 27 }) | |
| 28 Convey("bad (truncated buffer)", func() { | |
| 29 bs := b.Bytes() | |
| 30 _, err := readBytes(bytes.NewBuffer(bs[:len(bs)-
4])) | |
| 31 So(err.Error(), ShouldContainSubstring, "readByt
es: expected ") | |
| 32 }) | |
| 33 Convey("bad (bad varint)", func() { | |
| 34 _, err := readBytes(bytes.NewBuffer([]byte{0x8f}
)) | |
| 35 So(err.Error(), ShouldContainSubstring, "EOF") | |
| 36 }) | |
| 37 }) | |
| 38 | |
| 39 Convey("strings", func() { | |
| 40 t := "this is a test" | |
| 41 writeString(b, t) | |
| 42 Convey("good", func() { | |
| 43 r, err := readString(b) | |
| 44 So(err, ShouldBeNil) | |
| 45 So(r, ShouldEqual, t) | |
| 46 }) | |
| 47 Convey("bad (truncated buffer)", func() { | |
| 48 bs := b.Bytes() | |
| 49 _, err := readString(bytes.NewBuffer(bs[:len(bs)
-4])) | |
| 50 So(err.Error(), ShouldContainSubstring, "readByt
es: expected ") | |
| 51 }) | |
| 52 }) | |
| 53 }) | |
| 54 } | |
| OLD | NEW |