added AST feature and test case
This commit is contained in:
@@ -2,6 +2,7 @@ package generate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/config"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -18,9 +19,51 @@ func TestCreateFolder(t *testing.T) {
|
||||
// Testing if a new project is created successfully
|
||||
func TestGenerateNewProject(t *testing.T) {
|
||||
// Checking if a new project is created successfully
|
||||
err := GenerateNewProject("p2prctest")
|
||||
err := GenerateNewProject("p2prctest","p2prctest")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Testing AST function to ensure imports are
|
||||
// working as intended
|
||||
func TestChangingImportAST(t *testing.T) {
|
||||
// Create a new variable of type
|
||||
var np NewProject
|
||||
// Get current directory
|
||||
path, err := config.GetCurrentPath()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Error(err)
|
||||
}
|
||||
// Create testcase scenario
|
||||
err = config.Copy(path + "testcaseAST.go", path + "/Test/testcaseAST.go")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Error(err)
|
||||
}
|
||||
// Sets new directory to the folder test
|
||||
np.NewDir = path + "Test/"
|
||||
// Sets file name to be opened and modified in the AST
|
||||
np.FileNameAST = path + "Test/" + "testcaseAST.go"
|
||||
// Call the Read AST function
|
||||
err = np.GetASTGoFile()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Error(err)
|
||||
}
|
||||
// Change an import
|
||||
err = np.ChangeImports("fmt", "lolol")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Error(err)
|
||||
}
|
||||
// Write those saved changes
|
||||
err = np.WriteGoAst()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user