~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/csv/writer_test.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2011 The Go Authors. All rights reserved.
 
2
// Use of this source code is governed by a BSD-style
 
3
// license that can be found in the LICENSE file.
 
4
 
 
5
package csv
 
6
 
 
7
import (
 
8
        "bytes"
 
9
        "testing"
 
10
)
 
11
 
 
12
var writeTests = []struct {
 
13
        Input   [][]string
 
14
        Output  string
 
15
        UseCRLF bool
 
16
}{
 
17
        {Input: [][]string{{"abc"}}, Output: "abc\n"},
 
18
        {Input: [][]string{{"abc"}}, Output: "abc\r\n", UseCRLF: true},
 
19
        {Input: [][]string{{`"abc"`}}, Output: `"""abc"""` + "\n"},
 
20
        {Input: [][]string{{`a"b`}}, Output: `"a""b"` + "\n"},
 
21
        {Input: [][]string{{`"a"b"`}}, Output: `"""a""b"""` + "\n"},
 
22
        {Input: [][]string{{" abc"}}, Output: `" abc"` + "\n"},
 
23
        {Input: [][]string{{"abc,def"}}, Output: `"abc,def"` + "\n"},
 
24
        {Input: [][]string{{"abc", "def"}}, Output: "abc,def\n"},
 
25
        {Input: [][]string{{"abc"}, {"def"}}, Output: "abc\ndef\n"},
 
26
        {Input: [][]string{{"abc\ndef"}}, Output: "\"abc\ndef\"\n"},
 
27
        {Input: [][]string{{"abc\ndef"}}, Output: "\"abc\r\ndef\"\r\n", UseCRLF: true},
 
28
}
 
29
 
 
30
func TestWrite(t *testing.T) {
 
31
        for n, tt := range writeTests {
 
32
                b := &bytes.Buffer{}
 
33
                f := NewWriter(b)
 
34
                f.UseCRLF = tt.UseCRLF
 
35
                err := f.WriteAll(tt.Input)
 
36
                if err != nil {
 
37
                        t.Errorf("Unexpected error: %s\n", err)
 
38
                }
 
39
                out := b.String()
 
40
                if out != tt.Output {
 
41
                        t.Errorf("#%d: out=%q want %q", n, out, tt.Output)
 
42
                }
 
43
        }
 
44
}