(t *testing.T, useStdin, raw bool)
| 739 | } |
| 740 | |
| 741 | func testFilterForEachLine(t *testing.T, useStdin, raw bool) { |
| 742 | file := testFile(t, `; comment |
| 743 | one |
| 744 | # another comment |
| 745 | |
| 746 | |
| 747 | two |
| 748 | # indented comment |
| 749 | three |
| 750 | four |
| 751 | five |
| 752 | six `) |
| 753 | defer func() { |
| 754 | err := os.Remove(file) |
| 755 | require.NoError(t, err) |
| 756 | }() |
| 757 | lines := []string{} |
| 758 | fileName := file |
| 759 | if useStdin { |
| 760 | in, err := os.Open(file) |
| 761 | require.NoError(t, err) |
| 762 | oldStdin := os.Stdin |
| 763 | os.Stdin = in |
| 764 | defer func() { |
| 765 | os.Stdin = oldStdin |
| 766 | _ = in.Close() |
| 767 | }() |
| 768 | fileName = "-" |
| 769 | } |
| 770 | err := forEachLine(fileName, raw, func(s string) error { |
| 771 | lines = append(lines, s) |
| 772 | return nil |
| 773 | }) |
| 774 | require.NoError(t, err) |
| 775 | if raw { |
| 776 | assert.Equal(t, "; comment,one,# another comment,,,two, # indented comment,three ,four ,five, six ", |
| 777 | strings.Join(lines, ",")) |
| 778 | } else { |
| 779 | assert.Equal(t, "one,two,three,four,five,six", strings.Join(lines, ",")) |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | func TestFilterForEachLine(t *testing.T) { |
| 784 | testFilterForEachLine(t, false, false) |
no test coverage detected
searching dependent graphs…