aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/csv/writer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/csv/writer_test.go')
-rw-r--r--src/encoding/csv/writer_test.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/encoding/csv/writer_test.go b/src/encoding/csv/writer_test.go
index 99bc84e998..011f01c172 100644
--- a/src/encoding/csv/writer_test.go
+++ b/src/encoding/csv/writer_test.go
@@ -13,7 +13,9 @@ import (
var writeTests = []struct {
Input [][]string
Output string
+ Error error
UseCRLF bool
+ Comma rune
}{
{Input: [][]string{{"abc"}}, Output: "abc\n"},
{Input: [][]string{{"abc"}}, Output: "abc\r\n", UseCRLF: true},
@@ -41,6 +43,9 @@ var writeTests = []struct {
{Input: [][]string{{`\.`}}, Output: "\"\\.\"\n"},
{Input: [][]string{{"x09\x41\xb4\x1c", "aktau"}}, Output: "x09\x41\xb4\x1c,aktau\n"},
{Input: [][]string{{",x09\x41\xb4\x1c", "aktau"}}, Output: "\",x09\x41\xb4\x1c\",aktau\n"},
+ {Input: [][]string{{"a", "a", ""}}, Output: "a|a|\n", Comma: '|'},
+ {Input: [][]string{{",", ",", ""}}, Output: ",|,|\n", Comma: '|'},
+ {Input: [][]string{{"foo"}}, Comma: '"', Error: errInvalidDelim},
}
func TestWrite(t *testing.T) {
@@ -48,9 +53,12 @@ func TestWrite(t *testing.T) {
b := &bytes.Buffer{}
f := NewWriter(b)
f.UseCRLF = tt.UseCRLF
+ if tt.Comma != 0 {
+ f.Comma = tt.Comma
+ }
err := f.WriteAll(tt.Input)
- if err != nil {
- t.Errorf("Unexpected error: %s\n", err)
+ if err != tt.Error {
+ t.Errorf("Unexpected error:\ngot %v\nwant %v", err, tt.Error)
}
out := b.String()
if out != tt.Output {