-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathutil_test.go
More file actions
62 lines (52 loc) · 2.06 KB
/
util_test.go
File metadata and controls
62 lines (52 loc) · 2.06 KB
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
// 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 utilities.
package golisp
import (
. "gopkg.in/check.v1"
)
type UtilitySuite struct {
}
var _ = Suite(&UtilitySuite{})
func (s *UtilitySuite) TestArrayToList(c *C) {
a := []*Data{IntegerWithValue(1), IntegerWithValue(2)}
sexpr := ArrayToList(a)
c.Assert(ListP(sexpr), Equals, true)
c.Assert(Length(sexpr), Equals, 2)
c.Assert(IntegerValue(Car(sexpr)), Equals, int64(1))
c.Assert(IntegerValue(Cadr(sexpr)), Equals, int64(2))
}
func (s *UtilitySuite) TestEmptyArrayToList(c *C) {
a := []*Data{}
sexpr := ArrayToList(a)
c.Assert(ListP(sexpr), Equals, true)
c.Assert(Length(sexpr), Equals, 0)
}
func (s *UtilitySuite) TestArrayToListWithTail(c *C) {
a := []*Data{IntegerWithValue(1), IntegerWithValue(2)}
tail := Cons(IntegerWithValue(3), Cons(IntegerWithValue(4), nil))
sexpr := ArrayToListWithTail(a, tail)
c.Assert(ListP(sexpr), Equals, true)
c.Assert(Length(sexpr), Equals, 4)
c.Assert(IntegerValue(First(sexpr)), Equals, int64(1))
c.Assert(IntegerValue(Second(sexpr)), Equals, int64(2))
c.Assert(IntegerValue(Third(sexpr)), Equals, int64(3))
c.Assert(IntegerValue(Fourth(sexpr)), Equals, int64(4))
}
func (s *UtilitySuite) TestArrayToListWithEmptyTail(c *C) {
a := []*Data{IntegerWithValue(1), IntegerWithValue(2)}
sexpr := ArrayToListWithTail(a, nil)
c.Assert(ListP(sexpr), Equals, true)
c.Assert(Length(sexpr), Equals, 2)
c.Assert(IntegerValue(First(sexpr)), Equals, int64(1))
c.Assert(IntegerValue(Second(sexpr)), Equals, int64(2))
}
func (s *UtilitySuite) TestToArray(c *C) {
list := Cons(IntegerWithValue(1), Cons(IntegerWithValue(2), nil))
ary := ToArray(list)
c.Assert(len(ary), Equals, 2)
c.Assert(IntegerValue(ary[0]), Equals, int64(1))
c.Assert(IntegerValue(ary[1]), Equals, int64(2))
}