Skip to content

Commit

Permalink
match without result (#25)
Browse files Browse the repository at this point in the history
* match without result

* fix
  • Loading branch information
alexpantyukhin authored Sep 19, 2019
1 parent ba44840 commit 25c72c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion match.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ func (matcher *Matcher) Result() (bool, interface{}) {
params = append(params, reflect.ValueOf(matchedItems[i]))
}

return true, reflect.ValueOf(mi.action).Call(params)[0].Interface()
funcRes := reflect.ValueOf(mi.action).Call(params)
if (len(funcRes)) > 0 {
return true, funcRes[0].Interface()
}

return true, nil
}

return true, mi.action
Expand Down
6 changes: 6 additions & 0 deletions match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func TestMatch_Fibonacci(t *testing.T) {
assert.Equal(t, 21, fib(8))
}

func TestMatch_MatchWithoutResult(t *testing.T){
Match(10).
When(10, func() { assert.True(t, true) }).
Result()
}

func TestMatch_SimpleTypeIntWithFunc(t *testing.T) {
_, res := Match(42).
When(42, func() interface{} { return 84 }).
Expand Down

0 comments on commit 25c72c4

Please sign in to comment.