-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsymbol_table_frame_test.go
54 lines (42 loc) · 1.47 KB
/
symbol_table_frame_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
51
52
53
54
// Copyright 2014 SteelSeries ApS. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This package implements a basic LISP interpretor for embedding in a go program for scripting.
// This file tests the symbol table frame.
package golisp
import (
. "gopkg.in/check.v1"
)
type SymbolTableFrameSuite struct {
frame *SymbolTableFrame
}
var _ = Suite(&SymbolTableFrameSuite{})
func (s *SymbolTableFrameSuite) SetUpTest(c *C) {
s.frame = NewSymbolTableFrameBelow(nil, "test")
}
func (s *SymbolTableFrameSuite) TestFetching(c *C) {
sym := SymbolWithName("test")
b := BindingWithSymbolAndValue(sym, IntegerWithValue(42))
s.frame.SetBindingAt("test", b)
fetched, found := s.frame.BindingNamed("test")
c.Assert(fetched, NotNil)
c.Assert(found, Equals, true)
c.Assert(StringValue(fetched.Sym), Equals, "test")
c.Assert(IntegerValue(fetched.Val), Equals, int64(42))
}
func (s *SymbolTableFrameSuite) TestBinding(c *C) {
_, err := s.frame.BindTo(Intern("test"), IntegerWithValue(42))
c.Assert(err, IsNil)
binding, found := s.frame.Bindings["test"]
c.Assert(found, Equals, true)
c.Assert(binding, NotNil)
}
func (s *SymbolTableFrameSuite) TestSymbolValue(c *C) {
sym := Intern("test")
_, err := s.frame.BindTo(sym, IntegerWithValue(42))
c.Assert(err, IsNil)
val := s.frame.ValueOf(sym)
c.Assert(val, NotNil)
c.Assert(int(TypeOf(val)), Equals, IntegerType)
c.Assert(IntegerValue(val), Equals, int64(42))
}