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

Unified Diff: service/rawdatastore/invertible_test.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 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 | « service/rawdatastore/invertible.go ('k') | service/rawdatastore/properties.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/rawdatastore/invertible_test.go
diff --git a/service/rawdatastore/invertible_test.go b/service/rawdatastore/invertible_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..1040f6d13fa30be8018131e3b28f04fe9cdb896c
--- /dev/null
+++ b/service/rawdatastore/invertible_test.go
@@ -0,0 +1,89 @@
+// 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 rawdatastore
+
+import (
+ "bytes"
+ "testing"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestInvertible(t *testing.T) {
+ t.Parallel()
+
+ Convey("Test InvertibleByteBuffer", t, func() {
+ inv := Invertible(&bytes.Buffer{})
+
+ Convey("normal writing", func() {
+ Convey("Write", func() {
+ n, err := inv.Write([]byte("hello"))
+ So(err, ShouldBeNil)
+ So(n, ShouldEqual, 5)
+ So(inv.String(), ShouldEqual, "hello")
+ })
+ Convey("WriteString", func() {
+ n, err := inv.WriteString("hello")
+ So(err, ShouldBeNil)
+ So(n, ShouldEqual, 5)
+ So(inv.String(), ShouldEqual, "hello")
+ })
+ Convey("WriteByte", func() {
+ for i := byte('a'); i < 'f'; i++ {
+ err := inv.WriteByte(i)
+ So(err, ShouldBeNil)
+ }
+ So(inv.String(), ShouldEqual, "abcde")
+
+ Convey("ReadByte", func() {
+ for i := 0; i < 5; i++ {
+ b, err := inv.ReadByte()
+ So(err, ShouldBeNil)
+ So(b, ShouldEqual, byte('a')+byte(i))
+ }
+ })
+ })
+ })
+ Convey("inverted writing", func() {
+ inv.Invert()
+ Convey("Write", func() {
+ n, err := inv.Write([]byte("hello"))
+ So(err, ShouldBeNil)
+ So(n, ShouldEqual, 5)
+ So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\x90")
+ })
+ Convey("WriteString", func() {
+ n, err := inv.WriteString("hello")
+ So(err, ShouldBeNil)
+ So(n, ShouldEqual, 5)
+ So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\x90")
+ })
+ Convey("WriteByte", func() {
+ for i := byte('a'); i < 'f'; i++ {
+ err := inv.WriteByte(i)
+ So(err, ShouldBeNil)
+ }
+ So(inv.String(), ShouldEqual, "\x9e\x9d\x9c\x9b\x9a")
+
+ Convey("ReadByte", func() {
+ for i := 0; i < 5; i++ {
+ b, err := inv.ReadByte()
+ So(err, ShouldBeNil)
+ So(b, ShouldEqual, byte('a')+byte(i)) // inverted back to normal
+ }
+ })
+ })
+ })
+ Convey("Toggleable", func() {
+ inv.Invert()
+ n, err := inv.Write([]byte("hello"))
+ So(err, ShouldBeNil)
+ inv.Invert()
+ n, err = inv.Write([]byte("hello"))
+ So(n, ShouldEqual, 5)
+ So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\x90hello")
+ })
+ })
+}
« no previous file with comments | « service/rawdatastore/invertible.go ('k') | service/rawdatastore/properties.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698