diff --git a/pkg/formatters/ast/ast_test.go b/pkg/formatters/ast/ast/ast_test.go similarity index 86% rename from pkg/formatters/ast/ast_test.go rename to pkg/formatters/ast/ast/ast_test.go index a82fc94..b648f93 100644 --- a/pkg/formatters/ast/ast_test.go +++ b/pkg/formatters/ast/ast/ast_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "git.golang1.ru/softonik/godog" + "git.golang1.ru/softonik/godog/pkg/formatters/ast" "git.golang1.ru/softonik/godog/pkg/lib" . "git.golang1.ru/softonik/godog_and_gomega" . "github.com/onsi/gomega" @@ -58,7 +59,7 @@ func файл(fname string, content *godog.DocString) { } func добавляетсяШагСФункциейС(шаг, func_name, params string) { - err := ДобавитьШаг("`"+шаг+"`", func_name, params) + err := ast.ДобавитьШаг("`"+шаг+"`", func_name, params) Ok(err) } @@ -68,7 +69,7 @@ func файлДолженСодержать(fname string, content *godog.DocStri Ω(cont).To(Be(content.Content)) - pkg, err := получитьИмяGoПакетаФайла(fname) + pkg, err := lib.ПолучитьИмяGoПакетаФайла(fname) Ok(err) Ω(pkg).To(Be("mypkg")) } diff --git a/pkg/formatters/ast/features/app.feature b/pkg/formatters/ast/ast/features/app.feature similarity index 100% rename from pkg/formatters/ast/features/app.feature rename to pkg/formatters/ast/ast/features/app.feature diff --git a/pkg/formatters/ast/init_test.go b/pkg/formatters/ast/ast/init_test.go similarity index 100% rename from pkg/formatters/ast/init_test.go rename to pkg/formatters/ast/ast/init_test.go diff --git a/pkg/formatters/ast/helpers.go b/pkg/formatters/ast/helpers.go index 63fc189..2928e94 100644 --- a/pkg/formatters/ast/helpers.go +++ b/pkg/formatters/ast/helpers.go @@ -3,13 +3,13 @@ package ast import ( "fmt" "go/ast" - "go/parser" - "go/token" "os" "path/filepath" "time" "errors" + + "git.golang1.ru/softonik/godog/pkg/lib" ) const ( @@ -25,7 +25,7 @@ func получитьИмяGoПакетаВЭтойДире() (pkg_name string, } if !info.IsDir() && filepath.Ext(path) == ".go" { - pkg, err := получитьИмяGoПакетаФайла(path) + pkg, err := lib.ПолучитьИмяGoПакетаФайла(path) if err != nil { return err } @@ -38,14 +38,6 @@ func получитьИмяGoПакетаВЭтойДире() (pkg_name string, return } -func получитьИмяGoПакетаФайла(fname string) (string, error) { - fset := token.NewFileSet() - node, err := parser.ParseFile(fset, fname, nil, parser.AllErrors) - if err != nil { - return "", err - } - return node.Name.Name, nil -} func переименоватьФайлСоВременем(fname string) error { os.MkdirAll(BACKUP_DIR, 0755) diff --git a/pkg/lib/helpers.go b/pkg/lib/helpers.go new file mode 100644 index 0000000..ab12c96 --- /dev/null +++ b/pkg/lib/helpers.go @@ -0,0 +1,15 @@ +package lib + +import ( + "go/parser" + "go/token" +) + +func ПолучитьИмяGoПакетаФайла(fname string) (string, error) { + fset := token.NewFileSet() + node, err := parser.ParseFile(fset, fname, nil, parser.AllErrors) + if err != nil { + return "", err + } + return node.Name.Name, nil +}