-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilter_test.go
More file actions
78 lines (68 loc) · 1.76 KB
/
filter_test.go
File metadata and controls
78 lines (68 loc) · 1.76 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pdf
import (
"bytes"
"io"
"testing"
)
func TestASCIIHexDecode(t *testing.T) {
tests := []struct {
input string
want string
}{
{"414243>", "ABC"},
{"61 62 63 >", "abc"},
{"414>", "A@"}, // Odd length assumes 0 trailing
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
r := bytes.NewReader([]byte(tt.input))
// applyFilter(rd io.Reader, name string, param Value)
gotReader, err := applyFilter(r, "ASCIIHexDecode", Value{})
if err != nil {
t.Fatalf("applyFilter failed: %v", err)
}
got, _ := io.ReadAll(gotReader)
if string(got) != tt.want {
t.Errorf("got %q, want %q", string(got), tt.want)
}
})
}
}
func TestASCII85Decode(t *testing.T) {
tests := []struct {
input string
want string
}{
{"87cUR", "Hell"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
r := bytes.NewReader([]byte(tt.input))
gotReader, err := applyFilter(r, "ASCII85Decode", Value{})
if err != nil {
t.Fatalf("applyFilter failed: %v", err)
}
got, err := io.ReadAll(gotReader)
if err != nil && err != io.EOF {
t.Logf("Read returned error: %v (data: %q)", err, string(got))
}
if string(got) != tt.want {
t.Errorf("got %q, want %q", string(got), tt.want)
}
})
}
}
func TestFlateDecode(t *testing.T) {
// zlib compressed "Hello World"
input := []byte{0x78, 0x9c, 0xf2, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x08, 0xcf, 0x2f, 0xca, 0x49, 0x01, 0x04, 0x00, 0x00, 0xff, 0xff, 0x1a, 0x0b, 0x04, 0x5d}
want := "Hello World"
r := bytes.NewReader(input)
gotReader, err := applyFilter(r, "FlateDecode", Value{})
if err != nil {
t.Fatalf("applyFilter failed: %v", err)
}
got, _ := io.ReadAll(gotReader)
if string(got) != want {
t.Errorf("got %q, want %q", string(got), want)
}
}