(t *testing.T)
| 208 | } |
| 209 | |
| 210 | func TestCopyLinesFrom(t *testing.T) { |
| 211 | tests := map[string]struct { |
| 212 | Lines int64 |
| 213 | Offset int64 |
| 214 | }{ |
| 215 | "copyAll": { |
| 216 | Lines: lineBufferSize / 2, |
| 217 | }, |
| 218 | "copyPartial": { |
| 219 | Lines: lineBufferSize / 2, |
| 220 | Offset: lineBufferSize / 4, |
| 221 | }, |
| 222 | "copyLarge": { |
| 223 | Lines: 8 * lineBufferSize, |
| 224 | }, |
| 225 | } |
| 226 | |
| 227 | const lineLength = 128 |
| 228 | |
| 229 | for name, test := range tests { |
| 230 | t.Run(name, func(t *testing.T) { |
| 231 | data := make([]byte, test.Lines*lineLength) |
| 232 | for i := range data { |
| 233 | data[i] = byte(32 + rand.Intn(95)) // ascii letters, numbers, symbols |
| 234 | if i%lineLength == lineLength-1 { |
| 235 | data[i] = '\n' |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | var dst bytes.Buffer |
| 240 | n, err := copyLinesFrom(&dst, &lineReaderAt{r: bytes.NewReader(data)}, test.Offset) |
| 241 | if err != nil { |
| 242 | t.Fatalf("unexpected error copying data: %v", err) |
| 243 | } |
| 244 | if n != test.Lines-test.Offset { |
| 245 | t.Fatalf("incorrect number of lines copied: expected %d, actual %d", test.Lines-test.Offset, n) |
| 246 | } |
| 247 | |
| 248 | expected := data[test.Offset*lineLength:] |
| 249 | if !bytes.Equal(expected, dst.Bytes()) { |
| 250 | t.Fatalf("incorrect data copied:\nexpected: %v\nactual: %v", expected, dst.Bytes()) |
| 251 | } |
| 252 | }) |
| 253 | } |
| 254 | } |
nothing calls this directly
no test coverage detected