Skip to content

Commit

Permalink
Feature/#1 array comparison operators (MontFerret#71)
Browse files Browse the repository at this point in the history
* #1 Added ALL IN

* #1 Completed Array operator

* #1 Fixed linting issues
  • Loading branch information
ziflex authored Oct 7, 2018
1 parent 809a51b commit 0dfd58d
Show file tree
Hide file tree
Showing 18 changed files with 1,699 additions and 670 deletions.
323 changes: 323 additions & 0 deletions pkg/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,329 @@ func TestInOperator(t *testing.T) {
})
}

func TestArrayOperator(t *testing.T) {
Convey("ALL", t, func() {
Convey("[1,2,3] ALL IN [1,2,3] should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] ALL IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[1,2,4] ALL IN [1,2,3] should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,4] ALL IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("[4,5,6] ALL NOT IN [1,2,3] should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [4,5,6] ALL NOT IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[1,2,3] ALL > 0 should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] ALL > 0
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[1,2,3] ALL > 2 should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] ALL > 2
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("[1,2,3] ALL >= 3 should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] ALL >= 3
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("['foo','bar'] ALL != 'moo' should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN ['foo', 'bar'] ALL != 'moo'
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
})

Convey("ANY", t, func() {
Convey("[1,2,3] ANY IN [1,2,3] should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] ANY IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[4,2,5] ANY IN [1,2,3] should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [4,2,5] ANY IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[4,5,6] ANY IN [1,2,3] should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [4,5,6] ANY IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("[4,5,6] ANY NOT IN [1,2,3] should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [4,5,6] ANY NOT IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[1,2,3 ] ANY == 2 should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3 ] ANY == 2
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[1,2,3 ] ANY == 4 should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3 ] ANY == 4
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("['foo','bar'] ANY == 'foo' should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN ['foo', 'bar'] ANY == 'foo'
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})
})

Convey("NONE", t, func() {
Convey("[1,2,3] NONE IN [1,2,3] should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] NONE IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("[4,2,5] NONE IN [1,2,3] should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [4,2,5] NONE IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("[4,5,6] NONE IN [1,2,3] should return true", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [4,5,6] NONE IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[4,5,6] NONE NOT IN [1,2,3] should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [4,5,6] NONE NOT IN [1,2,3]
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("[1,2,3] NONE > 99 should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] NONE > 99
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `true`)
})

Convey("[1,2,3] NONE < 99 should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN [1,2,3] NONE < 99
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})

Convey("['foo','bar'] NONE == 'foo' should return false", func() {
c := compiler.New()

prog, err := c.Compile(`
RETURN ['foo','bar'] NONE == 'foo'
`)

So(err, ShouldBeNil)

out, err := prog.Run(context.Background())

So(err, ShouldBeNil)
So(string(out), ShouldEqual, `false`)
})
})
}

func TestForTernaryExpression(t *testing.T) {
Convey("RETURN foo ? TRUE : (FOR i IN 1..5 RETURN i*2)", t, func() {
c := compiler.New()
Expand Down
Loading

0 comments on commit 0dfd58d

Please sign in to comment.