mirror of
https://github.com/traefik/yaegi.git
synced 2026-06-01 18:37:56 +00:00
### Background #1102 changed how `Interpreter.Use` interprets export paths such that the last path component is stripped and used as the package name. This resulted in #1139 - attempting to Use an export with only one path component, such as `foo`, would result in the import path being `.`. ### Breaking API Change This PR changes the signature of `Interpreter.Use` from `Use(Exports)` to `Use(Exports) error`. ### Fix for #1139 With this PR, if Use is called with an incomplete export path, such as `foo`, Use will return an error.
39 lines
688 B
Go
39 lines
688 B
Go
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)
|
|
}
|
|
}
|