-
Notifications
You must be signed in to change notification settings - Fork 0
/
resTarget_test.go
51 lines (47 loc) · 965 Bytes
/
resTarget_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
package squl
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResTarget_dump(t *testing.T) {
testCases := []struct {
shouldFail bool
output string
args []interface{}
expected *ResTarget
}{
{
false,
"one.two AS u",
[]interface{}{},
&ResTarget{
Value: &ColumnRef{
Fields: []string{"one", "two"},
},
Alias: "u",
},
},
{
false,
"one.two[$1].four AS c",
[]interface{}{3},
&ResTarget{
Value: &ColumnRef{
Fields: []interface{}{"one", "two", Var{3}, "four"},
},
Alias: "c",
},
},
}
for i, testCase := range testCases {
counter := &ordinalMarker{}
actual, err := testCase.expected.dump(counter)
failMsg := fmt.Sprintf("testCase: %d %v", i, testCase)
if (err != nil) != testCase.shouldFail {
assert.Fail(t, failMsg, err)
}
assert.EqualValues(t, testCase.args, counter.args())
assert.Equal(t, testCase.output, actual, failMsg)
}
}