MCPcopy
hub / github.com/stretchr/testify / TestEmpty

Function TestEmpty

assert/assertions_test.go:1870–2050  ·  assert/assertions_test.go::TestEmpty
(t *testing.T)

Source from the content-addressed store, hash-verified

1868}
1869
1870func TestEmpty(t *testing.T) {
1871 t.Parallel()
1872
1873 mockT := new(testing.T)
1874 chWithValue := make(chan struct{}, 1)
1875 chWithValue <- struct{}{}
1876 var tiP *time.Time
1877 var tiNP time.Time
1878 var s *string
1879 var f *os.File
1880 sP := &s
1881 x := 1
1882 xP := &x
1883
1884 type TString string
1885 type TStruct struct {
1886 x int
1887 }
1888
1889 True(t, Empty(mockT, ""), "Empty string is empty")
1890 True(t, Empty(mockT, nil), "Nil is empty")
1891 True(t, Empty(mockT, []string{}), "Empty string array is empty")
1892 True(t, Empty(mockT, 0), "Zero int value is empty")
1893 True(t, Empty(mockT, false), "False value is empty")
1894 True(t, Empty(mockT, make(chan struct{})), "Channel without values is empty")
1895 True(t, Empty(mockT, s), "Nil string pointer is empty")
1896 True(t, Empty(mockT, f), "Nil os.File pointer is empty")
1897 True(t, Empty(mockT, tiP), "Nil time.Time pointer is empty")
1898 True(t, Empty(mockT, tiNP), "time.Time is empty")
1899 True(t, Empty(mockT, TStruct{}), "struct with zero values is empty")
1900 True(t, Empty(mockT, TString("")), "empty aliased string is empty")
1901 True(t, Empty(mockT, sP), "ptr to nil value is empty")
1902 True(t, Empty(mockT, [1]int{}), "array is state")
1903
1904 False(t, Empty(mockT, "something"), "Non Empty string is not empty")
1905 False(t, Empty(mockT, errors.New("something")), "Non nil object is not empty")
1906 False(t, Empty(mockT, []string{"something"}), "Non empty string array is not empty")
1907 False(t, Empty(mockT, 1), "Non-zero int value is not empty")
1908 False(t, Empty(mockT, true), "True value is not empty")
1909 False(t, Empty(mockT, chWithValue), "Channel with values is not empty")
1910 False(t, Empty(mockT, TStruct{x: 1}), "struct with initialized values is empty")
1911 False(t, Empty(mockT, TString("abc")), "non-empty aliased string is empty")
1912 False(t, Empty(mockT, xP), "ptr to non-nil value is not empty")
1913 False(t, Empty(mockT, [1]int{42}), "array is not state")
1914
1915 // error messages validation
1916 tests := []struct {
1917 name string
1918 value interface{}
1919 expectedResult bool
1920 expectedErrMsg string
1921 }{
1922 {
1923 name: "Non Empty string is not empty",
1924 value: "something",
1925 expectedResult: false,
1926 expectedErrMsg: "Should be empty, but was something\n",
1927 },

Callers

nothing calls this directly

Calls 6

TStringTypeAlias · 0.85
checkResultAndErrMsgMethod · 0.80
TrueFunction · 0.70
EmptyFunction · 0.70
FalseFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected