Добавлена функция с типом ShouldBeSkipped
Этот коммит содержится в:
родитель
938bb8bba4
коммит
df0a4527aa
2 изменённых файлов: 44 добавлений и 0 удалений
|
@ -184,6 +184,9 @@ func handleExprStmt(stmt *ast.ExprStmt) string {
|
|||
|
||||
func handleFuncDecl(decl ast.Decl) string {
|
||||
fd := decl.(*ast.FuncDecl)
|
||||
if shouldSkipFunction(fd.Type) {
|
||||
return ""
|
||||
}
|
||||
code := ""
|
||||
name := ""
|
||||
code += handleFuncDeclType(fd.Type)
|
||||
|
@ -200,6 +203,37 @@ func handleFuncDecl(decl ast.Decl) string {
|
|||
code += "}"
|
||||
return code
|
||||
}
|
||||
func shouldSkipFunction(t *ast.FuncType) (res bool) {
|
||||
r := t.Results
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
l := r.List
|
||||
if len(l) != 1 {
|
||||
return
|
||||
}
|
||||
|
||||
p := l[0]
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
|
||||
pt := p.Type
|
||||
if pt == nil {
|
||||
return
|
||||
}
|
||||
|
||||
i, ok := pt.(*ast.Ident)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if i.Name == "ShouldBeSkipped" {
|
||||
return true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func handleFuncDeclParams(t *ast.FuncType) string {
|
||||
code := ""
|
||||
|
|
|
@ -225,6 +225,16 @@ var _ = Describe("Go Translator", func() {
|
|||
Compare(source, expected)
|
||||
})
|
||||
|
||||
It("Function_Should_Be_Skipped", func() {
|
||||
source := `package test
|
||||
func foo() (s ShouldBeSkipped) {
|
||||
return;
|
||||
}
|
||||
`
|
||||
expected := ``
|
||||
Compare(source, expected)
|
||||
})
|
||||
|
||||
It("Package_Import", func() {
|
||||
source := `package test
|
||||
import "github.com/andygeiss/esp32-mqtt/api/controller"
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче