(t *testing.T)
| 962 | } |
| 963 | |
| 964 | func TestMatchRegexp_OutputsOnlyLinesMatchingRegexp(t *testing.T) { |
| 965 | t.Parallel() |
| 966 | input := "This is the first line in the file.\nHello, world.\nThis is another line in the file.\n" |
| 967 | tcs := []struct { |
| 968 | regex, want string |
| 969 | }{ |
| 970 | { |
| 971 | regex: `Hello|file`, |
| 972 | want: "This is the first line in the file.\nHello, world.\nThis is another line in the file.\n", |
| 973 | }, |
| 974 | { |
| 975 | regex: `an.ther`, |
| 976 | want: "This is another line in the file.\n", |
| 977 | }, |
| 978 | { |
| 979 | regex: `r[a-z]*s`, |
| 980 | want: "This is the first line in the file.\n", |
| 981 | }, |
| 982 | { |
| 983 | regex: `r[a-z]+s`, |
| 984 | want: "", |
| 985 | }, |
| 986 | { |
| 987 | regex: `bogus$`, |
| 988 | want: "", |
| 989 | }, |
| 990 | } |
| 991 | for _, tc := range tcs { |
| 992 | got, err := script.Echo(input).MatchRegexp(regexp.MustCompile(tc.regex)).String() |
| 993 | if err != nil { |
| 994 | t.Fatal(err) |
| 995 | } |
| 996 | if tc.want != got { |
| 997 | t.Error(cmp.Diff(tc.want, got)) |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | func TestReplaceReplacesMatchesWithSpecifiedText(t *testing.T) { |
| 1003 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…