-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtext_test.go
More file actions
81 lines (74 loc) · 2.13 KB
/
text_test.go
File metadata and controls
81 lines (74 loc) · 2.13 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"bytes"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestMakeColString(t *testing.T) {
cf := CSVParsingColumnFormatter{
ColumnFormatter: ColumnFormatter{
ColWidth: 4,
LiteralStrings: false,
},
}
for i, tc := range []struct {
input []byte
output string
}{
{[]byte("hello"), "hel…"},
{[]byte(""), ""},
{[]byte("………"), "………"},
{[]byte("………x"), "………x"},
{[]byte("………xx"), "…………"},
} {
if out := cf.makeColString(tc.input); out != tc.output {
t.Errorf("test case %d: %q != %q", i, out, tc.output)
}
}
}
var csvData = []byte(`a,bb,ccc
123,23,3
three,two,one
\,",","
"
`)
func TestColumnFormatter1(t *testing.T) {
cf := CSVParsingColumnFormatter{
ColumnFormatter: ColumnFormatter{
Output: &bytes.Buffer{},
},
}
cf.Write(csvData)
cf.Close()
str := cf.Output.(*bytes.Buffer).String()
if diff := cmp.Diff(str, `| a | bb | ccc |
---------------------
| 123 | 23 | 3 |
| three | two | one |
| \\ | , | \n |
`); diff != "" {
t.Fatalf("unexpected difference:\n%s", diff)
}
}
var csvData2 = []byte(`field1,"field number two",3
one,two,three
"one,""","""two""",3
,\,
some longer line that has more characters,makes up this value,"with some
quotes involved"
`)
func TestColumnFormatter2(t *testing.T) {
cf := CSVParsingColumnFormatter{ColumnFormatter: ColumnFormatter{Output: &bytes.Buffer{}}}
cf.Write(csvData2)
cf.Close()
str := cf.Output.(*bytes.Buffer).String()
if diff := cmp.Diff(str, `| field1 | field number two | 3 |
------------------------------------------------------------------------------------------------
| one | two | three |
| one," | "two" | 3 |
| | \\ | |
| some longer line that has more characters | makes up this value | with some\nquotes involved |
`); diff != "" {
t.Fatalf("unexpected difference:\n%s", diff)
}
}