This repository was archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathlength_test.go
104 lines (98 loc) · 1.5 KB
/
length_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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package function
import (
"testing"
"github.com/src-d/go-mysql-server/sql"
"github.com/src-d/go-mysql-server/sql/expression"
"github.com/stretchr/testify/require"
)
func TestLength(t *testing.T) {
testCases := []struct {
name string
input interface{}
inputType sql.Type
fn func(sql.Expression) sql.Expression
expected interface{}
}{
{
"length string",
"fóo",
sql.Text,
NewLength,
int32(4),
},
{
"length binary",
[]byte("fóo"),
sql.Blob,
NewLength,
int32(4),
},
{
"length empty",
"",
sql.Blob,
NewLength,
int32(0),
},
{
"length empty binary",
[]byte{},
sql.Blob,
NewLength,
int32(0),
},
{
"length nil",
nil,
sql.Blob,
NewLength,
nil,
},
{
"char_length string",
"fóo",
sql.Text,
NewCharLength,
int32(3),
},
{
"char_length binary",
[]byte("fóo"),
sql.Blob,
NewCharLength,
int32(3),
},
{
"char_length empty",
"",
sql.Blob,
NewCharLength,
int32(0),
},
{
"char_length empty binary",
[]byte{},
sql.Blob,
NewCharLength,
int32(0),
},
{
"char_length nil",
nil,
sql.Blob,
NewCharLength,
nil,
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)
result, err := tt.fn(expression.NewGetField(0, tt.inputType, "foo", false)).Eval(
sql.NewEmptyContext(),
sql.Row{tt.input},
)
require.NoError(err)
require.Equal(tt.expected, result)
})
}
}