| 921 | } |
| 922 | |
| 923 | func TestMatchOutputsOnlyMatchingLinesOfInput(t *testing.T) { |
| 924 | t.Parallel() |
| 925 | input := "This is the first line in the file.\nHello, world.\nThis is another line in the file.\n" |
| 926 | tcs := []struct { |
| 927 | match, want string |
| 928 | }{ |
| 929 | { |
| 930 | match: "line", |
| 931 | want: "This is the first line in the file.\nThis is another line in the file.\n", |
| 932 | }, |
| 933 | { |
| 934 | match: "another", |
| 935 | want: "This is another line in the file.\n", |
| 936 | }, |
| 937 | { |
| 938 | match: "definitely won't match any lines", |
| 939 | want: "", |
| 940 | }, |
| 941 | } |
| 942 | for _, tc := range tcs { |
| 943 | got, err := script.Echo(input).Match(tc.match).String() |
| 944 | if err != nil { |
| 945 | t.Fatal(err) |
| 946 | } |
| 947 | if tc.want != got { |
| 948 | t.Error(cmp.Diff(tc.want, got)) |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | func TestMatchOutputsNothingGivenEmptyInput(t *testing.T) { |
| 954 | t.Parallel() |