| 10 | ) |
| 11 | |
| 12 | func TestSplit(t *testing.T) { |
| 13 | f, err := os.Open("testdata/commonsense.txt") |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | defer f.Close() |
| 18 | |
| 19 | var i int |
| 20 | split, errptr := Split(f) |
| 21 | for chunk := range split { |
| 22 | i++ |
| 23 | want, err := os.ReadFile(fmt.Sprintf("testdata/chunk%02d", i)) |
| 24 | if err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | if !bytes.Equal(chunk, want) { |
| 28 | t.Errorf("mismatch in chunk %d", i) |
| 29 | } |
| 30 | } |
| 31 | if err := *errptr; err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | |
| 35 | const wantChunks = 16 |
| 36 | if i != wantChunks { |
| 37 | t.Errorf("got %d chunks, want %d", i, wantChunks) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func TestSplitFew(t *testing.T) { |
| 42 | for num := 0; num < 2; num++ { |