ReAll operator allows to successively apply a regexp on a string
(or convertible), []byte, error or fmt.Stringer interface (error
interface is tested before fmt.Stringer) and to match its groups
contents.
capture is used to match the contents of regexp groups. Groups
are presented as a []string or [][]byte depending the original
matched data. Note that an other operator can be used here.
t:=&testing.T{}got:="foo bar biz"ok:=td.Cmp(t,got,td.ReAll(`(\w+)`,td.Set("biz","foo","bar")),"checks value %s",got)fmt.Println(ok)// Matches, but all catured groups do not match Setgot="foo BAR biz"ok=td.Cmp(t,got,td.ReAll(`(\w+)`,td.Set("biz","foo","bar")),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CaptureComplex example
t:=&testing.T{}got:="11 45 23 56 85 96"ok:=td.Cmp(t,got,td.ReAll(`(\d+)`,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>10&&n<100}))),"checks value %s",got)fmt.Println(ok)// Matches, but 11 is not greater than 20ok=td.Cmp(t,got,td.ReAll(`(\d+)`,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>20&&n<100}))),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CompiledCapture example
t:=&testing.T{}expected:=regexp.MustCompile(`(\w+)`)got:="foo bar biz"ok:=td.Cmp(t,got,td.ReAll(expected,td.Set("biz","foo","bar")),"checks value %s",got)fmt.Println(ok)// Matches, but all catured groups do not match Setgot="foo BAR biz"ok=td.Cmp(t,got,td.ReAll(expected,td.Set("biz","foo","bar")),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CompiledCaptureComplex example
t:=&testing.T{}expected:=regexp.MustCompile(`(\d+)`)got:="11 45 23 56 85 96"ok:=td.Cmp(t,got,td.ReAll(expected,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>10&&n<100}))),"checks value %s",got)fmt.Println(ok)// Matches, but 11 is not greater than 20ok=td.Cmp(t,got,td.ReAll(expected,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>20&&n<100}))),"checks value %s",got)fmt.Println(ok)// Output:// true// false
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=&testing.T{}got:="foo bar biz"ok:=td.CmpReAll(t,got,`(\w+)`,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Matches, but all catured groups do not match Setgot="foo BAR biz"ok=td.CmpReAll(t,got,`(\w+)`,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CaptureComplex example
t:=&testing.T{}got:="11 45 23 56 85 96"ok:=td.CmpReAll(t,got,`(\d+)`,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>10&&n<100})),"checks value %s",got)fmt.Println(ok)// Matches, but 11 is not greater than 20ok=td.CmpReAll(t,got,`(\d+)`,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>20&&n<100})),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CompiledCapture example
t:=&testing.T{}expected:=regexp.MustCompile(`(\w+)`)got:="foo bar biz"ok:=td.CmpReAll(t,got,expected,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Matches, but all catured groups do not match Setgot="foo BAR biz"ok=td.CmpReAll(t,got,expected,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CompiledCaptureComplex example
t:=&testing.T{}expected:=regexp.MustCompile(`(\d+)`)got:="11 45 23 56 85 96"ok:=td.CmpReAll(t,got,expected,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>10&&n<100})),"checks value %s",got)fmt.Println(ok)// Matches, but 11 is not greater than 20ok=td.CmpReAll(t,got,expected,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>20&&n<100})),"checks value %s",got)fmt.Println(ok)// Output:// true// false
T.ReAll shortcut
func(t*T)ReAll(got,reg,captureany,args...any)bool
ReAll is a shortcut for:
t.Cmp(got,td.ReAll(reg,capture),args...)
See above for details.
Returns true if the test is OK, false if it fails.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=td.NewT(&testing.T{})got:="foo bar biz"ok:=t.ReAll(got,`(\w+)`,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Matches, but all catured groups do not match Setgot="foo BAR biz"ok=t.ReAll(got,`(\w+)`,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CaptureComplex example
t:=td.NewT(&testing.T{})got:="11 45 23 56 85 96"ok:=t.ReAll(got,`(\d+)`,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>10&&n<100})),"checks value %s",got)fmt.Println(ok)// Matches, but 11 is not greater than 20ok=t.ReAll(got,`(\d+)`,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>20&&n<100})),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CompiledCapture example
t:=td.NewT(&testing.T{})expected:=regexp.MustCompile(`(\w+)`)got:="foo bar biz"ok:=t.ReAll(got,expected,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Matches, but all catured groups do not match Setgot="foo BAR biz"ok=t.ReAll(got,expected,td.Set("biz","foo","bar"),"checks value %s",got)fmt.Println(ok)// Output:// true// false
CompiledCaptureComplex example
t:=td.NewT(&testing.T{})expected:=regexp.MustCompile(`(\d+)`)got:="11 45 23 56 85 96"ok:=t.ReAll(got,expected,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>10&&n<100})),"checks value %s",got)fmt.Println(ok)// Matches, but 11 is not greater than 20ok=t.ReAll(got,expected,td.ArrayEach(td.Code(func(numstring)bool{n,err:=strconv.Atoi(num)returnerr==nil&&n>20&&n<100})),"checks value %s",got)fmt.Println(ok)// Output:// true// false