-
Notifications
You must be signed in to change notification settings - Fork 0
/
err_test.go
62 lines (53 loc) · 1.42 KB
/
err_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
package lisp
import (
"context"
"strings"
"testing"
"github.com/jig/lisp/env"
"github.com/jig/lisp/lib/core"
"github.com/jig/lisp/types"
)
func TestBasicError(t *testing.T) {
ns := env.NewEnv()
_, err := REPL(context.Background(), ns, `(abc 1 2 3)`, types.NewCursorFile(t.Name()))
if err == nil {
t.Fatal("fatal error")
}
if !strings.HasSuffix(err.Error(), `symbol 'abc' not found`) {
t.Fatal(err)
}
}
func TestTryCatchError2(t *testing.T) {
ns := env.NewEnv()
res, err := REPL(context.Background(), ns, `(try abc (catch exc exc))`, types.NewCursorFile(t.Name()))
if err != nil {
t.Fatal(err)
}
//if !strings.HasSuffix(res.(string), `'abc' not found`) {
if res != `«go-error "symbol 'abc' not found"»` {
t.Fatalf("%s", res)
}
}
func TestTryCatchError3(t *testing.T) {
ns := env.NewEnv()
res, err := REPL(context.Background(), ns, `(try (abc 1 2) (catch exc exc))`, types.NewCursorFile(t.Name()))
if err != nil {
t.Fatal(err)
}
// if !strings.HasSuffix(res.(string), `'abc' not found`) {
if res != `«go-error "symbol 'abc' not found"»` {
t.Fatalf("%s", res)
}
}
func TestTryCatchThrowsMalType(t *testing.T) {
ns := env.NewEnv()
core.Load(ns)
res, err := REPL(context.Background(), ns, `(try (throw {:a 1}) (catch exc exc))`, types.NewCursorFile(t.Name()))
if err != nil {
t.Fatal(err)
}
// if !strings.HasSuffix(res.(string), `'abc' not found`) {
if res != `{:a 1}` {
t.Fatalf("%s", res)
}
}