Skip to content

Commit

Permalink
update test code
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Jan 29, 2025
1 parent b5fd39f commit e9a3682
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 131 deletions.
24 changes: 10 additions & 14 deletions go/tools/asthelpergen/ast_path_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ func newPathGen(pkgname string) *pathGen {
}

func (p *pathGen) genFile() (string, *jen.File) {
p.close()
p.file.ImportName("fmt", "fmt")

// Declare the ASTStep type with underlying type uint16
p.file.Add(jen.Type().Id("ASTStep").Uint16())

// Add the const block
p.file.Add(p.buildConstWithEnum())

// Add the ASTStep#DebugString() method to the file
p.file.Add(p.debugString())
return "ast_path.go", p.file
}

Expand Down Expand Up @@ -109,19 +118,6 @@ func (p *pathGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI
return nil
}

func (p *pathGen) close() {
p.file.ImportName("fmt", "fmt")

// Declare the ASTStep type with underlying type uint16
p.file.Add(jen.Type().Id("ASTStep").Uint16())

// Add the const block
p.file.Add(p.buildConstWithEnum())

// Add the DebugString() method to the file
p.file.Add(p.debugString())
}

func (p *pathGen) debugString() *jen.Statement {
var switchCases []jen.Code

Expand Down
19 changes: 19 additions & 0 deletions go/tools/asthelpergen/asthelpergen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strings"
"testing"

"vitess.io/vitess/go/tools/codegen"

"github.com/stretchr/testify/require"
)

Expand All @@ -45,3 +47,20 @@ func TestFullGeneration(t *testing.T) {
require.False(t, applyIdx == 0 && cloneIdx == 0, "file doesn't contain expected contents")
}
}

func TestRecreateAllFiles(t *testing.T) {
t.Skip("This test recreates all files in the integration directory. It should only be run when the ASTHelperGen code has changed.")
result, err := GenerateASTHelpers(&Options{
Packages: []string{"./integration/..."},
RootInterface: "vitess.io/vitess/go/tools/asthelpergen/integration.AST",
Clone: CloneOptions{
Exclude: []string{"*NoCloneType"},
},
})
require.NoError(t, err)

for fullPath, file := range result {
err := codegen.SaveJenFile(fullPath, file)
require.NoError(t, err)
}
}
4 changes: 2 additions & 2 deletions go/tools/asthelpergen/integration/ast_clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 5 additions & 21 deletions go/tools/asthelpergen/integration/ast_copy_on_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions go/tools/asthelpergen/integration/ast_equals.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions go/tools/asthelpergen/integration/ast_path.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions go/tools/asthelpergen/integration/ast_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions go/tools/asthelpergen/integration/ast_visit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e9a3682

Please sign in to comment.