forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselector_test.go
More file actions
35 lines (26 loc) · 1.31 KB
/
selector_test.go
File metadata and controls
35 lines (26 loc) · 1.31 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
package compiler
import "testing"
func TestSelector(t *testing.T) {
t.Parallel()
selectorExpectColumnExpr := func(t *testing.T, selector selector, expected, name string, column *Column) {
if actual := selector.ColumnExpr(name, column); expected != actual {
t.Errorf("Expected %v, got %v for data type %v", expected, actual, column.DataType)
}
}
t.Run("DefaultSelectorColumnExpr", func(t *testing.T) {
t.Parallel()
selector := newDefaultSelector()
selectorExpectColumnExpr(t, selector, "my_column", "my_column", &Column{DataType: "integer"})
selectorExpectColumnExpr(t, selector, "my_column", "my_column", &Column{DataType: "json"})
selectorExpectColumnExpr(t, selector, "my_column", "my_column", &Column{DataType: "jsonb"})
selectorExpectColumnExpr(t, selector, "my_column", "my_column", &Column{DataType: "text"})
})
t.Run("SQLiteSelectorColumnExpr", func(t *testing.T) {
t.Parallel()
selector := newSQLiteSelector()
selectorExpectColumnExpr(t, selector, "my_column", "my_column", &Column{DataType: "integer"})
selectorExpectColumnExpr(t, selector, "my_column", "my_column", &Column{DataType: "json"})
selectorExpectColumnExpr(t, selector, "json(my_column)", "my_column", &Column{DataType: "jsonb"})
selectorExpectColumnExpr(t, selector, "my_column", "my_column", &Column{DataType: "text"})
})
}