github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/testhelpers/matchers/be_in_display_order_test.go (about) 1 package matchers_test 2 3 import ( 4 "strings" 5 6 . "github.com/cloudfoundry/cli/testhelpers/matchers" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("BeInDisplayOrder()", func() { 13 var ( 14 matcher OmegaMatcher 15 actual []string 16 ) 17 18 actual = []string{ 19 "1st line 1", 20 "2nd line 2", 21 "3rd line 3", 22 "4th line 4", 23 } 24 25 It("asserts actual is in same display order with expected", func() { 26 matcher = BeInDisplayOrder( 27 []string{"1st"}, 28 []string{"2nd"}, 29 []string{"3rd"}, 30 []string{"4th"}, 31 ) 32 33 success, err := matcher.Match(actual) 34 Ω(success).To(Equal(true)) 35 Ω(err).To(BeNil()) 36 37 matcher = BeInDisplayOrder( 38 []string{"1st"}, 39 []string{"3rd"}, 40 []string{"2nd"}, 41 []string{"4th"}, 42 ) 43 44 success, err = matcher.Match(actual) 45 Ω(success).To(Equal(false)) 46 Ω(err).To(BeNil()) 47 msg := matcher.FailureMessage([]string{}) 48 Ω(strings.Contains(msg, "2nd")).To(Equal(true)) 49 }) 50 51 It("asserts actual contains the expected string", func() { 52 matcher = BeInDisplayOrder( 53 []string{"Not in the actual"}, 54 ) 55 56 success, err := matcher.Match(actual) 57 Ω(success).To(Equal(false)) 58 Ω(err).To(BeNil()) 59 60 msg := matcher.FailureMessage([]string{}) 61 Ω(strings.Contains(msg, "Not in the actual")).To(Equal(true)) 62 }) 63 64 It("asserts actual contains 2 substrings in the same display line ", func() { 65 matcher = BeInDisplayOrder( 66 []string{"1st", "line"}, 67 []string{"4th", "line"}, 68 ) 69 70 success, err := matcher.Match(actual) 71 Ω(success).To(Equal(true)) 72 Ω(err).To(BeNil()) 73 74 matcher = BeInDisplayOrder( 75 []string{"1st", "line 2"}, 76 ) 77 78 success, err = matcher.Match(actual) 79 Ω(success).To(Equal(false)) 80 81 msg := matcher.FailureMessage([]string{}) 82 Ω(strings.Contains(msg, "line 2")).To(Equal(true)) 83 84 matcher = BeInDisplayOrder( 85 []string{"1st"}, 86 []string{"line 1"}, 87 ) 88 89 success, err = matcher.Match(actual) 90 Ω(success).To(Equal(false)) 91 92 msg = matcher.FailureMessage([]string{}) 93 Ω(strings.Contains(msg, "line 1")).To(Equal(true)) 94 }) 95 96 It("asserts actual contains 2 substrings displaying in order on a single line ", func() { 97 matcher = BeInDisplayOrder( 98 []string{"1st", "line 1"}, 99 ) 100 101 success, err := matcher.Match(actual) 102 Ω(success).To(Equal(true)) 103 Ω(err).To(BeNil()) 104 105 matcher = BeInDisplayOrder( 106 []string{"line 1", "1st"}, 107 ) 108 109 success, err = matcher.Match(actual) 110 Ω(success).To(Equal(false)) 111 112 msg := matcher.FailureMessage([]string{}) 113 Ω(strings.Contains(msg, "1st")).To(Equal(true)) 114 }) 115 116 })