-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlcommatize_test.go
56 lines (48 loc) · 1.41 KB
/
sqlcommatize_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
package sqlcommatize
import (
"fmt"
"reflect"
"testing"
)
const LB = LineBreak
func TestCommatizer_Transform(t *testing.T) {
type testCase struct {
input string
want string
}
runCases := func(tc []testCase, rt RowType, cs CommaStyle) {
for _, c := range tc {
got := Commatize([]byte(c.input), rt, cs)
want := []byte(c.want)
if !reflect.DeepEqual(got, want) {
t.Fatalf("Got %v, want %v", got, want)
}
}
}
// numbers
cases := []testCase{
{"1", "1"},
{fmt.Sprintf("1%s2", LB), fmt.Sprintf("1,%s2", LB)},
{fmt.Sprintf("1%s2%s3", LB, LB), fmt.Sprintf("1,%s2,%s3", LB, LB)},
// Excel adding extra line break at the end edge case
{fmt.Sprintf("1%s2%s", LB, LB), fmt.Sprintf("1,%s2", LB)},
}
runCases(cases, Number, Trailing)
// strings
cases = []testCase{
{"a", "'a'"},
{fmt.Sprintf("a%sb", LB), fmt.Sprintf("'a',%s'b'", LB)},
{fmt.Sprintf("a%sb%sc", LB, LB), fmt.Sprintf("'a',%s'b',%s'c'", LB, LB)},
{fmt.Sprintf("'a'%sb%s'c''", LB, LB), fmt.Sprintf("'''a''',%s'b',%s'''c'''''", LB, LB)},
// Excel adding extra line break at the end edge case
{fmt.Sprintf("1'%s'2%s", LB, LB), fmt.Sprintf("'1''',%s'''2'", LB)},
}
runCases(cases, String, Trailing)
// leading commas
cases = []testCase{
{"a", "'a'"},
{fmt.Sprintf("a%sb", LB), fmt.Sprintf("'a'%s,'b'", LB)},
{fmt.Sprintf("a%sb%sc", LB, LB), fmt.Sprintf("'a'%s,'b'%s,'c'", LB, LB)},
}
runCases(cases, String, Leading)
}