| 1000 | } |
| 1001 | |
| 1002 | func 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 | |
| 1040 | func TestReplaceRegexp_ReplacesMatchesWithSpecifiedText(t *testing.T) { |
| 1041 | t.Parallel() |