Skip to content

Commit eaf72c3

Browse files
authored
Re-add format check to parser test for 00007_array (#52)
1 parent 6af51af commit eaf72c3

File tree

6,694 files changed

+6771
-7258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,694 files changed

+6771
-7258
lines changed

CLAUDE.md

Lines changed: 20 additions & 1 deletion

cmd/next-test/main.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package main
22

33
import (
44
"encoding/json"
5+
"flag"
56
"fmt"
67
"os"
78
"path/filepath"
89
"sort"
910
)
1011

12+
var formatFlag = flag.Bool("format", false, "Find tests with todo_format instead of todo")
13+
1114
type testMetadata struct {
1215
Todo bool `json:"todo,omitempty"`
16+
TodoFormat bool `json:"todo_format,omitempty"`
1317
Explain *bool `json:"explain,omitempty"`
1418
Skip bool `json:"skip,omitempty"`
1519
ParseError bool `json:"parse_error,omitempty"`
@@ -21,6 +25,8 @@ type todoTest struct {
2125
}
2226

2327
func main() {
28+
flag.Parse()
29+
2430
testdataDir := "parser/testdata"
2531
entries, err := os.ReadDir(testdataDir)
2632
if err != nil {
@@ -49,9 +55,15 @@ func main() {
4955
continue
5056
}
5157

52-
// Only include tests marked as todo
53-
if !metadata.Todo {
54-
continue
58+
// Check for todo or todo_format based on flag
59+
if *formatFlag {
60+
if !metadata.TodoFormat {
61+
continue
62+
}
63+
} else {
64+
if !metadata.Todo {
65+
continue
66+
}
5567
}
5668

5769
// Skip tests with skip or explain=false or parse_error
@@ -72,8 +84,13 @@ func main() {
7284
})
7385
}
7486

87+
todoType := "todo"
88+
if *formatFlag {
89+
todoType = "todo_format"
90+
}
91+
7592
if len(todoTests) == 0 {
76-
fmt.Println("No todo tests found!")
93+
fmt.Printf("No %s tests found!\n", todoType)
7794
return
7895
}
7996

@@ -86,7 +103,7 @@ func main() {
86103
next := todoTests[0]
87104
testDir := filepath.Join(testdataDir, next.name)
88105

89-
fmt.Printf("Next test: %s\n\n", next.name)
106+
fmt.Printf("Next %s test: %s\n\n", todoType, next.name)
90107

91108
// Print query.sql contents
92109
queryPath := filepath.Join(testDir, "query.sql")
@@ -99,5 +116,5 @@ func main() {
99116
fmt.Printf("\nExpected EXPLAIN output:\n%s\n", string(explainBytes))
100117
}
101118

102-
fmt.Printf("\nRemaining todo tests: %d\n", len(todoTests))
119+
fmt.Printf("\nRemaining %s tests: %d\n", todoType, len(todoTests))
103120
}

internal/format/statements.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88

99
// formatSelectWithUnionQuery formats a SELECT with UNION query.
1010
func formatSelectWithUnionQuery(sb *strings.Builder, q *ast.SelectWithUnionQuery) {
11+
if q == nil {
12+
return
13+
}
1114
for i, sel := range q.Selects {
1215
if i > 0 {
1316
sb.WriteString(" UNION ")
@@ -23,6 +26,9 @@ func formatSelectWithUnionQuery(sb *strings.Builder, q *ast.SelectWithUnionQuery
2326

2427
// formatSelectQuery formats a SELECT query.
2528
func formatSelectQuery(sb *strings.Builder, q *ast.SelectQuery) {
29+
if q == nil {
30+
return
31+
}
2632
sb.WriteString("SELECT ")
2733

2834
if q.Distinct {

parser/parser_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ import (
1717
// Use with: go test ./parser -check-skipped -v
1818
var checkSkipped = flag.Bool("check-skipped", false, "Run skipped todo tests to see which ones now pass")
1919

20+
// checkFormat runs skipped todo_format tests to see which ones now pass.
21+
// Use with: go test ./parser -check-format -v
22+
var checkFormat = flag.Bool("check-format", false, "Run skipped todo_format tests to see which ones now pass")
23+
2024
// testMetadata holds optional metadata for a test case
2125
type testMetadata struct {
2226
Todo bool `json:"todo,omitempty"`
27+
TodoFormat bool `json:"todo_format,omitempty"` // true if format roundtrip test is pending
2328
Source string `json:"source,omitempty"`
2429
Explain *bool `json:"explain,omitempty"`
2530
Skip bool `json:"skip,omitempty"`
@@ -170,6 +175,33 @@ func TestParser(t *testing.T) {
170175
}
171176
}
172177

178+
// Check Format output (roundtrip test)
179+
// Skip if todo_format is true, unless -check-format flag is set
180+
if !metadata.TodoFormat || *checkFormat {
181+
formatted := parser.Format(stmts)
182+
expected := strings.TrimSpace(query)
183+
if formatted != expected {
184+
if metadata.TodoFormat {
185+
if *checkFormat {
186+
t.Logf("FORMAT STILL FAILING:\nExpected:\n%s\n\nGot:\n%s", expected, formatted)
187+
}
188+
} else {
189+
t.Errorf("Format output mismatch\nExpected:\n%s\n\nGot:\n%s", expected, formatted)
190+
}
191+
} else if metadata.TodoFormat && *checkFormat {
192+
// Automatically remove the todo_format flag from metadata.json
193+
metadata.TodoFormat = false
194+
updatedBytes, err := json.Marshal(metadata)
195+
if err != nil {
196+
t.Errorf("Failed to marshal updated metadata: %v", err)
197+
} else if err := os.WriteFile(metadataPath, append(updatedBytes, '\n'), 0644); err != nil {
198+
t.Errorf("Failed to write updated metadata.json: %v", err)
199+
} else {
200+
t.Logf("FORMAT ENABLED - removed todo_format flag from: %s", entry.Name())
201+
}
202+
}
203+
}
204+
173205
// If we get here with a todo test and -check-skipped is set, the test passes!
174206
// Automatically remove the todo flag from metadata.json
175207
if metadata.Todo && *checkSkipped {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"todo_format":true}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"todo_format":true}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"todo_format":true}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"todo_format":true}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"todo_format":true}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"todo_format":true}

0 commit comments

Comments
 (0)