-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathfind_params_test.go
More file actions
32 lines (28 loc) · 899 Bytes
/
find_params_test.go
File metadata and controls
32 lines (28 loc) · 899 Bytes
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
package compiler
import (
"testing"
"github.com/sqlc-dev/sqlc/internal/sql/ast"
)
func TestFindParametersSelectStmtUsesFromRangeVarForWhereParams(t *testing.T) {
t.Parallel()
tableName := "solar_commcard_mapping"
refs, errs := findParameters(&ast.SelectStmt{
FromClause: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: &tableName}}},
WhereClause: &ast.A_Expr{
Lexpr: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "deviceId"}}}},
Rexpr: &ast.ParamRef{Number: 1, Location: 1},
},
})
if len(errs) > 0 {
t.Fatalf("findParameters returned errors: %v", errs)
}
if len(refs) != 1 {
t.Fatalf("expected 1 ref, got %d", len(refs))
}
if refs[0].rv == nil || refs[0].rv.Relname == nil {
t.Fatal("expected ref to carry range var")
}
if got := *refs[0].rv.Relname; got != tableName {
t.Fatalf("expected ref range var %q, got %q", tableName, got)
}
}