-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader_test.go
More file actions
34 lines (29 loc) · 821 Bytes
/
reader_test.go
File metadata and controls
34 lines (29 loc) · 821 Bytes
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
package main
import (
"bufio"
"strings"
"testing"
)
func TestReader(t *testing.T) {
expectations := []TestExpectation{
{"\n\t", "nil"},
{"\"hello world\"", "\"hello world\""},
{"()", "nil"}, // empty list
{"1", "1"},
{"'(1 2 3)", "(quote (1 2 3))"},
// {"' \r\n(1 2 3 )", "(1 2 3)"},
{"(1 2 (3.1 3.2 3.3) 4 5 \"six\")", "(1 2 (3.1 3.2 3.3) 4 5 \"six\")"},
{"1.34", "1.34"},
{"(if 10 20 30)", "(if 10 20 30)"},
{"`(if ,a ,@b 30)", "(backquote (if (unquote a) (unquote-splice b) 30))"},
}
for _, exp := range expectations {
reader := bufio.NewReader(strings.NewReader(exp.arg))
result, _ := Read(reader)
actual := LispObject2String(result)
if actual != exp.expected {
t.Errorf("TestRead: Expected (read %v) => %s, but got %s",
exp.arg, exp.expected, actual)
}
}
}