github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/testing/equal_test.go (about)

     1  package testing_test
     2  
     3  import (
     4  	"context"
     5  	t "testing"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  
     9  	"github.com/MontFerret/ferret/pkg/runtime/core"
    10  	"github.com/MontFerret/ferret/pkg/runtime/values"
    11  	"github.com/MontFerret/ferret/pkg/stdlib/testing"
    12  	"github.com/MontFerret/ferret/pkg/stdlib/testing/base"
    13  )
    14  
    15  func TestEqual(t *t.T) {
    16  	Equal := base.NewPositiveAssertion(testing.Equal)
    17  
    18  	Convey("When arg is not passed", t, func() {
    19  		Convey("It should return an error", func() {
    20  			_, err := Equal(context.Background())
    21  
    22  			So(err, ShouldBeError)
    23  
    24  			_, err = Equal(context.Background(), values.NewInt(1))
    25  
    26  			So(err, ShouldBeError)
    27  		})
    28  	})
    29  
    30  	Convey("When args are string", t, func() {
    31  		Convey("When 'Foo' and 'Bar'", func() {
    32  			Convey("It should return an error", func() {
    33  				_, err := Equal(context.Background(), values.NewString("Foo"), values.NewString("Bar"))
    34  
    35  				So(err, ShouldBeError)
    36  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [string] 'Foo' to be equal to [string] 'Bar'").Error())
    37  			})
    38  		})
    39  
    40  		Convey("When 'Foo' and 'Foo'", func() {
    41  			Convey("It should not return an error", func() {
    42  				_, err := Equal(context.Background(), values.NewString("Foo"), values.NewString("Foo"))
    43  
    44  				So(err, ShouldBeNil)
    45  			})
    46  		})
    47  	})
    48  
    49  	Convey("When args are numbers", t, func() {
    50  		Convey("When 1 and 2", func() {
    51  			Convey("It should return an error", func() {
    52  				_, err := Equal(context.Background(), values.NewInt(1), values.NewInt(2))
    53  
    54  				So(err, ShouldBeError)
    55  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [int] '1' to be equal to [int] '2'").Error())
    56  			})
    57  		})
    58  
    59  		Convey("When 1 and 1", func() {
    60  			Convey("It should not return an error", func() {
    61  				_, err := Equal(context.Background(), values.NewInt(1), values.NewInt(1))
    62  
    63  				So(err, ShouldBeNil)
    64  			})
    65  		})
    66  	})
    67  
    68  	Convey("When args are boolean", t, func() {
    69  		Convey("When False and True", func() {
    70  			Convey("It should return an error", func() {
    71  				_, err := Equal(context.Background(), values.False, values.True)
    72  
    73  				So(err, ShouldBeError)
    74  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [boolean] 'false' to be equal to [boolean] 'true'").Error())
    75  			})
    76  		})
    77  
    78  		Convey("When False and False", func() {
    79  			Convey("It should not return an error", func() {
    80  				_, err := Equal(context.Background(), values.False, values.False)
    81  
    82  				So(err, ShouldBeNil)
    83  			})
    84  		})
    85  	})
    86  
    87  	Convey("When args are arrays", t, func() {
    88  		Convey("When [1] and [1,2]", func() {
    89  			Convey("It should return an error", func() {
    90  				_, err := Equal(
    91  					context.Background(),
    92  					values.NewArrayWith(values.NewInt(1)),
    93  					values.NewArrayWith(values.NewInt(1), values.NewInt(2)),
    94  				)
    95  
    96  				So(err, ShouldBeError)
    97  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [array] '[1]' to be equal to [array] '[1,2]'").Error())
    98  			})
    99  		})
   100  
   101  		Convey("When [1,2] and [1,2]", func() {
   102  			Convey("It should not return an error", func() {
   103  				_, err := Equal(
   104  					context.Background(),
   105  					values.NewArrayWith(values.NewInt(1), values.NewInt(2)),
   106  					values.NewArrayWith(values.NewInt(1), values.NewInt(2)),
   107  				)
   108  
   109  				So(err, ShouldBeNil)
   110  			})
   111  		})
   112  	})
   113  }
   114  
   115  func TestNotEqual(t *t.T) {
   116  	NotEqual := base.NewNegativeAssertion(testing.Equal)
   117  
   118  	Convey("When arg is not passed", t, func() {
   119  		Convey("It should return an error", func() {
   120  			_, err := NotEqual(context.Background())
   121  
   122  			So(err, ShouldBeError)
   123  
   124  			_, err = NotEqual(context.Background(), values.NewInt(1))
   125  
   126  			So(err, ShouldBeError)
   127  		})
   128  	})
   129  
   130  	Convey("When args are string", t, func() {
   131  		Convey("When 'Foo' and 'Bar'", func() {
   132  			Convey("It should return an error", func() {
   133  				_, err := NotEqual(context.Background(), values.NewString("Foo"), values.NewString("Bar"))
   134  
   135  				So(err, ShouldBeNil)
   136  			})
   137  		})
   138  
   139  		Convey("When 'Foo' and 'Foo'", func() {
   140  			Convey("It should not return an error", func() {
   141  				_, err := NotEqual(context.Background(), values.NewString("Foo"), values.NewString("Foo"))
   142  
   143  				So(err, ShouldBeError)
   144  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [string] 'Foo' not to be equal to [string] 'Foo'").Error())
   145  			})
   146  		})
   147  	})
   148  
   149  	Convey("When args are numbers", t, func() {
   150  		Convey("When 1 and 2", func() {
   151  			Convey("It should return an error", func() {
   152  				_, err := NotEqual(context.Background(), values.NewInt(1), values.NewInt(2))
   153  
   154  				So(err, ShouldBeNil)
   155  			})
   156  		})
   157  
   158  		Convey("When 1 and 1", func() {
   159  			Convey("It should not return an error", func() {
   160  				_, err := NotEqual(context.Background(), values.NewInt(1), values.NewInt(1))
   161  
   162  				So(err, ShouldBeError)
   163  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [int] '1' not to be equal to [int] '1'").Error())
   164  			})
   165  		})
   166  	})
   167  
   168  	Convey("When args are boolean", t, func() {
   169  		Convey("When False and True", func() {
   170  			Convey("It should return an error", func() {
   171  				_, err := NotEqual(context.Background(), values.False, values.True)
   172  
   173  				So(err, ShouldBeNil)
   174  			})
   175  		})
   176  
   177  		Convey("When False and False", func() {
   178  			Convey("It should not return an error", func() {
   179  				_, err := NotEqual(context.Background(), values.False, values.False)
   180  
   181  				So(err, ShouldBeError)
   182  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [boolean] 'false' not to be equal to [boolean] 'false'").Error())
   183  			})
   184  		})
   185  	})
   186  
   187  	Convey("When args are arrays", t, func() {
   188  		Convey("When [1] and [1,2]", func() {
   189  			Convey("It should return an error", func() {
   190  				_, err := NotEqual(
   191  					context.Background(),
   192  					values.NewArrayWith(values.NewInt(1)),
   193  					values.NewArrayWith(values.NewInt(1), values.NewInt(2)),
   194  				)
   195  
   196  				So(err, ShouldBeNil)
   197  			})
   198  		})
   199  
   200  		Convey("When [1,2] and [1,2]", func() {
   201  			Convey("It should not return an error", func() {
   202  				_, err := NotEqual(
   203  					context.Background(),
   204  					values.NewArrayWith(values.NewInt(1), values.NewInt(2)),
   205  					values.NewArrayWith(values.NewInt(1), values.NewInt(2)),
   206  				)
   207  
   208  				So(err, ShouldBeError)
   209  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [array] '[1,2]' not to be equal to [array] '[1,2]'").Error())
   210  			})
   211  		})
   212  	})
   213  }