compiler: allow to use exported variables

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-07-28 19:35:41 +03:00
parent b8d7e93459
commit 6df019913d
5 changed files with 124 additions and 23 deletions

View file

@ -136,3 +136,54 @@ func TestMultipleFiles(t *testing.T) {
}`
eval(t, src, big.NewInt(42))
}
func TestExportedVariable(t *testing.T) {
t.Run("Use", func(t *testing.T) {
src := `package foo
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/multi"
func Main() int {
return multi.SomeVar12
}`
eval(t, src, big.NewInt(12))
})
t.Run("ChangeAndUse", func(t *testing.T) {
src := `package foo
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/multi"
func Main() int {
multi.SomeVar12 = 10
return multi.Sum()
}`
eval(t, src, big.NewInt(40))
})
t.Run("PackageAlias", func(t *testing.T) {
src := `package foo
import kek "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/multi"
func Main() int {
kek.SomeVar12 = 10
return kek.Sum()
}`
eval(t, src, big.NewInt(40))
})
t.Run("DifferentName", func(t *testing.T) {
src := `package foo
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/strange"
func Main() int {
normal.NormalVar = 42
return normal.NormalVar
}`
eval(t, src, big.NewInt(42))
})
t.Run("MultipleEqualNames", func(t *testing.T) {
src := `package foo
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/multi"
var SomeVar12 = 1
func Main() int {
SomeVar30 := 3
sum := SomeVar12 + multi.SomeVar30
sum += SomeVar30
sum += multi.SomeVar12
return sum
}`
eval(t, src, big.NewInt(46))
})
}