(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestTree(t *testing.T) { |
| 62 | text, err := os.ReadFile("testdata/commonsense.txt") |
| 63 | if err != nil { |
| 64 | t.Fatal(err) |
| 65 | } |
| 66 | |
| 67 | root, err := buildTree(text) |
| 68 | if err != nil { |
| 69 | t.Fatal(err) |
| 70 | } |
| 71 | |
| 72 | if !compareTrees(root, wantTree) { |
| 73 | t.Fatal("tree mismatch") |
| 74 | } |
| 75 | |
| 76 | var innerErr error |
| 77 | |
| 78 | pr, pw := io.Pipe() |
| 79 | go func() { |
| 80 | defer pw.Close() |
| 81 | for chunk := range root.AllChunks() { |
| 82 | _, innerErr = pw.Write(chunk) |
| 83 | if innerErr != nil { |
| 84 | return |
| 85 | } |
| 86 | } |
| 87 | }() |
| 88 | |
| 89 | reassembled, err := io.ReadAll(pr) |
| 90 | if err != nil { |
| 91 | t.Fatal(err) |
| 92 | } |
| 93 | if innerErr != nil { |
| 94 | t.Fatal(innerErr) |
| 95 | } |
| 96 | if !bytes.Equal(text, reassembled) { |
| 97 | t.Error("reassembled text does not match original") |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | func TestSeek(t *testing.T) { |
| 102 | text, err := os.ReadFile("testdata/commonsense.txt") |
nothing calls this directly
no test coverage detected