|
| 1 | +package lisp_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + _ "embed" |
| 6 | + "log" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/jig/lisp" |
| 10 | + "github.com/jig/lisp/env" |
| 11 | + "github.com/jig/lisp/lib/core/nscore" |
| 12 | + "github.com/jig/lisp/types" |
| 13 | +) |
| 14 | + |
| 15 | +//go:embed dolessfn_test.lisp |
| 16 | +var dolessfn_test string |
| 17 | + |
| 18 | +func TestDoLessFunction(t *testing.T) { |
| 19 | + ns := env.NewEnv() |
| 20 | + for _, library := range []struct { |
| 21 | + name string |
| 22 | + load func(ns types.EnvType) error |
| 23 | + }{ |
| 24 | + {"core mal", nscore.Load}, |
| 25 | + // {"core mal with input", nscore.LoadInput}, |
| 26 | + // {"command line args", nscore.LoadCmdLineArgs}, |
| 27 | + // {"concurrent", nsconcurrent.Load}, |
| 28 | + // {"core mal extended", nscoreextended.Load}, |
| 29 | + // {"assert", nsassert.Load}, |
| 30 | + } { |
| 31 | + if err := library.load(ns); err != nil { |
| 32 | + log.Fatalf("Library Load Error: %v\n", err) |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + ast, err := lisp.READ(dolessfn_test, nil, nil) |
| 37 | + if err != nil { |
| 38 | + t.Fatal(err) |
| 39 | + } |
| 40 | + res, err := lisp.EVAL(context.Background(), ast, ns) |
| 41 | + if err != nil { |
| 42 | + t.Fatal(err) |
| 43 | + } |
| 44 | + if !res.(bool) { |
| 45 | + t.Fatalf(`res.(int) != 4 (res.(int) == %d)`, res) |
| 46 | + } |
| 47 | +} |
0 commit comments