(t *testing.T)
| 1038 | } |
| 1039 | |
| 1040 | func TestReplaceRegexp_ReplacesMatchesWithSpecifiedText(t *testing.T) { |
| 1041 | t.Parallel() |
| 1042 | input := "hello world" |
| 1043 | tcs := []struct { |
| 1044 | regex, replace, want string |
| 1045 | }{ |
| 1046 | { |
| 1047 | regex: "hel+o", |
| 1048 | replace: "bye", |
| 1049 | want: "bye world\n", |
| 1050 | }, |
| 1051 | { |
| 1052 | regex: "Does not .* in input", |
| 1053 | replace: "Will not appear in output", |
| 1054 | want: "hello world\n", |
| 1055 | }, |
| 1056 | { |
| 1057 | regex: "^([a-z]+) ([a-z]+)", |
| 1058 | replace: "$1 cruel $2", |
| 1059 | want: "hello cruel world\n", |
| 1060 | }, |
| 1061 | { |
| 1062 | regex: "hello{1}", |
| 1063 | replace: "Ж9", |
| 1064 | want: "Ж9 world\n", |
| 1065 | }, |
| 1066 | } |
| 1067 | for _, tc := range tcs { |
| 1068 | got, err := script.Echo(input).ReplaceRegexp(regexp.MustCompile(tc.regex), tc.replace).String() |
| 1069 | if err != nil { |
| 1070 | t.Fatal(err) |
| 1071 | } |
| 1072 | if tc.want != got { |
| 1073 | t.Error(cmp.Diff(tc.want, got)) |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | func TestRejectDropsMatchingLinesFromInput(t *testing.T) { |
| 1079 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…