-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_test.go
28 lines (26 loc) · 1.07 KB
/
convert_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
package gmnlisp
import (
"context"
"testing"
)
func TestConvert(t *testing.T) {
ctx := context.Background()
w := New()
assertEqual(t, `(convert 1 <character>)`, Rune(1))
assertEqual(t, `(convert #\A <integer>)`, Integer('A'))
assertEqual(t, `(convert 1 <float>)`, Float(1.0))
assertEqual(t, `(convert 1.0 <integer>)`, Integer(1))
assertEqual(t, `(convert 1 <string>)`, String(`1`))
assertEqual(t, `(convert "1" <integer>)`, Integer(1))
assertEqual(t, `(convert "1.1" <float>)`, Float(1.1))
assertEqual(t, `(convert "s" <symbol>)`, NewSymbol("s"))
assertEqual(t, `(convert #\a <integer>)`, Integer('a'))
assertEqual(t, `(convert "abc" <list>)`, List(Rune('a'), Rune('b'), Rune('c')))
assertEqual(t, `(convert '(1 2 3) <list>)`, List(Integer(1), Integer(2), Integer(3)))
assertEqual(t, `(convert "abc" <general-vector>)`,
NewVector(ctx, w, Rune('a'), Rune('b'), Rune('c')))
assertEqual(t, `(convert '(1 2 3) <general-vector>)`,
NewVector(ctx, w, Integer(1), Integer(2), Integer(3)))
assertEqual(t, `(convert #(1 2 3) <list>)`,
List(Integer(1), Integer(2), Integer(3)))
}