-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreader_test.go
34 lines (28 loc) · 879 Bytes
/
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
package macreader
import (
"bytes"
"encoding/csv"
"fmt"
)
func Example() {
// testFile is a CSV file with CR line endings.
testFile := bytes.NewBufferString("a,b,c\r1,2,3\r").Bytes()
// First try reading the csv file the normal way.
// The CSV reader doesn't recognize the '\r' line ending.
r1 := csv.NewReader(bytes.NewReader(testFile))
lines1, err := r1.ReadAll()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Without macreader: %#v\n", lines1)
// Now try reading the csv file using macreader.
// It should work as expected.
r2 := csv.NewReader(New(bytes.NewReader(testFile)))
lines2, err := r2.ReadAll()
if err != nil {
fmt.Println(err)
}
fmt.Printf("With macreader: %#v\n", lines2)
// Output: Without macreader: [][]string{[]string{"a", "b", "c\r1", "2", "3"}}
// With macreader: [][]string{[]string{"a", "b", "c"}, []string{"1", "2", "3"}}
}