-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmacros_test.go
67 lines (56 loc) · 1.79 KB
/
macros_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
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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 built-in primitive functions.
package golisp
import (
. "gopkg.in/check.v1"
)
type MacrosSuite struct {
}
var _ = Suite(&BuiltinsSuite{})
func (s *MacrosSuite) SetUpSuite(c *C) {
InitLisp()
}
func (s *BuiltinsSuite) TestNoUnquoting(c *C) {
code, _ := Parse("`(+ a 1)")
result, err := Eval(code, Global)
c.Assert(err, IsNil)
c.Assert(result, NotNil)
c.Assert(String(result), Equals, "(+ a 1)")
}
func (s *BuiltinsSuite) TestUnquotingInteger(c *C) {
code, _ := Parse("`(+ a ,1)")
result, err := Eval(code, Global)
c.Assert(err, IsNil)
c.Assert(result, NotNil)
c.Assert(String(result), Equals, "(+ a 1)")
}
func (s *BuiltinsSuite) TestUnquotingSymbol(c *C) {
_, err := Global.BindTo(SymbolWithName("a"), IntegerWithValue(5))
c.Assert(err, IsNil)
code, _ := Parse("`(+ ,a 1)")
result, err := Eval(code, Global)
c.Assert(err, IsNil)
c.Assert(result, NotNil)
c.Assert(String(result), Equals, "(+ 5 1)")
}
func (s *BuiltinsSuite) TestUnquotingExpression(c *C) {
_, err := Global.BindTo(SymbolWithName("a"), IntegerWithValue(5))
c.Assert(err, IsNil)
code, _ := Parse("`(+ ,(+ a 1) 1)")
result, err := Eval(code, Global)
c.Assert(err, IsNil)
c.Assert(result, NotNil)
c.Assert(String(result), Equals, "(+ 6 1)")
}
func (s *BuiltinsSuite) TestUnquoteSplicing(c *C) {
_, err := Global.BindTo(SymbolWithName("a"), IntegerWithValue(5))
c.Assert(err, IsNil)
code, _ := Parse("`(+ ,@(list 1 2 3) 1)")
result, err := Eval(code, Global)
c.Assert(err, IsNil)
c.Assert(result, NotNil)
c.Assert(String(result), Equals, "(+ 1 2 3 1)")
}