github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/util/testhelpers/matchers/be_in_display_order_test.go (about)

     1  package matchers_test
     2  
     3  import (
     4  	"strings"
     5  
     6  	. "code.cloudfoundry.org/cli/cf/util/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  		Expect(err).ToNot(HaveOccurred())
    35  		Expect(success).To(Equal(true))
    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  		Expect(err).ToNot(HaveOccurred())
    46  		Expect(success).To(Equal(false))
    47  		msg := matcher.FailureMessage([]string{})
    48  		Expect(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  		Expect(err).ToNot(HaveOccurred())
    58  		Expect(success).To(Equal(false))
    59  
    60  		msg := matcher.FailureMessage([]string{})
    61  		Expect(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  		Expect(err).ToNot(HaveOccurred())
    72  		Expect(success).To(Equal(true))
    73  
    74  		matcher = BeInDisplayOrder(
    75  			[]string{"1st", "line 2"},
    76  		)
    77  
    78  		success, err = matcher.Match(actual)
    79  		Expect(err).ToNot(HaveOccurred())
    80  		Expect(success).To(Equal(false))
    81  
    82  		msg := matcher.FailureMessage([]string{})
    83  		Expect(strings.Contains(msg, "line 2")).To(Equal(true))
    84  
    85  		matcher = BeInDisplayOrder(
    86  			[]string{"1st"},
    87  			[]string{"line 1"},
    88  		)
    89  
    90  		success, err = matcher.Match(actual)
    91  		Expect(err).ToNot(HaveOccurred())
    92  		Expect(success).To(Equal(false))
    93  
    94  		msg = matcher.FailureMessage([]string{})
    95  		Expect(strings.Contains(msg, "line 1")).To(Equal(true))
    96  	})
    97  
    98  	It("asserts actual contains 2 substrings displaying in order on a single line ", func() {
    99  		matcher = BeInDisplayOrder(
   100  			[]string{"1st", "line 1"},
   101  		)
   102  
   103  		success, err := matcher.Match(actual)
   104  		Expect(err).ToNot(HaveOccurred())
   105  		Expect(success).To(Equal(true))
   106  
   107  		matcher = BeInDisplayOrder(
   108  			[]string{"line 1", "1st"},
   109  		)
   110  
   111  		success, err = matcher.Match(actual)
   112  		Expect(err).ToNot(HaveOccurred())
   113  		Expect(success).To(Equal(false))
   114  
   115  		msg := matcher.FailureMessage([]string{})
   116  		Expect(strings.Contains(msg, "1st")).To(Equal(true))
   117  	})
   118  })