MCPcopy
hub / github.com/bitfield/script / TestReplaceRegexp_ReplacesMatchesWithSpecifiedText

Function TestReplaceRegexp_ReplacesMatchesWithSpecifiedText

script_test.go:1040–1076  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1038}
1039
1040func 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
1078func TestRejectDropsMatchingLinesFromInput(t *testing.T) {
1079 t.Parallel()

Callers

nothing calls this directly

Calls 4

EchoFunction · 0.92
StringMethod · 0.80
ReplaceRegexpMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…