| 1621 | } |
| 1622 | |
| 1623 | func TestSliceSink_(t *testing.T) { |
| 1624 | t.Parallel() |
| 1625 | tests := []struct { |
| 1626 | name string |
| 1627 | pipe *script.Pipe |
| 1628 | want []string |
| 1629 | }{ |
| 1630 | { |
| 1631 | name: "returns three elements for three lines of input", |
| 1632 | pipe: script.Echo("testdata/multiple_files/1.txt\ntestdata/multiple_files/2.txt\ntestdata/multiple_files/3.tar.zip\n"), |
| 1633 | want: []string{ |
| 1634 | "testdata/multiple_files/1.txt", |
| 1635 | "testdata/multiple_files/2.txt", |
| 1636 | "testdata/multiple_files/3.tar.zip", |
| 1637 | }, |
| 1638 | }, |
| 1639 | { |
| 1640 | name: "returns an empty slice given empty input", |
| 1641 | pipe: script.Echo(""), |
| 1642 | want: []string{}, |
| 1643 | }, |
| 1644 | { |
| 1645 | name: "returns one empty string given input containing a single newline", |
| 1646 | pipe: script.Echo("\n"), |
| 1647 | want: []string{""}, |
| 1648 | }, |
| 1649 | { |
| 1650 | name: "returns an empty string for each empty input line", |
| 1651 | pipe: script.Echo("testdata/multiple_files/1.txt\n\ntestdata/multiple_files/3.tar.zip"), |
| 1652 | want: []string{ |
| 1653 | "testdata/multiple_files/1.txt", |
| 1654 | "", |
| 1655 | "testdata/multiple_files/3.tar.zip", |
| 1656 | }, |
| 1657 | }, |
| 1658 | } |
| 1659 | for _, tt := range tests { |
| 1660 | t.Run(tt.name, func(t *testing.T) { |
| 1661 | p := tt.pipe |
| 1662 | got, err := p.Slice() |
| 1663 | if err != nil { |
| 1664 | t.Fatal(err) |
| 1665 | } |
| 1666 | if !cmp.Equal(tt.want, got) { |
| 1667 | t.Error(cmp.Diff(tt.want, got)) |
| 1668 | } |
| 1669 | }) |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | func TestStringOutputsInputStringUnchanged(t *testing.T) { |
| 1674 | t.Parallel() |