-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpbm_test.go
54 lines (48 loc) · 1.28 KB
/
pbm_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
// Test PBM files.
package netpbm
import (
"bytes"
"compress/flate"
"testing"
)
// TestDecodePGMEncodePBM confirms that a PGM file can be re-encoded as PBM.
func TestDecodePGMEncodePBM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, pgmRaw, PGM)
opts := &EncodeOptions{Format: PBM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}
// TestDecodePPMEncodePBM confirms that a PPM file can be re-encoded as PBM.
func TestDecodePPMEncodePBM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, ppmRaw, PPM)
opts := &EncodeOptions{Format: PBM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}
// TestDecodePBMComments confirms that we can decode a PBM file
// containing comments.
func TestDecodePBMComments(t *testing.T) {
// Read the image.
r := flate.NewReader(bytes.NewBufferString(pbmRawComments))
defer r.Close()
_, cs, err := DecodeWithComments(r, nil)
if err != nil {
t.Fatal(err)
}
// Confirm that the comments are as expected.
exp := []string{"This file contains", "a variety of comments...", "", " ...in all sorts", "of tricky forms."}
if len(cs) != len(exp) {
t.Fatalf("Expected %#v but received %#v", exp, cs)
}
for i, e := range exp {
if e != cs[i] {
t.Fatalf("Expected %q but received %q", e, cs[i])
}
}
}