Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Unified Diff: service/datastore/serialize/binary_tools_test.go

Issue 1576353002: Add tests for binary_tools functions (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Fix one more assertion statement Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/serialize/binary_tools_test.go
diff --git a/service/datastore/serialize/binary_tools_test.go b/service/datastore/serialize/binary_tools_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..d10495bf56b9f4b1bd349e7b862b2dd25034a25c
--- /dev/null
+++ b/service/datastore/serialize/binary_tools_test.go
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package serialize
+
+import (
+ "testing"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestBinaryTools(t *testing.T) {
+ t.Parallel()
+
+ Convey("Test Join", t, func() {
+ Convey("returns bytes with nil separator", func() {
+ join := Join([]byte("hello"), []byte("world"))
+ So(join, ShouldResemble, []byte("helloworld"))
+ })
+ })
+
+ Convey("Test Invert", t, func() {
+ Convey("returns nil for nil input", func() {
+ inv := Invert(nil)
+ So(inv, ShouldBeNil)
+ })
+
+ Convey("returns nil for empty input", func() {
+ inv := Invert([]byte{})
+ So(inv, ShouldBeNil)
+ })
+
+ Convey("returns byte slice of same length as input", func() {
+ input := []byte("こんにちは, world")
+ inv := Invert(input)
+ So(len(input), ShouldEqual, len(inv))
+ })
+
+ Convey("returns byte slice with each byte inverted", func() {
+ inv := Invert([]byte("foo"))
+ So(inv, ShouldResemble, []byte{153, 144, 144})
+ })
+ })
+
+ Convey("Test Increment", t, func() {
+ Convey("returns empty slice and overflow true when input is nil", func() {
+ incr, overflow := Increment(nil)
+ So(incr, ShouldBeNil)
+ So(overflow, ShouldBeTrue)
+ })
+
+ Convey("returns empty slice and overflow true when input is empty", func() {
+ incr, overflow := Increment([]byte{})
+ So(incr, ShouldBeNil)
+ So(overflow, ShouldBeTrue)
+ })
+
+ Convey("handles overflow", func() {
+ incr, overflow := Increment([]byte{0xFF, 0xFF})
+ So(incr, ShouldResemble, []byte{0, 0})
+ So(overflow, ShouldBeTrue)
+ })
+
+ Convey("increments with overflow false when there is no overflow", func() {
+ incr, overflow := Increment([]byte{0xCA, 0xFF, 0xFF})
+ So(incr, ShouldResemble, []byte{0xCB, 0, 0})
+ So(overflow, ShouldBeFalse)
+ })
+ })
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698