ics - unfolder_test.go
1 package ics
2
3 import (
4 "bytes"
5 "io"
6 "strings"
7 "testing"
8 )
9
10 func TestUnfolder(t *testing.T) {
11 tests := []struct {
12 Input, Output string
13 }{
14 {"A", "A"},
15 {"A\nB", "A\nB"},
16 {"A\r\n B", "AB"},
17 {"ABCDEFGHIJKL\r\n MNOP\r\n QRSTUV\r\nWXY\r\n Z", "ABCDEFGHIJKLMNOPQRSTUV\r\nWXYZ"},
18 {"\xe2\r\n \x82\r\n \xac", "€"},
19 {"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"},
20 }
21 var buf bytes.Buffer
22 for n, test := range tests {
23 io.Copy(&buf, &unfolder{r: strings.NewReader(test.Input)})
24 if str := buf.String(); str != test.Output {
25 t.Errorf("test %d.1: expecting output %q, got %q", n+1, test.Output, str)
26 }
27 buf.Reset()
28 var b [1]byte
29 u := &unfolder{r: strings.NewReader(test.Input)}
30 for {
31 if _, err := u.Read(b[:]); err == io.EOF {
32 break
33 } else if err != nil {
34 t.Errorf("test %d.2: unexpected error: %s", n+1, err)
35 }
36 buf.Write(b[:])
37 }
38 if str := buf.String(); str != test.Output {
39 t.Errorf("test %d.3: expecting output %q, got %q", n+1, test.Output, str)
40 }
41 buf.Reset()
42 }
43 }