-
Notifications
You must be signed in to change notification settings - Fork 0
/
escape_reader_test.go
58 lines (54 loc) · 1.3 KB
/
escape_reader_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
55
56
57
58
package csvdecoder
import (
"io/ioutil"
"strings"
"testing"
)
func TestEscapeReader(t *testing.T) {
for _, tc := range []struct {
name string
input string
escapeChar rune
expectedResult string
}{
{
name: "should work without anything to escape",
input: "my example string",
escapeChar: '_',
expectedResult: "my example string",
},
{
name: "should replace escaping quotes",
input: `my _"example_" string`,
escapeChar: '_',
expectedResult: `my ""example"" string`,
},
{
name: "should not replace escaping chars without quotes",
input: "my _example_ string",
escapeChar: '_',
expectedResult: "my _example_ string",
},
{
name: "should ignore escaped escaped chars",
input: `my example string__"`,
escapeChar: '_',
expectedResult: `my example string__"`,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
r, err := NewReaderWithCustomEscape(strings.NewReader(tc.input), tc.escapeChar)
if err != nil {
t.Fatal(err)
}
result, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}
if string(result) != tc.expectedResult {
t.Errorf("expected value '%s' got '%s'", tc.expectedResult, result)
}
})
}
}