-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_test.go
58 lines (47 loc) · 1.21 KB
/
block_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package bzip2
import (
"testing"
"github.com/larzconwell/bzip2/internal/testhelpers"
)
func TestBlockFullWrite(t *testing.T) {
block := newBlock(1000)
_, err := block.Write(testhelpers.NoRunData(block.size))
if err == nil {
t.Error("Block full size write should return size reached error")
}
if err != errBlockSizeReached {
t.Fatal(err)
}
}
func TestBlockMultiWrite(t *testing.T) {
block := newBlock(1000)
n, err := block.Write(testhelpers.NoRunData(block.size / 2))
if err != nil {
t.Fatal(err)
}
if n != block.size/2 {
t.Error("Block half write wrote unexpected number of bytes. Got", n,
"wanted", block.size/2)
}
_, err = block.Write(testhelpers.NoRunData(block.size / 2))
if err == nil {
t.Error("Block full size write should return size reached error")
}
if err != errBlockSizeReached {
t.Fatal(err)
}
}
func TestBlockOverWrite(t *testing.T) {
block := newBlock(1000)
n, err := block.Write(testhelpers.NoRunData(block.size + 500))
if err == nil {
t.Error("Block full size write should return size reached error")
}
if err != errBlockSizeReached {
t.Fatal(err)
}
if n != block.size {
t.Error("Block write wrote unexpected number of bytes. Got", n,
"wanted", block.size)
}
}