idoneal - cleaner_test.go
1 package meta
2
3 import (
4 "io"
5 "strings"
6 "testing"
7 )
8
9 func TestCleaner(t *testing.T) {
10 var buf [5]byte
11 for n, test := range [...]struct {
12 Input, Output string
13 }{
14 {
15 "A",
16 "A",
17 },
18 {
19 "\n",
20 "",
21 },
22 {
23 "A\nB",
24 "A\nB",
25 },
26 {
27 "\n\nA\nB\n\n",
28 "A\nB\n",
29 },
30 {
31 "A\n\nB",
32 "A\nB",
33 },
34 {
35 "A\r\nB",
36 "A\nB",
37 },
38 {
39 "A\r\n\nB",
40 "A\nB",
41 },
42 {
43 "A\r\n\r\n\r\n\n\n\nB\n\n\nC\r\n\n\r\nD",
44 "A\nB\nC\nD",
45 },
46 } {
47 for i := 1; i <= 5; i++ {
48 var sb strings.Builder
49 io.CopyBuffer(&sb, cleaner(strings.NewReader(test.Input)), buf[:i])
50 if output := sb.String(); test.Output != output {
51 t.Errorf("test %d.%d: expecting output %q, got %q", n+1, i, test.Output, output)
52 }
53 }
54 }
55 }
56