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

Function TestExtractEdgeCases

pkg/gosqlx/coverage_test.go:216–552  ·  view source on GitHub ↗

TestExtractEdgeCases covers more extract paths for collectFromExpression coverage.

(t *testing.T)

Source from the content-addressed store, hash-verified

214
215// TestExtractEdgeCases covers more extract paths for collectFromExpression coverage.
216func TestExtractEdgeCases(t *testing.T) {
217 t.Run("columns from CASE", func(t *testing.T) {
218 r := mustParseHelper(t, "SELECT CASE WHEN status = 'active' THEN name ELSE email END FROM users")
219 cols := ExtractColumns(r)
220 if len(cols) == 0 {
221 t.Error("expected columns")
222 }
223 })
224
225 t.Run("columns from CAST", func(t *testing.T) {
226 r := mustParseHelper(t, "SELECT CAST(age AS TEXT) FROM users")
227 cols := ExtractColumns(r)
228 if len(cols) == 0 {
229 t.Error("expected columns from CAST expression")
230 }
231 })
232
233 t.Run("columns from IN", func(t *testing.T) {
234 r := mustParseHelper(t, "SELECT * FROM t WHERE status IN ('a', 'b', 'c')")
235 cols := ExtractColumns(r)
236 if len(cols) == 0 {
237 t.Error("expected columns from IN expression")
238 }
239 })
240
241 t.Run("columns from BETWEEN", func(t *testing.T) {
242 r := mustParseHelper(t, "SELECT * FROM t WHERE age BETWEEN min_age AND max_age")
243 cols := ExtractColumns(r)
244 if len(cols) == 0 {
245 t.Error("expected columns from BETWEEN expression")
246 }
247 })
248
249 t.Run("columns from unary NOT", func(t *testing.T) {
250 r := mustParseHelper(t, "SELECT * FROM t WHERE NOT active")
251 cols := ExtractColumns(r)
252 if len(cols) == 0 {
253 t.Error("expected columns from NOT expression")
254 }
255 })
256
257 t.Run("tables from UNION", func(t *testing.T) {
258 r := mustParseHelper(t, "SELECT * FROM t1 UNION SELECT * FROM t2")
259 tables := ExtractTables(r)
260 if len(tables) < 2 {
261 t.Errorf("expected >= 2 tables, got %d", len(tables))
262 }
263 })
264
265 t.Run("tables from subquery", func(t *testing.T) {
266 r := mustParseHelper(t, "SELECT * FROM (SELECT * FROM inner_t) AS sub JOIN outer_t ON sub.id = outer_t.id")
267 tables := ExtractTables(r)
268 if len(tables) == 0 {
269 t.Error("expected tables")
270 }
271 })
272
273 t.Run("functions from nested calls", func(t *testing.T) {

Callers

nothing calls this directly

Calls 10

mustParseHelperFunction · 0.85
ExtractColumnsFunction · 0.85
ExtractTablesFunction · 0.85
ExtractFunctionsFunction · 0.85
ExtractColumnsQualifiedFunction · 0.85
ExtractTablesQualifiedFunction · 0.85
ExtractMetadataFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected