OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package bytes_test | 5 package bytes_test |
6 | 6 |
7 import ( | 7 import ( |
8 . "bytes"; | 8 . "bytes"; |
9 "rand"; | 9 "rand"; |
10 "testing"; | 10 "testing"; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 check(t, testname+" (empty 1)", buf, s); | 104 check(t, testname+" (empty 1)", buf, s); |
105 | 105 |
106 for { | 106 for { |
107 n, err := buf.Read(fub); | 107 n, err := buf.Read(fub); |
108 if n == 0 { | 108 if n == 0 { |
109 break | 109 break |
110 } | 110 } |
111 if err != nil { | 111 if err != nil { |
112 t.Errorf(testname+" (empty 2): err should always be nil,
found err == %s\n", err) | 112 t.Errorf(testname+" (empty 2): err should always be nil,
found err == %s\n", err) |
113 } | 113 } |
114 » » s = s[n:len(s)]; | 114 » » s = s[n:]; |
115 check(t, testname+" (empty 3)", buf, s); | 115 check(t, testname+" (empty 3)", buf, s); |
116 } | 116 } |
117 | 117 |
118 check(t, testname+" (empty 4)", buf, ""); | 118 check(t, testname+" (empty 4)", buf, ""); |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 func TestBasicOperations(t *testing.T) { | 122 func TestBasicOperations(t *testing.T) { |
123 var buf Buffer; | 123 var buf Buffer; |
124 | 124 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 wlen := rand.Intn(len(data)); | 221 wlen := rand.Intn(len(data)); |
222 if i%2 == 0 { | 222 if i%2 == 0 { |
223 s = fillString(t, "TestMixedReadsAndWrites (1)", &buf, s
, 1, data[0:wlen]) | 223 s = fillString(t, "TestMixedReadsAndWrites (1)", &buf, s
, 1, data[0:wlen]) |
224 } else { | 224 } else { |
225 s = fillBytes(t, "TestMixedReadsAndWrites (1)", &buf, s,
1, bytes[0:wlen]) | 225 s = fillBytes(t, "TestMixedReadsAndWrites (1)", &buf, s,
1, bytes[0:wlen]) |
226 } | 226 } |
227 | 227 |
228 rlen := rand.Intn(len(data)); | 228 rlen := rand.Intn(len(data)); |
229 fub := make([]byte, rlen); | 229 fub := make([]byte, rlen); |
230 n, _ := buf.Read(fub); | 230 n, _ := buf.Read(fub); |
231 » » s = s[n:len(s)]; | 231 » » s = s[n:]; |
232 } | 232 } |
233 empty(t, "TestMixedReadsAndWrites (2)", &buf, s, make([]byte, buf.Len())
); | 233 empty(t, "TestMixedReadsAndWrites (2)", &buf, s, make([]byte, buf.Len())
); |
234 } | 234 } |
235 | 235 |
236 | 236 |
237 func TestNil(t *testing.T) { | 237 func TestNil(t *testing.T) { |
238 var b *Buffer; | 238 var b *Buffer; |
239 if b.String() != "<nil>" { | 239 if b.String() != "<nil>" { |
240 t.Error("expcted <nil>; got %q", b.String()) | 240 t.Error("expcted <nil>; got %q", b.String()) |
241 } | 241 } |
242 } | 242 } |
OLD | NEW |