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

Function TestMatchRegexp_OutputsOnlyLinesMatchingRegexp

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

Source from the content-addressed store, hash-verified

962}
963
964func 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
1002func TestReplaceReplacesMatchesWithSpecifiedText(t *testing.T) {
1003 t.Parallel()

Callers

nothing calls this directly

Calls 4

EchoFunction · 0.92
StringMethod · 0.80
MatchRegexpMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…