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 serialize |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 |
| 10 . "github.com/smartystreets/goconvey/convey" |
| 11 ) |
| 12 |
| 13 func TestBinaryTools(t *testing.T) { |
| 14 t.Parallel() |
| 15 |
| 16 Convey("Test Join", t, func() { |
| 17 Convey("returns bytes with nil separator", func() { |
| 18 join := Join([]byte("hello"), []byte("world")) |
| 19 So(join, ShouldResemble, []byte("helloworld")) |
| 20 }) |
| 21 }) |
| 22 |
| 23 Convey("Test Invert", t, func() { |
| 24 Convey("returns nil for nil input", func() { |
| 25 inv := Invert(nil) |
| 26 So(inv, ShouldBeNil) |
| 27 }) |
| 28 |
| 29 Convey("returns nil for empty input", func() { |
| 30 inv := Invert([]byte{}) |
| 31 So(inv, ShouldBeNil) |
| 32 }) |
| 33 |
| 34 Convey("returns byte slice of same length as input", func() { |
| 35 input := []byte("こんにちは, world") |
| 36 inv := Invert(input) |
| 37 So(len(input), ShouldEqual, len(inv)) |
| 38 }) |
| 39 |
| 40 Convey("returns byte slice with each byte inverted", func() { |
| 41 inv := Invert([]byte("foo")) |
| 42 So(inv, ShouldResemble, []byte{153, 144, 144}) |
| 43 }) |
| 44 }) |
| 45 |
| 46 Convey("Test Increment", t, func() { |
| 47 Convey("returns empty slice and overflow true when input is nil"
, func() { |
| 48 incr, overflow := Increment(nil) |
| 49 So(incr, ShouldBeNil) |
| 50 So(overflow, ShouldBeTrue) |
| 51 }) |
| 52 |
| 53 Convey("returns empty slice and overflow true when input is empt
y", func() { |
| 54 incr, overflow := Increment([]byte{}) |
| 55 So(incr, ShouldBeNil) |
| 56 So(overflow, ShouldBeTrue) |
| 57 }) |
| 58 |
| 59 Convey("handles overflow", func() { |
| 60 incr, overflow := Increment([]byte{0xFF, 0xFF}) |
| 61 So(incr, ShouldResemble, []byte{0, 0}) |
| 62 So(overflow, ShouldBeTrue) |
| 63 }) |
| 64 |
| 65 Convey("increments with overflow false when there is no overflow
", func() { |
| 66 incr, overflow := Increment([]byte{0xCA, 0xFF, 0xFF}) |
| 67 So(incr, ShouldResemble, []byte{0xCB, 0, 0}) |
| 68 So(overflow, ShouldBeFalse) |
| 69 }) |
| 70 }) |
| 71 } |
OLD | NEW |