(t *testing.T)
| 1724 | } |
| 1725 | |
| 1726 | func TestArray_Transform(t *testing.T) { |
| 1727 | t.Run("check index", func(t *testing.T) { |
| 1728 | reporter := newMockReporter(t) |
| 1729 | array := NewArray(reporter, []interface{}{1, 2, 3}) |
| 1730 | |
| 1731 | newArray := array.Transform(func(idx int, val interface{}) interface{} { |
| 1732 | if v, ok := val.(float64); ok { |
| 1733 | assert.Equal(t, idx, int(v)-1) |
| 1734 | } |
| 1735 | return val |
| 1736 | }) |
| 1737 | |
| 1738 | assert.Equal(t, []interface{}{float64(1), float64(2), float64(3)}, newArray.value) |
| 1739 | newArray.chain.assert(t, success) |
| 1740 | }) |
| 1741 | |
| 1742 | t.Run("transform value", func(t *testing.T) { |
| 1743 | reporter := newMockReporter(t) |
| 1744 | array := NewArray(reporter, []interface{}{2, 4, 6}) |
| 1745 | |
| 1746 | newArray := array.Transform(func(_ int, val interface{}) interface{} { |
| 1747 | if v, ok := val.(float64); ok { |
| 1748 | return int(v) * int(v) |
| 1749 | } |
| 1750 | t.Errorf("failed transformation") |
| 1751 | return nil |
| 1752 | }) |
| 1753 | |
| 1754 | assert.Equal(t, []interface{}{float64(4), float64(16), float64(36)}, newArray.value) |
| 1755 | newArray.chain.assert(t, success) |
| 1756 | }) |
| 1757 | |
| 1758 | t.Run("empty array", func(t *testing.T) { |
| 1759 | reporter := newMockReporter(t) |
| 1760 | array := NewArray(reporter, []interface{}{}) |
| 1761 | |
| 1762 | newArray := array.Transform(func(_ int, _ interface{}) interface{} { |
| 1763 | t.Errorf("failed transformation") |
| 1764 | return nil |
| 1765 | }) |
| 1766 | |
| 1767 | newArray.chain.assert(t, success) |
| 1768 | }) |
| 1769 | |
| 1770 | t.Run("invalid argument", func(t *testing.T) { |
| 1771 | reporter := newMockReporter(t) |
| 1772 | array := NewArray(reporter, []interface{}{2, 4, 6}) |
| 1773 | |
| 1774 | newArray := array.Transform(nil) |
| 1775 | |
| 1776 | newArray.chain.assert(t, failure) |
| 1777 | }) |
| 1778 | |
| 1779 | t.Run("canonization", func(t *testing.T) { |
| 1780 | type ( |
| 1781 | myInt int |
| 1782 | ) |
| 1783 |
nothing calls this directly
no test coverage detected
searching dependent graphs…