-
Notifications
You must be signed in to change notification settings - Fork 2
/
unfolder_test.go
43 lines (41 loc) · 1.1 KB
/
unfolder_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
package ics
import (
"bytes"
"io"
"strings"
"testing"
)
func TestUnfolder(t *testing.T) {
tests := []struct {
Input, Output string
}{
{"A", "A"},
{"A\nB", "A\nB"},
{"A\r\n B", "AB"},
{"ABCDEFGHIJKL\r\n MNOP\r\n QRSTUV\r\nWXY\r\n Z", "ABCDEFGHIJKLMNOPQRSTUV\r\nWXYZ"},
{"\xe2\r\n \x82\r\n \xac", "€"},
{"BEGIN:VCALENDAR\r\nPRODID:TestDecode\r\nVERSION:2.0\r\nEND:VCALENDAR\r\n", "BEGIN:VCALENDAR\r\nPRODID:TestDecode\r\nVERSION:2.0\r\nEND:VCALENDAR\r\n"},
}
var buf bytes.Buffer
for n, test := range tests {
io.Copy(&buf, &unfolder{r: strings.NewReader(test.Input)})
if str := buf.String(); str != test.Output {
t.Errorf("test %d.1: expecting output %q, got %q", n+1, test.Output, str)
}
buf.Reset()
var b [1]byte
u := &unfolder{r: strings.NewReader(test.Input)}
for {
if _, err := u.Read(b[:]); err == io.EOF {
break
} else if err != nil {
t.Errorf("test %d.2: unexpected error: %s", n+1, err)
}
buf.Write(b[:])
}
if str := buf.String(); str != test.Output {
t.Errorf("test %d.3: expecting output %q, got %q", n+1, test.Output, str)
}
buf.Reset()
}
}