forked from expr-lang/expr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface_test.go
More file actions
40 lines (30 loc) · 794 Bytes
/
Copy pathinterface_test.go
File metadata and controls
40 lines (30 loc) · 794 Bytes
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
package interface_test
import (
"testing"
"github.com/expr-lang/expr"
"github.com/expr-lang/expr/internal/testify/assert"
)
type StoreInterface interface {
Get(string) int
}
type StoreImpt struct{}
func (f StoreImpt) Get(s string) int {
return 42
}
func (f StoreImpt) Set(s string, i int) bool {
return true
}
type Env struct {
Store StoreInterface `expr:"store"`
}
func TestInterfaceHide(t *testing.T) {
var env Env
p, err := expr.Compile(`store.Get("foo")`, expr.Env(env))
assert.NoError(t, err)
out, err := expr.Run(p, Env{Store: StoreImpt{}})
assert.NoError(t, err)
assert.Equal(t, 42, out)
_, err = expr.Compile(`store.Set("foo", 100)`, expr.Env(env))
assert.Error(t, err)
assert.Contains(t, err.Error(), "type interface_test.StoreInterface has no method Set")
}