1// Copyright 2019, The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package value
6
7import (
8	"archive/tar"
9	"math"
10	"reflect"
11	"testing"
12)
13
14func TestIsZero(t *testing.T) {
15	tests := []struct {
16		in   interface{}
17		want bool
18	}{
19		{0, true},
20		{1, false},
21		{"", true},
22		{"foo", false},
23		{[]byte(nil), true},
24		{[]byte{}, false},
25		{map[string]bool(nil), true},
26		{map[string]bool{}, false},
27		{tar.Header{}, true},
28		{&tar.Header{}, false},
29		{tar.Header{Name: "foo"}, false},
30		{(chan bool)(nil), true},
31		{make(chan bool), false},
32		{(func(*testing.T))(nil), true},
33		{TestIsZero, false},
34		{[...]int{0, 0, 0}, true},
35		{[...]int{0, 1, 0}, false},
36		{math.Copysign(0, +1), true},
37		{math.Copysign(0, -1), false},
38		{complex(math.Copysign(0, +1), math.Copysign(0, +1)), true},
39		{complex(math.Copysign(0, -1), math.Copysign(0, +1)), false},
40		{complex(math.Copysign(0, +1), math.Copysign(0, -1)), false},
41		{complex(math.Copysign(0, -1), math.Copysign(0, -1)), false},
42	}
43
44	for _, tt := range tests {
45		t.Run("", func(t *testing.T) {
46			got := IsZero(reflect.ValueOf(tt.in))
47			if got != tt.want {
48				t.Errorf("IsZero(%v) = %v, want %v", tt.in, got, tt.want)
49			}
50		})
51	}
52}
53