initial commit
[govpp.git] / vendor / github.com / onsi / gomega / matchers / match_regexp_matcher_test.go
1 package matchers_test
2
3 import (
4         . "github.com/onsi/ginkgo"
5         . "github.com/onsi/gomega"
6         . "github.com/onsi/gomega/matchers"
7 )
8
9 var _ = Describe("MatchRegexp", func() {
10         Context("when actual is a string", func() {
11                 It("should match against the string", func() {
12                         Ω(" a2!bla").Should(MatchRegexp(`\d!`))
13                         Ω(" a2!bla").ShouldNot(MatchRegexp(`[A-Z]`))
14                 })
15         })
16
17         Context("when actual is a stringer", func() {
18                 It("should call the stringer and match agains the returned string", func() {
19                         Ω(&myStringer{a: "Abc3"}).Should(MatchRegexp(`[A-Z][a-z]+\d`))
20                 })
21         })
22
23         Context("when the matcher is called with multiple arguments", func() {
24                 It("should pass the string and arguments to sprintf", func() {
25                         Ω(" a23!bla").Should(MatchRegexp(`\d%d!`, 3))
26                 })
27         })
28
29         Context("when actual is neither a string nor a stringer", func() {
30                 It("should error", func() {
31                         success, err := (&MatchRegexpMatcher{Regexp: `\d`}).Match(2)
32                         Ω(success).Should(BeFalse())
33                         Ω(err).Should(HaveOccurred())
34                 })
35         })
36
37         Context("when the passed in regexp fails to compile", func() {
38                 It("should error", func() {
39                         success, err := (&MatchRegexpMatcher{Regexp: "("}).Match("Foo")
40                         Ω(success).Should(BeFalse())
41                         Ω(err).Should(HaveOccurred())
42                 })
43         })
44 })