From 59344caf3388ce568afb558b2227900fc9fdffc5 Mon Sep 17 00:00:00 2001 From: Softonik Date: Fri, 6 Jun 2025 15:52:32 +0300 Subject: [PATCH] =?UTF-8?q?AST:=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=B2=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BA=D0=B5=D1=82,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B1=D1=8B=D0=BB=D0=BE=20=D1=86=D0=B8=D0=BA?= =?UTF-8?q?=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B9=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/formatters/ast/{ => ast}/ast_test.go | 5 +++-- pkg/formatters/ast/{ => ast}/features/app.feature | 0 pkg/formatters/ast/{ => ast}/init_test.go | 0 pkg/formatters/ast/helpers.go | 14 +++----------- pkg/lib/helpers.go | 15 +++++++++++++++ 5 files changed, 21 insertions(+), 13 deletions(-) rename pkg/formatters/ast/{ => ast}/ast_test.go (86%) rename pkg/formatters/ast/{ => ast}/features/app.feature (100%) rename pkg/formatters/ast/{ => ast}/init_test.go (100%) create mode 100644 pkg/lib/helpers.go 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 +}