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

Function TestCommonTableExpr

pkg/sql/ast/nodes_test.go:97–144  ·  view source on GitHub ↗

Test CommonTableExpr node

(t *testing.T)

Source from the content-addressed store, hash-verified

95
96// Test CommonTableExpr node
97func TestCommonTableExpr(t *testing.T) {
98 tests := []struct {
99 name string
100 cte *CommonTableExpr
101 wantLiteral string
102 wantChildren int
103 }{
104 {
105 name: "simple CTE",
106 cte: &CommonTableExpr{
107 Name: "my_cte",
108 Statement: &SelectStatement{},
109 },
110 wantLiteral: "my_cte",
111 wantChildren: 1,
112 },
113 {
114 name: "CTE with columns",
115 cte: &CommonTableExpr{
116 Name: "cte_with_cols",
117 Columns: []string{"col1", "col2", "col3"},
118 Statement: &SelectStatement{},
119 },
120 wantLiteral: "cte_with_cols",
121 wantChildren: 1,
122 },
123 }
124
125 for _, tt := range tests {
126 tt := tt // G601: Create local copy to avoid memory aliasing
127 t.Run(tt.name, func(t *testing.T) {
128 // Test TokenLiteral
129 if got := tt.cte.TokenLiteral(); got != tt.wantLiteral {
130 t.Errorf("CommonTableExpr.TokenLiteral() = %v, want %v", got, tt.wantLiteral)
131 }
132
133 // Test Children
134 children := tt.cte.Children()
135 if len(children) != tt.wantChildren {
136 t.Errorf("CommonTableExpr.Children() count = %d, want %d", len(children), tt.wantChildren)
137 }
138
139 // Test that it implements Statement interface
140 var _ Statement = tt.cte
141 tt.cte.statementNode()
142 })
143 }
144}
145
146// Test SetOperation node
147func TestSetOperation(t *testing.T) {

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