github.com/MontFerret/ferret@v0.18.0/pkg/compiler/compiler_precedence_test.go (about) 1 package compiler_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/MontFerret/ferret/pkg/compiler" 8 9 . "github.com/smartystreets/goconvey/convey" 10 ) 11 12 func TestPrecedence(t *testing.T) { 13 Convey("Math operators", t, func() { 14 Convey("2 + 2 * 2", func() { 15 c := compiler.New() 16 17 p := c.MustCompile(`RETURN 2 + 2 * 2`) 18 19 out := p.MustRun(context.Background()) 20 21 So(string(out), ShouldEqual, "6") 22 }) 23 24 Convey("2 * 2 + 2", func() { 25 c := compiler.New() 26 27 p := c.MustCompile(`RETURN 2 * 2 + 2`) 28 29 out := p.MustRun(context.Background()) 30 31 So(string(out), ShouldEqual, "6") 32 }) 33 34 Convey("2 * (2 + 2)", func() { 35 c := compiler.New() 36 37 p := c.MustCompile(`RETURN 2 * (2 + 2)`) 38 39 out := p.MustRun(context.Background()) 40 41 So(string(out), ShouldEqual, "8") 42 }) 43 }) 44 45 Convey("Logical", t, func() { 46 Convey("TRUE OR TRUE AND FALSE", func() { 47 c := compiler.New() 48 49 p := c.MustCompile(`RETURN TRUE OR TRUE AND FALSE`) 50 51 out := p.MustRun(context.Background()) 52 53 So(string(out), ShouldEqual, "true") 54 }) 55 56 Convey("FALSE AND TRUE OR TRUE", func() { 57 c := compiler.New() 58 59 p := c.MustCompile(`RETURN FALSE AND TRUE OR TRUE`) 60 61 out := p.MustRun(context.Background()) 62 63 So(string(out), ShouldEqual, "true") 64 }) 65 }) 66 }