(t *testing.T)
| 1884 | } |
| 1885 | |
| 1886 | func TestArray_Find(t *testing.T) { |
| 1887 | t.Run("elements of same type", func(t *testing.T) { |
| 1888 | reporter := newMockReporter(t) |
| 1889 | array := NewArray(reporter, []interface{}{1, 2, 3, 4, 5, 6}) |
| 1890 | |
| 1891 | foundValue := array.Find(func(index int, value *Value) bool { |
| 1892 | return value.Raw() == 2.0 |
| 1893 | }) |
| 1894 | |
| 1895 | assert.Equal(t, 2.0, foundValue.Raw()) |
| 1896 | assert.Equal(t, array.Raw(), []interface{}{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}) |
| 1897 | |
| 1898 | array.chain.assert(t, success) |
| 1899 | foundValue.chain.assert(t, success) |
| 1900 | }) |
| 1901 | |
| 1902 | t.Run("elements of different types", func(t *testing.T) { |
| 1903 | reporter := newMockReporter(t) |
| 1904 | array := NewArray(reporter, []interface{}{1, "foo", true, "bar"}) |
| 1905 | |
| 1906 | foundValue := array.Find(func(index int, value *Value) bool { |
| 1907 | stringifiedValue := value.String().NotEmpty().Raw() |
| 1908 | return stringifiedValue == "bar" |
| 1909 | }) |
| 1910 | |
| 1911 | assert.Equal(t, "bar", foundValue.Raw()) |
| 1912 | assert.Equal(t, array.Raw(), []interface{}{1.0, "foo", true, "bar"}) |
| 1913 | |
| 1914 | array.chain.assert(t, success) |
| 1915 | foundValue.chain.assert(t, success) |
| 1916 | }) |
| 1917 | |
| 1918 | t.Run("first match", func(t *testing.T) { |
| 1919 | reporter := newMockReporter(t) |
| 1920 | array := NewArray(reporter, []interface{}{1, "foo", true, "bar"}) |
| 1921 | |
| 1922 | foundValue := array.Find(func(index int, value *Value) bool { |
| 1923 | stringifiedValue := value.String().Raw() |
| 1924 | return stringifiedValue != "" |
| 1925 | }) |
| 1926 | |
| 1927 | assert.Equal(t, "foo", foundValue.Raw()) |
| 1928 | assert.Equal(t, array.Raw(), []interface{}{1.0, "foo", true, "bar"}) |
| 1929 | |
| 1930 | array.chain.assert(t, success) |
| 1931 | foundValue.chain.assert(t, success) |
| 1932 | }) |
| 1933 | |
| 1934 | t.Run("no match", func(t *testing.T) { |
| 1935 | reporter := newMockReporter(t) |
| 1936 | array := NewArray(reporter, []interface{}{1, "foo", true, "bar"}) |
| 1937 | |
| 1938 | foundValue := array.Find(func(index int, value *Value) bool { |
| 1939 | return value.Raw() == 2.0 |
| 1940 | }) |
| 1941 | |
| 1942 | assert.Equal(t, nil, foundValue.Raw()) |
| 1943 | assert.Equal(t, array.Raw(), []interface{}{1.0, "foo", true, "bar"}) |
nothing calls this directly
no test coverage detected
searching dependent graphs…