-
Notifications
You must be signed in to change notification settings - Fork 0
/
environ_test.go
37 lines (32 loc) · 971 Bytes
/
environ_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
package goscm
import (
"testing"
)
func Test_Environment(t *testing.T) {
// Making a top-level environment
top := NewEnv(nil)
if top.String() != "#<environment>" {
t.Error()
}
// Adding to an environment and retrieving
top.Add(NewSymbol("foo"), NewPlainInt(9987654))
ret, err := top.Find(NewSymbol("FoO"))
if err != nil { t.Error(err) }
ans, ok := ret.(*PlainInt)
if !ok { t.Error(ok) }
if ans.String() != "9987654" { t.Error(ans) }
// Making a child environment and retrieving from it
env := NewEnv(top)
env.Add(NewSymbol("bar"), NewPlainInt(9987666))
ret, err = env.Find(NewSymbol("BAR"))
if err != nil { t.Error(err) }
ans, ok = ret.(*PlainInt)
if !ok { t.Error(ok) }
if ans.String() != "9987666" { t.Error(ans) }
// Retrieving from a parent environment from a child
ret, err = env.Find(NewSymbol("foo"))
if err != nil { t.Error(err) }
ans, ok = ret.(*PlainInt)
if !ok { t.Error(ok) }
if ans.String() != "9987654" { t.Error(ans) }
}