TestExtractEdgeCases covers more extract paths for collectFromExpression coverage.
(t *testing.T)
| 214 | |
| 215 | // TestExtractEdgeCases covers more extract paths for collectFromExpression coverage. |
| 216 | func 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) { |
nothing calls this directly
no test coverage detected