mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: implement multiple return support
This commit is contained in:
parent
f3391f8576
commit
f4571ba8cf
2 changed files with 80 additions and 8 deletions
71
pkg/compiler/return_test.go
Normal file
71
pkg/compiler/return_test.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package compiler_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMultipleReturn1(t *testing.T) {
|
||||
src := `
|
||||
package hello
|
||||
|
||||
func two() (int, int) {
|
||||
return 5, 9
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
a, _ := two()
|
||||
return a
|
||||
}
|
||||
`
|
||||
eval(t, src, big.NewInt(5))
|
||||
}
|
||||
|
||||
func TestMultipleReturn2(t *testing.T) {
|
||||
src := `
|
||||
package hello
|
||||
|
||||
func two() (int, int) {
|
||||
return 5, 9
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
_, b := two()
|
||||
return b
|
||||
}
|
||||
`
|
||||
eval(t, src, big.NewInt(9))
|
||||
}
|
||||
|
||||
func TestMultipleReturnWithArg(t *testing.T) {
|
||||
src := `
|
||||
package hello
|
||||
|
||||
func inc2(a int) (int, int) {
|
||||
return a+1, a+2
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
a, b := 3, 9
|
||||
a, b = inc2(a)
|
||||
return a+b
|
||||
}
|
||||
`
|
||||
eval(t, src, big.NewInt(9))
|
||||
}
|
||||
|
||||
func TestSingleReturn(t *testing.T) {
|
||||
src := `
|
||||
package hello
|
||||
|
||||
func inc(k int) int {
|
||||
return k+1
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
a, b := inc(3), inc(4)
|
||||
return a+b
|
||||
}
|
||||
`
|
||||
eval(t, src, big.NewInt(9))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue