File: closure_test.go

package info (click to toggle)
golang-github-traefik-yaegi 0.16.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 24,608 kB
  • sloc: sh: 457; makefile: 39
file content (38 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (2)
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
package clos1

import (
	"testing"

	"github.com/traefik/yaegi/interp"
	"github.com/traefik/yaegi/stdlib"
)

func TestFunctionCall(t *testing.T) {
	i := interp.New(interp.Options{GoPath: "./_pkg"})
	if err := i.Use(stdlib.Symbols); err != nil {
		t.Fatal(err)
	}

	_, err := i.Eval(`import "foo/bar"`)
	if err != nil {
		t.Fatal(err)
	}

	fnv, err := i.Eval(`bar.NewSample()`)
	if err != nil {
		t.Fatal(err)
	}

	fn, ok := fnv.Interface().(func(string, string) func(string) string)
	if !ok {
		t.Fatal("conversion failed")
	}

	fn2 := fn("hello", "world")
	val := fn2("truc")

	expected := "herev1helloworldtruc"
	if val != expected {
		t.Errorf("Got: %q, want: %q", val, expected)
	}
}