| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package serialize | 5 package serialize |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "testing" | 9 "testing" |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 Convey("ReadByte", func() { | 40 Convey("ReadByte", func() { |
| 41 for i := 0; i < 5; i++ { | 41 for i := 0; i < 5; i++ { |
| 42 b, err := inv.ReadByte() | 42 b, err := inv.ReadByte() |
| 43 So(err, ShouldBeNil) | 43 So(err, ShouldBeNil) |
| 44 So(b, ShouldEqual, byte('a')+byt
e(i)) | 44 So(b, ShouldEqual, byte('a')+byt
e(i)) |
| 45 } | 45 } |
| 46 }) | 46 }) |
| 47 }) | 47 }) |
| 48 }) | 48 }) |
| 49 Convey("inverted writing", func() { | 49 Convey("inverted writing", func() { |
| 50 » » » inv.Invert() | 50 » » » inv.SetInvert(true) |
| 51 Convey("Write", func() { | 51 Convey("Write", func() { |
| 52 n, err := inv.Write([]byte("hello")) | 52 n, err := inv.Write([]byte("hello")) |
| 53 So(err, ShouldBeNil) | 53 So(err, ShouldBeNil) |
| 54 So(n, ShouldEqual, 5) | 54 So(n, ShouldEqual, 5) |
| 55 So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\
x90") | 55 So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\
x90") |
| 56 }) | 56 }) |
| 57 Convey("WriteString", func() { | 57 Convey("WriteString", func() { |
| 58 n, err := inv.WriteString("hello") | 58 n, err := inv.WriteString("hello") |
| 59 So(err, ShouldBeNil) | 59 So(err, ShouldBeNil) |
| 60 So(n, ShouldEqual, 5) | 60 So(n, ShouldEqual, 5) |
| 61 So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\
x90") | 61 So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\
x90") |
| 62 }) | 62 }) |
| 63 Convey("WriteByte", func() { | 63 Convey("WriteByte", func() { |
| 64 for i := byte('a'); i < 'f'; i++ { | 64 for i := byte('a'); i < 'f'; i++ { |
| 65 err := inv.WriteByte(i) | 65 err := inv.WriteByte(i) |
| 66 So(err, ShouldBeNil) | 66 So(err, ShouldBeNil) |
| 67 } | 67 } |
| 68 So(inv.String(), ShouldEqual, "\x9e\x9d\x9c\x9b\
x9a") | 68 So(inv.String(), ShouldEqual, "\x9e\x9d\x9c\x9b\
x9a") |
| 69 | 69 |
| 70 Convey("ReadByte", func() { | 70 Convey("ReadByte", func() { |
| 71 for i := 0; i < 5; i++ { | 71 for i := 0; i < 5; i++ { |
| 72 b, err := inv.ReadByte() | 72 b, err := inv.ReadByte() |
| 73 So(err, ShouldBeNil) | 73 So(err, ShouldBeNil) |
| 74 So(b, ShouldEqual, byte('a')+byt
e(i)) // inverted back to normal | 74 So(b, ShouldEqual, byte('a')+byt
e(i)) // inverted back to normal |
| 75 } | 75 } |
| 76 }) | 76 }) |
| 77 }) | 77 }) |
| 78 }) | 78 }) |
| 79 Convey("Toggleable", func() { | 79 Convey("Toggleable", func() { |
| 80 » » » inv.Invert() | 80 » » » inv.SetInvert(true) |
| 81 n, err := inv.Write([]byte("hello")) | 81 n, err := inv.Write([]byte("hello")) |
| 82 So(err, ShouldBeNil) | 82 So(err, ShouldBeNil) |
| 83 » » » inv.Invert() | 83 » » » inv.SetInvert(false) |
| 84 n, err = inv.Write([]byte("hello")) | 84 n, err = inv.Write([]byte("hello")) |
| 85 So(n, ShouldEqual, 5) | 85 So(n, ShouldEqual, 5) |
| 86 So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\x90hello
") | 86 So(inv.String(), ShouldEqual, "\x97\x9a\x93\x93\x90hello
") |
| 87 }) | 87 }) |
| 88 }) | 88 }) |
| 89 } | 89 } |
| OLD | NEW |