MCPcopy Index your code
hub / github.com/bitfield/script / TestReplaceReplacesMatchesWithSpecifiedText

Function TestReplaceReplacesMatchesWithSpecifiedText

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

Source from the content-addressed store, hash-verified

1000}
1001
1002func TestReplaceReplacesMatchesWithSpecifiedText(t *testing.T) {
1003 t.Parallel()
1004 input := "hello world"
1005 tcs := []struct {
1006 search, replace, want string
1007 }{
1008 {
1009 search: "hello",
1010 replace: "bye",
1011 want: "bye world\n",
1012 },
1013 {
1014 search: "Does not exist in input",
1015 replace: "Will not appear in output",
1016 want: "hello world\n",
1017 },
1018 {
1019 search: " world",
1020 replace: " string with newline\n",
1021 want: "hello string with newline\n\n",
1022 },
1023 {
1024 search: "hello",
1025 replace: "Ж9",
1026 want: "Ж9 world\n",
1027 },
1028 }
1029 for _, tc := range tcs {
1030 got, err := script.Echo(input).Replace(tc.search, tc.replace).String()
1031 if err != nil {
1032 t.Fatal(err)
1033 }
1034 if tc.want != got {
1035 t.Error(cmp.Diff(tc.want, got))
1036 }
1037 }
1038}
1039
1040func TestReplaceRegexp_ReplacesMatchesWithSpecifiedText(t *testing.T) {
1041 t.Parallel()

Callers

nothing calls this directly

Calls 4

EchoFunction · 0.92
StringMethod · 0.80
ReplaceMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…