github.com/cloudfoundry-attic/ltc@v0.0.0-20151123212628-098adc7919fc/test_helpers/regex_safe_say.go (about) 1 package test_helpers 2 3 import ( 4 "fmt" 5 "regexp" 6 7 "github.com/onsi/gomega/gbytes" 8 "github.com/onsi/gomega/types" 9 ) 10 11 func Say(expected string, args ...interface{}) types.GomegaMatcher { 12 return gbytes.Say(regexSafe(expected), args...) 13 } 14 15 func SayLine(expected string, args ...interface{}) types.GomegaMatcher { 16 return gbytes.Say(regexSafe(expected)+"\n", args...) 17 } 18 19 func SayNewLine() types.GomegaMatcher { 20 return Say("\n") 21 } 22 23 func SayIncorrectUsage() types.GomegaMatcher { 24 return gbytes.Say(regexSafe("Incorrect Usage")) 25 } 26 27 var regex = regexp.MustCompile("[-/\\\\^$*+?.()|[\\]{}]") 28 29 func regexSafe(matcher string) string { 30 return regex.ReplaceAllStringFunc(matcher, func(s string) string { 31 return fmt.Sprintf("\\%s", s) 32 }) 33 }