defaultifempty_test.go 520 B

12345678910111213141516171819202122232425
  1. package help
  2. import (
  3. "testing"
  4. )
  5. func TestDefaultIfEmpty(t *testing.T) {
  6. defaultValue := 0
  7. tests := []struct {
  8. input []interface{}
  9. want []interface{}
  10. }{
  11. {[]interface{}{}, []interface{}{defaultValue}},
  12. {[]interface{}{1, 2, 3, 4, 5}, []interface{}{1, 2, 3, 4, 5}},
  13. }
  14. for _, test := range tests {
  15. q := From(test.input).DefaultIfEmpty(defaultValue)
  16. if !validateQuery(q, test.want) {
  17. t.Errorf("From(%v).DefaultIfEmpty(%v)=%v expected %v", test.input, defaultValue, toSlice(q), test.want)
  18. }
  19. }
  20. }