(t *testing.T)
| 662 | } |
| 663 | |
| 664 | func TestIsEmptyValue(t *testing.T) { |
| 665 | str := "string" |
| 666 | tests := []struct { |
| 667 | value interface{} |
| 668 | empty bool |
| 669 | }{ |
| 670 | // slices, arrays, and maps |
| 671 | {[]int{}, true}, |
| 672 | {[]int{0}, false}, |
| 673 | {[0]int{}, true}, |
| 674 | {[3]int{}, false}, |
| 675 | {[3]int{1}, false}, |
| 676 | {map[string]string{}, true}, |
| 677 | {map[string]string{"a": "b"}, false}, |
| 678 | |
| 679 | // strings |
| 680 | {"", true}, |
| 681 | {" ", false}, |
| 682 | {"a", false}, |
| 683 | |
| 684 | // bool |
| 685 | {true, false}, |
| 686 | {false, true}, |
| 687 | |
| 688 | // ints of various types |
| 689 | {(int)(0), true}, {(int)(1), false}, {(int)(-1), false}, |
| 690 | {(int8)(0), true}, {(int8)(1), false}, {(int8)(-1), false}, |
| 691 | {(int16)(0), true}, {(int16)(1), false}, {(int16)(-1), false}, |
| 692 | {(int32)(0), true}, {(int32)(1), false}, {(int32)(-1), false}, |
| 693 | {(int64)(0), true}, {(int64)(1), false}, {(int64)(-1), false}, |
| 694 | {(uint)(0), true}, {(uint)(1), false}, |
| 695 | {(uint8)(0), true}, {(uint8)(1), false}, |
| 696 | {(uint16)(0), true}, {(uint16)(1), false}, |
| 697 | {(uint32)(0), true}, {(uint32)(1), false}, |
| 698 | {(uint64)(0), true}, {(uint64)(1), false}, |
| 699 | |
| 700 | // floats |
| 701 | {(float32)(0), true}, {(float32)(0.0), true}, {(float32)(0.1), false}, |
| 702 | {(float64)(0), true}, {(float64)(0.0), true}, {(float64)(0.1), false}, |
| 703 | |
| 704 | // pointers |
| 705 | {(*int)(nil), true}, |
| 706 | {new([]int), false}, |
| 707 | {&str, false}, |
| 708 | |
| 709 | // time |
| 710 | {time.Time{}, true}, |
| 711 | {time.Now(), false}, |
| 712 | |
| 713 | // unknown type - always false unless a nil pointer, which are always empty. |
| 714 | {(*struct{ int })(nil), true}, |
| 715 | {struct{ int }{}, false}, |
| 716 | {struct{ int }{0}, false}, |
| 717 | {struct{ int }{1}, false}, |
| 718 | } |
| 719 | |
| 720 | for _, tt := range tests { |
| 721 | got := isEmptyValue(reflect.ValueOf(tt.value)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…