Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more unit tests for operators #742

Merged
merged 1 commit into from
Jun 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions pkg/runtime/expressions/operators/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,3 +1220,63 @@ func TestGreaterOrEqual(t *testing.T) {
})
})
}

func TestLess(t *testing.T) {
Convey("Less than value", t, func() {
Convey("1 < 5", func() {
So(operators.Less(values.NewInt(1), values.NewInt(5)), ShouldEqual, values.True)
})
Convey("5 < 2", func() {
So(operators.Less(values.NewInt(5), values.NewInt(2)), ShouldEqual, values.False)
})
})
}

func TestLessOrEqual(t *testing.T) {
Convey("Less than value", t, func() {
Convey("1 < 5", func() {
So(operators.LessOrEqual(values.NewInt(1), values.NewInt(5)), ShouldEqual, values.True)
})
Convey("5 < 2", func() {
So(operators.LessOrEqual(values.NewInt(5), values.NewInt(2)), ShouldEqual, values.False)
})
Convey("5 <= 5", func() {
So(operators.LessOrEqual(values.NewInt(5), values.NewInt(5)), ShouldEqual, values.True)
})
})
}

func TestNot(t *testing.T) {
Convey("Invert truthiness", t, func() {
Convey("true turns false", func() {
So(operators.Not(values.NewBoolean(true), nil), ShouldEqual, values.False)
})
Convey("false turns true", func() {
So(operators.Not(values.NewBoolean(false), nil), ShouldEqual, values.True)
})
Convey("'' turns true", func() {
So(operators.Not(values.NewString(""), nil), ShouldEqual, values.True)
})
Convey("'foo' turns false", func() {
So(operators.Not(values.NewString("foo"), nil), ShouldEqual, values.False)
})
Convey("1 turns false", func() {
So(operators.Not(values.NewInt(1), nil), ShouldEqual, values.False)
})
Convey("0 turns true", func() {
So(operators.Not(values.NewInt(0), nil), ShouldEqual, values.True)
})
Convey("1.0 turns false", func() {
So(operators.Not(values.NewFloat(1), nil), ShouldEqual, values.False)
})
Convey("0.0 turns true", func() {
So(operators.Not(values.NewFloat(0.0), nil), ShouldEqual, values.True)
})
Convey("current turns false", func() {
So(operators.Not(values.NewDateTime(values.NewCurrentDateTime().Time), nil), ShouldEqual, values.False)
})
Convey("zerotime turns true", func() {
So(operators.Not(values.NewDateTime(values.ZeroDateTime.Time), nil), ShouldEqual, values.True)
})
})
}