-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtype_test.go
105 lines (87 loc) · 3.27 KB
/
type_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// 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 type functions.
package golisp
import (
. "gopkg.in/check.v1"
)
type TypeSuite struct {
}
var _ = Suite(&TypeSuite{})
func (s *TypeSuite) TestList(c *C) {
sexpr := Cons(IntegerWithValue(5), nil)
c.Assert(ListP(sexpr), Equals, true)
c.Assert(PairP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, ConsCellType)
c.Assert(TypeName(ConsCellType), Equals, "List")
}
// func (s *TypeSuite) TestAlist(c *C) {
// sexpr := Acons(IntegerWithValue(5), StringWithValue("five"), nil)
// c.Assert(AlistP(sexpr), Equals, true)
// c.Assert(ListP(sexpr), Equals, true)
// c.Assert(int(TypeOf(sexpr)), Equals, AlistType)
// c.Assert(TypeName(AlistType), Equals, "Association List")
// c.Assert(DottedPairP(Car(sexpr)), Equals, true)
// c.Assert(TypeOf(Car(sexpr)), Equals, AlistCellType)
// c.Assert(TypeName(AlistCellType), Equals, "Association List Cell")
// }
func (s *TypeSuite) TestInteger(c *C) {
sexpr := IntegerWithValue(5)
c.Assert(IntegerP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, IntegerType)
c.Assert(TypeName(IntegerType), Equals, "Integer")
}
func (s *TypeSuite) TestFloat(c *C) {
sexpr := FloatWithValue(5.0)
c.Assert(FloatP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, FloatType)
c.Assert(TypeName(FloatType), Equals, "Float")
}
func (s *TypeSuite) TestBoolean(c *C) {
sexpr := BooleanWithValue(true)
c.Assert(BooleanP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, BooleanType)
c.Assert(TypeName(BooleanType), Equals, "Boolean")
}
func (s *TypeSuite) TestString(c *C) {
sexpr := StringWithValue("str")
c.Assert(StringP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, StringType)
c.Assert(TypeName(StringType), Equals, "String")
}
func (s *TypeSuite) TestSymbol(c *C) {
sexpr := SymbolWithName("str")
c.Assert(SymbolP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, SymbolType)
c.Assert(TypeName(SymbolType), Equals, "Symbol")
}
func (s *TypeSuite) TestFunction(c *C) {
sexpr := FunctionWithNameParamsBodyAndParent("func", nil, nil, nil)
c.Assert(FunctionP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, FunctionType)
c.Assert(TypeName(FunctionType), Equals, "Function")
}
func (s *TypeSuite) TestMacro(c *C) {
sexpr := MacroWithNameParamsBodyAndParent("mac", nil, nil, nil)
c.Assert(MacroP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, MacroType)
c.Assert(TypeName(MacroType), Equals, "Macro")
}
func (s *TypeSuite) TestPrimitive(c *C) {
sexpr := PrimitiveWithNameAndFunc("prim", nil)
c.Assert(FunctionP(sexpr), Equals, false)
c.Assert(PrimitiveP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, PrimitiveType)
c.Assert(TypeName(PrimitiveType), Equals, "Primitive")
}
func (s *TypeSuite) TestObject(c *C) {
sexpr := ObjectWithTypeAndValue("obj", nil)
c.Assert(ObjectP(sexpr), Equals, true)
c.Assert(int(TypeOf(sexpr)), Equals, BoxedObjectType)
c.Assert(TypeName(BoxedObjectType), Equals, "Go Object")
}
func (s *TypeSuite) TestUnknown(c *C) {
c.Assert(TypeName(255), Equals, "Unknown")
}