-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbom_test.go
55 lines (51 loc) · 1 KB
/
bom_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
package bom
import (
"bytes"
"io/ioutil"
"testing"
)
var (
test_cases = []struct {
src []byte
expected []byte
}{
{
[]byte{bom0, bom1, bom2}, []byte{},
},
{
[]byte{0x33, bom0, bom1, bom2}, []byte{0x33, bom0, bom1, bom2},
},
{
[]byte{bom0, bom1}, []byte{bom0, bom1},
},
{
[]byte{bom0, bom2}, []byte{bom0, bom2},
},
{
[]byte{bom0, bom1, bom2, 0x11}, []byte{0x11},
},
}
)
func TestNewReaderWithoutBom(t *testing.T) {
for index, test_case := range test_cases {
result, err := NewReaderWithoutBom(bytes.NewReader(test_case.src))
if err != nil {
t.Fatal(err)
}
bs, err := ioutil.ReadAll(result)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(bs, test_case.expected) != 0 {
t.Fatalf("The %d th test_case failed", index)
}
}
}
func TestCleanBom(t *testing.T) {
for index, test_case := range test_cases {
result := CleanBom(test_case.src)
if bytes.Compare(result, test_case.expected) != 0 {
t.Fatalf("The %d th test_case failed", index)
}
}
}