-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnu_test.go
43 lines (36 loc) · 848 Bytes
/
gnu_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
package main
import (
"context"
"path/filepath"
"testing"
gm "github.com/hymkor/gmnlisp"
)
func test(t *testing.T, code string, expect gm.Node) {
ctx := context.Background()
w := gm.New()
v, f := setupFunctions(ctx, w, []string{})
w = w.Let(v).Flet(f)
if _, err := w.Interpret(ctx, embededLsp); err != nil {
panic(err.Error())
}
if e := w.Assert(code, expect); e != "" {
t.Helper()
t.Fatal(e)
}
}
func TestBasename(t *testing.T) {
test(t, `(basename "hoge.tar")`, gm.String("hoge"))
}
func TestDir(t *testing.T) {
test(t, `(dir "foo\\bar\\gar.tar")`, gm.String(`foo\bar`))
}
func TestNotDir(t *testing.T) {
test(t, `(notdir "foo\\bar\\gar.tar")`, gm.String(`gar.tar`))
}
func TestAbs(t *testing.T) {
temp, err := filepath.Abs(".")
if err != nil {
t.Fatal(err.Error())
}
test(t, `(abspath ".")`, gm.String(temp))
}