@@ -116,8 +116,27 @@ func TestExtractTables_WithCTE(t *testing.T) {
116116}
117117
118118func TestExtractTables_WithRecursiveCTE (t * testing.T ) {
119- // Skipping - Recursive CTE with complex JOIN syntax not fully supported yet
120- t .Skip ("Recursive CTE with complex syntax not fully supported" )
119+ sql := `WITH RECURSIVE org_chart AS (
120+ SELECT id, name, manager_id, 1 as level FROM employees WHERE manager_id IS NULL
121+ UNION ALL
122+ SELECT e.id, e.name, e.manager_id, o.level + 1
123+ FROM employees e
124+ INNER JOIN org_chart o ON e.manager_id = o.id
125+ )
126+ SELECT * FROM org_chart`
127+
128+ astNode , err := Parse (sql )
129+ if err != nil {
130+ t .Fatalf ("Failed to parse recursive CTE: %v" , err )
131+ }
132+
133+ tables := ExtractTables (astNode )
134+ if ! contains (tables , "employees" ) {
135+ t .Errorf ("Expected to find 'employees' table, got: %v" , tables )
136+ }
137+ if ! contains (tables , "org_chart" ) {
138+ t .Errorf ("Expected to find 'org_chart' CTE reference, got: %v" , tables )
139+ }
121140}
122141
123142func TestExtractTables_Insert (t * testing.T ) {
@@ -647,23 +666,58 @@ func TestExtractMetadata_EmptyQuery(t *testing.T) {
647666}
648667
649668func TestExtractColumns_WithCaseExpression (t * testing.T ) {
650- // Skipping - CASE expressions not fully supported in parser yet
651- t .Skip ("CASE expressions not fully supported in parser yet" )
669+ sql := "SELECT CASE status WHEN 'active' THEN name ELSE 'N/A' END FROM users"
670+ astNode , err := Parse (sql )
671+ if err != nil {
672+ t .Fatalf ("Failed to parse SQL: %v" , err )
673+ }
674+
675+ cols := ExtractColumns (astNode )
676+ if ! contains (cols , "status" ) {
677+ t .Errorf ("Expected 'status' in columns, got: %v" , cols )
678+ }
679+ if ! contains (cols , "name" ) {
680+ t .Errorf ("Expected 'name' in columns, got: %v" , cols )
681+ }
652682}
653683
654684func TestExtractColumns_WithInExpression (t * testing.T ) {
655- // Skipping - IN expressions in WHERE clause not fully supported yet
656- t .Skip ("IN expressions in WHERE clause not fully supported yet" )
685+ sql := "SELECT * FROM users WHERE status IN ('active', 'pending')"
686+ astNode , err := Parse (sql )
687+ if err != nil {
688+ t .Fatalf ("Failed to parse SQL: %v" , err )
689+ }
690+
691+ cols := ExtractColumns (astNode )
692+ if ! contains (cols , "status" ) {
693+ t .Errorf ("Expected 'status' in columns, got: %v" , cols )
694+ }
657695}
658696
659697func TestExtractColumns_WithBetweenExpression (t * testing.T ) {
660- // Skipping - BETWEEN expressions not fully supported yet
661- t .Skip ("BETWEEN expressions not fully supported yet" )
698+ sql := "SELECT * FROM products WHERE price BETWEEN 10 AND 100"
699+ astNode , err := Parse (sql )
700+ if err != nil {
701+ t .Fatalf ("Failed to parse SQL: %v" , err )
702+ }
703+
704+ cols := ExtractColumns (astNode )
705+ if ! contains (cols , "price" ) {
706+ t .Errorf ("Expected 'price' in columns, got: %v" , cols )
707+ }
662708}
663709
664710func TestExtractFunctions_InCaseExpression (t * testing.T ) {
665- // Skipping - CASE expressions not fully supported yet
666- t .Skip ("CASE expressions not fully supported yet" )
711+ sql := "SELECT CASE WHEN COUNT(*) > 0 THEN 'yes' ELSE 'no' END FROM users"
712+ astNode , err := Parse (sql )
713+ if err != nil {
714+ t .Fatalf ("Failed to parse SQL: %v" , err )
715+ }
716+
717+ funcs := ExtractFunctions (astNode )
718+ if ! contains (funcs , "COUNT" ) {
719+ t .Errorf ("Expected 'COUNT' in functions, got: %v" , funcs )
720+ }
667721}
668722
669723func TestExtractTables_WithSetOperations (t * testing.T ) {
@@ -854,11 +908,27 @@ func TestExtractFunctions_NoFunctions(t *testing.T) {
854908}
855909
856910func TestExtractColumns_WithCastExpression (t * testing.T ) {
857- // Skipping - CAST expressions not fully supported yet
858- t .Skip ("CAST expressions not fully supported yet" )
911+ sql := "SELECT CAST(price AS DECIMAL) FROM products"
912+ astNode , err := Parse (sql )
913+ if err != nil {
914+ t .Fatalf ("Failed to parse SQL: %v" , err )
915+ }
916+
917+ cols := ExtractColumns (astNode )
918+ if ! contains (cols , "price" ) {
919+ t .Errorf ("Expected 'price' in columns, got: %v" , cols )
920+ }
859921}
860922
861- func TestExtractFunctions_ExtractExpression (t * testing.T ) {
862- // Skipping - EXTRACT expressions not fully supported yet
863- t .Skip ("EXTRACT expressions not fully supported yet" )
923+ func TestExtractColumns_WithExtractExpression (t * testing.T ) {
924+ sql := "SELECT EXTRACT(YEAR FROM created_at) FROM orders"
925+ astNode , err := Parse (sql )
926+ if err != nil {
927+ t .Fatalf ("Failed to parse SQL: %v" , err )
928+ }
929+
930+ cols := ExtractColumns (astNode )
931+ if ! contains (cols , "created_at" ) {
932+ t .Errorf ("Expected 'created_at' in columns, got: %v" , cols )
933+ }
864934}
0 commit comments