github.com/MontFerret/ferret@v0.18.0/pkg/compiler/compiler_in_test.go (about)

     1  package compiler_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  
     9  	"github.com/MontFerret/ferret/pkg/compiler"
    10  )
    11  
    12  func TestInOperator(t *testing.T) {
    13  	Convey("1 IN [1,2,3] should return true", t, func() {
    14  		c := compiler.New()
    15  
    16  		p, err := c.Compile(`
    17  			RETURN 1 IN [1,2,3]
    18  		`)
    19  
    20  		So(err, ShouldBeNil)
    21  
    22  		out, err := p.Run(context.Background())
    23  
    24  		So(err, ShouldBeNil)
    25  		So(string(out), ShouldEqual, `true`)
    26  	})
    27  
    28  	Convey("4 IN [1,2,3] should return false", t, func() {
    29  		c := compiler.New()
    30  
    31  		p, err := c.Compile(`
    32  			RETURN 4 IN [1,2,3]
    33  		`)
    34  
    35  		So(err, ShouldBeNil)
    36  
    37  		out, err := p.Run(context.Background())
    38  
    39  		So(err, ShouldBeNil)
    40  		So(string(out), ShouldEqual, `false`)
    41  	})
    42  
    43  	Convey("4 NOT IN [1,2,3] should return true", t, func() {
    44  		c := compiler.New()
    45  
    46  		p, err := c.Compile(`
    47  			RETURN 4 NOT IN [1,2,3]
    48  		`)
    49  
    50  		So(err, ShouldBeNil)
    51  
    52  		out, err := p.Run(context.Background())
    53  
    54  		So(err, ShouldBeNil)
    55  		So(string(out), ShouldEqual, `true`)
    56  	})
    57  }
    58  
    59  func BenchmarkInOperator(b *testing.B) {
    60  	p := compiler.New().MustCompile(`
    61  			RETURN 1 IN [1,2,3]
    62  		`)
    63  
    64  	for n := 0; n < b.N; n++ {
    65  		p.Run(context.Background())
    66  	}
    67  }
    68  
    69  func BenchmarkInOperatorNot(b *testing.B) {
    70  	p := compiler.New().MustCompile(`
    71  			RETURN 4 NOT IN [1,2,3]
    72  		`)
    73  
    74  	for n := 0; n < b.N; n++ {
    75  		p.Run(context.Background())
    76  	}
    77  }