File: bom_test.go

package info (click to toggle)
golang-github-ssor-bom 0.0~git20170718.0.6386211-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports, sid, trixie
  • size: 72 kB
  • sloc: makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download | duplicates (2)
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)
		}
	}
}