|
@@ -7,19 +7,6 @@ import (
|
|
|
. "flow/internal/check"
|
|
|
)
|
|
|
|
|
|
-func TestRegistryGet(t *testing.T) {
|
|
|
- expect := Expect(t)
|
|
|
-
|
|
|
- r := registry.New()
|
|
|
- r.Register("vecadd", dummy1)
|
|
|
-
|
|
|
- fn, err := r.Get("vecadd")
|
|
|
-
|
|
|
- expect.NotErr(err)
|
|
|
- expect.Diff(nil, fn)
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
func TestRegistry(t *testing.T) {
|
|
|
expect := Expect(t)
|
|
|
|
|
@@ -37,6 +24,104 @@ func TestRegistry(t *testing.T) {
|
|
|
t.Log(d)
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+func TestEntry(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ e, err := r.Entry("bogus")
|
|
|
+ exp.Err(err)
|
|
|
+ exp.Eq(e, nil)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func TestRegister(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ e := r.Register("func", func(a, b int) int { return 0 })
|
|
|
+ exp.NotErr(e.Err())
|
|
|
+}
|
|
|
+func TestRegisterDuplicate(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ r.Register("func", func(a, b int) int { return 0 })
|
|
|
+ e := r.Register("func", func(b int) int { return 0 })
|
|
|
+ exp.NotErr(e.Err())
|
|
|
+}
|
|
|
+func TestRegisterInvalidOutput(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ e := r.Register("func", func(a int) {})
|
|
|
+ exp.Eq(e.Err(), registry.ErrOutput)
|
|
|
+}
|
|
|
+
|
|
|
+func TestRegisterInvalidInput(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ e := r.Register("func", func() int { return 0 })
|
|
|
+
|
|
|
+ exp.NotErr(e.Err())
|
|
|
+}
|
|
|
+
|
|
|
+func TestRegistryGet(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ e := r.Register("func", func() int { return 0 })
|
|
|
+ exp.NotErr(e.Err())
|
|
|
+
|
|
|
+ fn, err := r.Get("func")
|
|
|
+ exp.NotErr(err)
|
|
|
+ exp.NotNil(fn)
|
|
|
+}
|
|
|
+
|
|
|
+func TestRegistryGetEmpty(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ fn, err := r.Get("notfoundfunc")
|
|
|
+ exp.Eq(err, registry.ErrNotFound)
|
|
|
+ exp.Eq(fn, nil)
|
|
|
+}
|
|
|
+func TestRegistryGetConstructor(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+ e := r.Register("func", func() func() int {
|
|
|
+ return func() int {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ })
|
|
|
+ exp.NotErr(e.Err())
|
|
|
+
|
|
|
+ ifn, err := r.Get("func")
|
|
|
+ exp.NotErr(err)
|
|
|
+
|
|
|
+ fn, ok := ifn.(func() int)
|
|
|
+ exp.Eq(ok, true)
|
|
|
+
|
|
|
+ ret := fn()
|
|
|
+ exp.Eq(ret, 0)
|
|
|
+
|
|
|
+}
|
|
|
+func TestRegistryGetConstructorParam(t *testing.T) {
|
|
|
+ exp := Expect(t)
|
|
|
+ r := registry.New()
|
|
|
+
|
|
|
+ e := r.Register("func2", func(a, b int) func() int {
|
|
|
+ return func() int {
|
|
|
+ return a + b
|
|
|
+ }
|
|
|
+ })
|
|
|
+ exp.NotErr(e.Err())
|
|
|
+ ifn, err := r.Get("func2", 1, 1)
|
|
|
+ exp.NotErr(err)
|
|
|
+ exp.NotNil(ifn)
|
|
|
+
|
|
|
+ fn, ok := ifn.(func() int)
|
|
|
+ exp.Eq(ok, true)
|
|
|
+
|
|
|
+ ret := fn()
|
|
|
+ exp.Eq(ret, 2)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
func TestDescriptions(t *testing.T) {
|
|
|
expect := Expect(t)
|
|
|
|
|
@@ -46,7 +131,7 @@ func TestDescriptions(t *testing.T) {
|
|
|
|
|
|
d, err := r.Descriptions()
|
|
|
expect.NotErr(err)
|
|
|
- expect.Eq(2, len(d))
|
|
|
+ expect.Eq(len(d), 2)
|
|
|
|
|
|
t.Log(d)
|
|
|
|