-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope_test.go
50 lines (40 loc) · 1.04 KB
/
scope_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestScope(t *testing.T) {
t.Parallel()
t.Run("Test variable scope", func(t *testing.T) {
s := NewScope()
s.SetVar("foo", ScopeEntry{TypNumber, 42})
entry, ok := s.GetVar("foo")
assert.Equal(t, 42, entry.Value)
assert.True(t, ok)
s = NewScopeWithParent(s)
_, ok = s.GetVar("foo")
assert.False(t, ok)
})
t.Run("Test function scope", func(t *testing.T) {
s := NewScope()
s.SetFunc("foo", ScopeEntry{TypNumber, 42})
entry, ok := s.GetFunc("foo")
assert.Equal(t, 42, entry.Value)
assert.True(t, ok)
s = NewScopeWithParent(s)
entry, ok = s.GetFunc("foo")
assert.Equal(t, 42, entry.Value)
assert.True(t, ok)
})
t.Run("Test empty variable copy", func(t *testing.T) {
s := NewScope()
s.SetVar("foo", ScopeEntry{TypNumber, 42})
s.SetFunc("foo", ScopeEntry{TypNumber, 42})
s2 := s.EmptyVarCopy()
entry, ok := s2.GetVar("foo")
assert.False(t, ok)
entry, ok = s2.GetFunc("foo")
assert.Equal(t, 42, entry.Value)
assert.True(t, ok)
})
}