From cdad80cfca6bb42b5573823fca39c5d00d0d7131 Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 17 Jan 2022 03:51:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20return=20-x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile/service.go | 8 ++++++++ transpile/service_test.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/transpile/service.go b/transpile/service.go index f505a2a..7b247bb 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -106,6 +106,12 @@ func handleBasicLit(bl *ast.BasicLit) string { return bl.Value } +func handleUnaryExpr(expr *ast.UnaryExpr) string { + code := expr.Op.String() + code += handleExpr(expr.X) + return code +} + func handleBinaryExpr(expr ast.Expr) string { be := expr.(*ast.BinaryExpr) code := handleExpr(be.X) @@ -153,6 +159,8 @@ func handleExpr(expr ast.Expr) string { switch e := expr.(type) { case *ast.BasicLit: code += handleBasicLit(e) + case *ast.UnaryExpr: + code += handleUnaryExpr(e) case *ast.BinaryExpr: code += handleBinaryExpr(e) case *ast.CallExpr: diff --git a/transpile/service_test.go b/transpile/service_test.go index a0b2a65..e40cad3 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -573,6 +573,26 @@ var _ = Describe("Go Translator", func() { ` Compare(source, expected) }) + It("Объявление int функции с return -1", func() { + source := `package test + func Setup() {} + func Loop() { + } + + func MyFunction() int { + return -1 + } + ` + expected := ` + void setup() {} + void loop() { + } + MyFunction() { + return -1; + } + ` + Compare(source, expected) + }) It("Объявляет и вызывает функцию", func() { source := `package test func Setup() {}