MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestSelect

Function TestSelect

pkg/sql/ast/dml_test.go:20–131  ·  view source on GitHub ↗

Test Select node (DML)

(t *testing.T)

Source from the content-addressed store, hash-verified

18
19// Test Select node (DML)
20func TestSelect(t *testing.T) {
21 tests := []struct {
22 name string
23 sel *Select
24 wantLiteral string
25 minChildren int
26 }{
27 {
28 name: "simple SELECT with columns",
29 sel: &Select{
30 Columns: []Expression{
31 &Identifier{Name: "id"},
32 &Identifier{Name: "name"},
33 },
34 },
35 wantLiteral: "SELECT",
36 minChildren: 2,
37 },
38 {
39 name: "SELECT with FROM",
40 sel: &Select{
41 Columns: []Expression{&Identifier{Name: "*"}},
42 From: []TableReference{
43 {Name: "users"},
44 },
45 },
46 wantLiteral: "SELECT",
47 minChildren: 2,
48 },
49 {
50 name: "SELECT with WHERE",
51 sel: &Select{
52 Columns: []Expression{&Identifier{Name: "id"}},
53 From: []TableReference{
54 {Name: "users"},
55 },
56 Where: &BinaryExpression{
57 Left: &Identifier{Name: "id"},
58 Operator: "=",
59 Right: &LiteralValue{Value: "1"},
60 },
61 },
62 wantLiteral: "SELECT",
63 minChildren: 3,
64 },
65 {
66 name: "SELECT with GROUP BY and HAVING",
67 sel: &Select{
68 Columns: []Expression{
69 &Identifier{Name: "dept"},
70 &FunctionCall{Name: "COUNT", Arguments: []Expression{&Identifier{Name: "*"}}},
71 },
72 From: []TableReference{
73 {Name: "employees"},
74 },
75 GroupBy: []Expression{&Identifier{Name: "dept"}},
76 Having: &BinaryExpression{
77 Left: &FunctionCall{Name: "COUNT", Arguments: []Expression{&Identifier{Name: "*"}}},

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
TokenLiteralMethod · 0.65
ErrorfMethod · 0.65
ChildrenMethod · 0.65
statementNodeMethod · 0.65

Tested by

no test coverage detected