github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/funcmap/funcmap_test.go (about)

     1  package funcmap
     2  
     3  import (
     4      "testing"
     5  )
     6  
     7  var (
     8      testcases = map[string]interface{}{
     9          "hello": func() {print("hello")},
    10          "foobar": func(a, b, c int) int {return a+b+c},
    11          "errstring": "Can not call this as a function",
    12          "errnumeric": 123456789,
    13      }
    14      funcs = NewFuncs(100)
    15  )
    16  
    17  func TestBind(t *testing.T) {
    18      for k, v := range testcases {
    19          err := funcs.Bind(k, v)
    20          if k[:3] == "err" {
    21              if err == nil {
    22                  t.Error("Bind %s: %s", k, "an error should be paniced.")
    23              }
    24          } else {
    25              if err != nil {
    26                  t.Error("Bind %s: %s", k, err)
    27              }
    28          }
    29      }
    30  }
    31  
    32  func TestCall(t *testing.T) {
    33      if _, err := funcs.Call("foobar"); err == nil {
    34          t.Error("Call %s: %s", "foobar", "an error should be paniced.")
    35      }
    36      if _, err := funcs.Call("foobar", 0, 1, 2); err != nil {
    37          t.Error("Call %s: %s", "foobar", err)
    38      }
    39      if _, err := funcs.Call("errstring", 0, 1, 2); err == nil {
    40          t.Error("Call %s: %s", "errstring", "an error should be paniced.")
    41      }
    42  }