|
@@ -4,13 +4,18 @@ import (
|
|
"flow/internal/assert"
|
|
"flow/internal/assert"
|
|
"flow/registry"
|
|
"flow/registry"
|
|
"testing"
|
|
"testing"
|
|
|
|
+
|
|
|
|
+ "github.com/gohxs/prettylog"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+func init() {
|
|
|
|
+ prettylog.Global()
|
|
|
|
+}
|
|
func TestRegistry(t *testing.T) {
|
|
func TestRegistry(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
|
|
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- r.Register("vecadd", dummy1)
|
|
|
|
|
|
+ r.Add("vecadd", dummy1)
|
|
|
|
|
|
e, err := r.Entry("vecadd")
|
|
e, err := r.Entry("vecadd")
|
|
a.Eq(err, nil, "fetching entry")
|
|
a.Eq(err, nil, "fetching entry")
|
|
@@ -34,38 +39,32 @@ func TestEntry(t *testing.T) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func TestRegister(t *testing.T) {
|
|
|
|
- a := assert.A(t)
|
|
|
|
- r := registry.New()
|
|
|
|
- _, err := r.Register("func", func(a, b int) int { return 0 })
|
|
|
|
- a.Eq(err, nil, "should register a function")
|
|
|
|
-}
|
|
|
|
func TestRegisterDuplicate(t *testing.T) {
|
|
func TestRegisterDuplicate(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- r.Register("func", func(a, b int) int { return 0 })
|
|
|
|
- _, err := r.Register("func", func(b int) int { return 0 })
|
|
|
|
- a.Eq(err, nil, "should allow duplicate")
|
|
|
|
|
|
+ r.Add("func", func(a, b int) int { return 0 })
|
|
|
|
+ d := r.Add("func", func(b int) int { return 0 })
|
|
|
|
+ a.Eq(d.Err, nil, "should allow duplicate")
|
|
}
|
|
}
|
|
func TestRegisterOutput(t *testing.T) {
|
|
func TestRegisterOutput(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- _, err := r.Register("func", func(a int) {})
|
|
|
|
- a.Eq(err, nil, "should not give output error")
|
|
|
|
|
|
+ d := r.Add("func", func(a int) {})
|
|
|
|
+ a.Eq(d.Err, nil, "should not give output error")
|
|
}
|
|
}
|
|
|
|
|
|
func TestRegisterInvalidInput(t *testing.T) {
|
|
func TestRegisterInvalidInput(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- _, err := r.Register("func", func() int { return 0 })
|
|
|
|
- a.Eq(err, nil, "should register a func without params")
|
|
|
|
|
|
+ d := r.Add("func", func() int { return 0 })
|
|
|
|
+ a.Eq(d.Err, nil, "should register a func without params")
|
|
}
|
|
}
|
|
|
|
|
|
func TestRegistryGet(t *testing.T) {
|
|
func TestRegistryGet(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- _, err := r.Register("func", func() int { return 0 })
|
|
|
|
- a.Eq(err, nil, "should register func")
|
|
|
|
|
|
+ d := r.Add("func", func() int { return 0 })
|
|
|
|
+ a.Eq(d.Err, nil, "should register func")
|
|
|
|
|
|
fn, err := r.Get("func")
|
|
fn, err := r.Get("func")
|
|
a.Eq(err, nil, "should fetch a function")
|
|
a.Eq(err, nil, "should fetch a function")
|
|
@@ -82,12 +81,12 @@ func TestRegistryGetEmpty(t *testing.T) {
|
|
func TestRegistryGetConstructor(t *testing.T) {
|
|
func TestRegistryGetConstructor(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- _, err := r.Register("func", func() func() int {
|
|
|
|
|
|
+ d := r.Add("func", func() func() int {
|
|
return func() int {
|
|
return func() int {
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- a.Eq(err, nil, "should register the constructor func")
|
|
|
|
|
|
+ a.Eq(d.Err, nil, "should register the constructor func")
|
|
|
|
|
|
ifn, err := r.Get("func")
|
|
ifn, err := r.Get("func")
|
|
a.Eq(err, nil, "get should not error")
|
|
a.Eq(err, nil, "get should not error")
|
|
@@ -103,12 +102,12 @@ func TestRegistryGetConstructorParam(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
|
|
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- _, err := r.Register("func2", func(a, b int) func() int {
|
|
|
|
|
|
+ d := r.Add("func2", func(a, b int) func() int {
|
|
return func() int {
|
|
return func() int {
|
|
return a + b
|
|
return a + b
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- a.Eq(err, nil)
|
|
|
|
|
|
+ a.Eq(d.Err, nil)
|
|
ifn, err := r.Get("func2", 1, 1)
|
|
ifn, err := r.Get("func2", 1, 1)
|
|
a.Eq(err, nil, "should not fail passing params to constructor")
|
|
a.Eq(err, nil, "should not fail passing params to constructor")
|
|
a.NotEq(ifn, nil, "should return a function")
|
|
a.NotEq(ifn, nil, "should return a function")
|
|
@@ -125,8 +124,8 @@ func TestDescriptions(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
|
|
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- r.Register("vecadd", dummy1)
|
|
|
|
- r.Register("vecstr", dummy2)
|
|
|
|
|
|
+ r.Add("vecadd", dummy1)
|
|
|
|
+ r.Add("vecstr", dummy2)
|
|
|
|
|
|
d, err := r.Descriptions()
|
|
d, err := r.Descriptions()
|
|
a.Eq(err, nil, "should fetch Descriptions")
|
|
a.Eq(err, nil, "should fetch Descriptions")
|
|
@@ -137,16 +136,16 @@ func TestDescriptions(t *testing.T) {
|
|
func TestClone(t *testing.T) {
|
|
func TestClone(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
r := registry.New()
|
|
r := registry.New()
|
|
- r.Register("vecadd", dummy1)
|
|
|
|
|
|
+ r.Add("vecadd", dummy1)
|
|
|
|
|
|
- d, err := r.Descriptions()
|
|
|
|
|
|
+ desc, err := r.Descriptions()
|
|
a.Eq(err, nil, "should not error fetching description")
|
|
a.Eq(err, nil, "should not error fetching description")
|
|
|
|
|
|
- a.Eq(len(d), 1, "should contain 1 descriptions")
|
|
|
|
|
|
+ a.Eq(len(desc), 1, "should contain 1 descriptions")
|
|
|
|
|
|
r2 := r.Clone()
|
|
r2 := r.Clone()
|
|
- r2.Register("vecmul", dummy2)
|
|
|
|
- a.Eq(len(d), 1, "should contain 1 descriptions")
|
|
|
|
|
|
+ r2.Add("vecmul", dummy2)
|
|
|
|
+ a.Eq(len(desc), 1, "should contain 1 descriptions")
|
|
|
|
|
|
d2, err := r2.Descriptions()
|
|
d2, err := r2.Descriptions()
|
|
a.Eq(err, nil, "should not error fetching descriptions")
|
|
a.Eq(err, nil, "should not error fetching descriptions")
|
|
@@ -155,42 +154,27 @@ func TestClone(t *testing.T) {
|
|
_, ok := d2["vecmul"]
|
|
_, ok := d2["vecmul"]
|
|
a.Eq(ok, true, "should be equal")
|
|
a.Eq(ok, true, "should be equal")
|
|
}
|
|
}
|
|
|
|
+
|
|
func TestNotAFunc(t *testing.T) {
|
|
func TestNotAFunc(t *testing.T) {
|
|
|
|
+ a := assert.A(t)
|
|
r := registry.New()
|
|
r := registry.New()
|
|
|
|
|
|
- _, err := r.Add("test")
|
|
|
|
- assert.Eq(t, err, registry.ErrNotAFunc, "should give not a func error")
|
|
|
|
-}
|
|
|
|
|
|
+ d := r.Add("test", []string{})
|
|
|
|
+ a.Eq(d.Err, registry.ErrNotAFunc, "should give a func error")
|
|
|
|
|
|
-func TestRegisterErr(t *testing.T) {
|
|
|
|
- r := registry.New()
|
|
|
|
|
|
+ d = r.Add("test")
|
|
|
|
+ a.Eq(d.Err, registry.ErrNotAFunc, "should give a func error")
|
|
|
|
+
|
|
|
|
+ d = r.Add([]string{})
|
|
|
|
+ a.Eq(d.Err, registry.ErrNotAFunc, "should give a func error")
|
|
|
|
|
|
- _, err := r.Register("name", "notfunc")
|
|
|
|
- assert.Eq(t, err, registry.ErrNotAFunc, "should give not a func error")
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func TestRegisterMust(t *testing.T) {
|
|
|
|
- a := assert.A(t)
|
|
|
|
|
|
+func TestRegisterErr(t *testing.T) {
|
|
r := registry.New()
|
|
r := registry.New()
|
|
|
|
|
|
- func() {
|
|
|
|
- defer func() {
|
|
|
|
- p := recover()
|
|
|
|
- a.Eq(p, registry.ErrNotAFunc, "should panic giving ErrNotAFunc")
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- r.MustRegister("name", "notfunc")
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- func() {
|
|
|
|
- defer func() {
|
|
|
|
- p := recover()
|
|
|
|
- a.Eq(p, registry.ErrNotAFunc, "should panic giving ErrNotAFunc")
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- r.MustAdd("name", "notfunc")
|
|
|
|
-
|
|
|
|
- }()
|
|
|
|
|
|
+ d := r.Add("name", "notfunc")
|
|
|
|
+ assert.Eq(t, d.Err, registry.ErrNotAFunc, "should give a func error")
|
|
}
|
|
}
|
|
|
|
|
|
/*func TestAddEntry(t *testing.T) {
|
|
/*func TestAddEntry(t *testing.T) {
|