forked from ledongthuc/pdf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_test.go
54 lines (51 loc) · 1.16 KB
/
read_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
package pdf
import (
"testing"
)
func TestRead(t *testing.T) {
t.Run("HeaderValidation", testHeaderValidation)
}
func testHeaderValidation(t *testing.T) {
tscs := map[string]struct {
input []byte
expectedValid bool
}{
"nil": {
input: nil,
expectedValid: false,
},
"empty": {
input: []byte{},
expectedValid: false,
},
"missing LF": {
input: []byte{37, 80, 68, 70, 45, 49, 46, 55},
expectedValid: false,
},
"ok LF": {
input: []byte{37, 80, 68, 70, 45, 49, 46, 55, 10},
expectedValid: true,
},
"invalid version 1.8": {
input: []byte{37, 80, 68, 70, 45, 49, 46, 58, 10},
expectedValid: false,
},
"ok CRLF": {
input: []byte{37, 80, 68, 70, 45, 49, 46, 55, 13, 10},
expectedValid: true,
},
"ok space + CRLF": {
input: []byte{37, 80, 68, 70, 45, 49, 46, 55, 32, 13, 10},
expectedValid: true,
},
}
for name, data := range tscs {
data := data
t.Run(name, func(t *testing.T) {
gotValid := headerRegexp.Match(data.input)
if gotValid != data.expectedValid {
t.Errorf("expected %t, got %t", data.expectedValid, gotValid)
}
})
}
}