TestSpec_PublicAPI_Map validates the documented behavior of Map as described in the sliceutil README.md specification.
(t *testing.T)
| 30 | // TestSpec_PublicAPI_Map validates the documented behavior of Map as described |
| 31 | // in the sliceutil README.md specification. |
| 32 | func TestSpec_PublicAPI_Map(t *testing.T) { |
| 33 | t.Run("applies transform to every element", func(t *testing.T) { |
| 34 | names := []string{"alice", "bob"} |
| 35 | upper := Map(names, strings.ToUpper) |
| 36 | assert.Equal(t, []string{"ALICE", "BOB"}, upper, "Map should transform all elements") |
| 37 | }) |
| 38 | |
| 39 | t.Run("does not modify input slice", func(t *testing.T) { |
| 40 | original := []string{"alice", "bob"} |
| 41 | input := make([]string, len(original)) |
| 42 | copy(input, original) |
| 43 | _ = Map(input, strings.ToUpper) |
| 44 | assert.Equal(t, original, input, "Map must not modify the input slice") |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | // TestSpec_PublicAPI_MapKeys validates the documented behavior of MapKeys |
| 49 | // as described in the sliceutil README.md specification. |