Добавлена поддержка return -x
Этот коммит содержится в:
родитель
3ecf93ee06
коммит
cdad80cfca
2 изменённых файлов: 28 добавлений и 0 удалений
|
@ -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:
|
||||
|
|
|
@ -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() {}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче