From 3749f38720bd893e936f7987b367ac89c6f9c20e Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 24 May 2021 17:10:20 +0300 Subject: [PATCH] compiler/test: add more tests for inline behaviour --- pkg/compiler/inline_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/compiler/inline_test.go b/pkg/compiler/inline_test.go index 328eec6ac..644476731 100644 --- a/pkg/compiler/inline_test.go +++ b/pkg/compiler/inline_test.go @@ -48,6 +48,11 @@ func checkCallCount(t *testing.T, src string, expectedCall, expectedInitSlot, ex func TestInline(t *testing.T) { srcTmpl := `package foo import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline" + type pair struct { a, b int } + type triple struct { + a int + b pair + } // local alias func sum(a, b int) int { return 42 @@ -130,6 +135,28 @@ func TestInline(t *testing.T) { checkCallCount(t, src, 0, 1, 1) eval(t, src, big.NewInt(221)) }) + t.Run("selector, global", func(t *testing.T) { + src := fmt.Sprintf(srcTmpl, `return inline.Sum(inline.A, 2)`) + checkCallCount(t, src, 0, 1, 1) + eval(t, src, big.NewInt(3)) + }) + t.Run("selector, struct, simple", func(t *testing.T) { + src := fmt.Sprintf(srcTmpl, `x := pair{a: 1, b: 2}; return inline.Sum(x.b, 1)`) + checkCallCount(t, src, 0, 1, 2) + eval(t, src, big.NewInt(3)) + }) + t.Run("selector, struct, complex", func(t *testing.T) { + src := fmt.Sprintf(srcTmpl, `x := triple{a: 1, b: pair{a: 2, b: 3}} + return inline.Sum(x.b.a, 1)`) + checkCallCount(t, src, 0, 1, 2) + eval(t, src, big.NewInt(3)) + }) + t.Run("expression", func(t *testing.T) { + src := fmt.Sprintf(srcTmpl, `x, y := 1, 2 + return inline.Sum(x+y, y*2)`) + checkCallCount(t, src, 0, 1, 4) + eval(t, src, big.NewInt(7)) + }) } func TestInlineInLoop(t *testing.T) {