From 97aa44c7ef47584b8799e6158b4b3cebc2b21798 Mon Sep 17 00:00:00 2001 From: Hikmatulloh Hari Mukti Date: Fri, 5 Mar 2021 23:39:36 +0700 Subject: [PATCH] Resolve issue #15 token.REM on Float operation should return ErrInvalidOperationOnFloat --- boolean/boolean.go | 2 +- expr_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/boolean/boolean.go b/boolean/boolean.go index d236c6c..5f82ef0 100644 --- a/boolean/boolean.go +++ b/boolean/boolean.go @@ -77,7 +77,7 @@ func (v *visitor) arithmetic(xVisitor, yVisitor *visitor, op token.Token) { case token.QUO: v.res, v.kind = fmt.Sprintf("%f", x/y), token.FLOAT case token.REM: - v.res, v.kind = fmt.Sprintf("%f", x+y), token.FLOAT + v.err = ErrInvalidOperationOnFloat } return } diff --git a/expr_test.go b/expr_test.go index 3b50f94..2addaca 100644 --- a/expr_test.go +++ b/expr_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/muktihari/expr" + "github.com/muktihari/expr/boolean" "github.com/muktihari/expr/float" "github.com/muktihari/expr/integer" ) @@ -142,6 +143,7 @@ func TestBool(t *testing.T) { {In: "-4 * -2 > -1", Eq: true}, {In: "10 % 2 > -2", Eq: true}, {In: "10 % 2 < 1", Eq: true}, + {In: "10.2 % 2 > 2", Err: boolean.ErrInvalidOperationOnFloat}, } for _, tc := range tt {