예제 #1
0
        public void LessThanExpression()
        {
            var e = new LessThanExpression(new Literal("13"), new Literal("37"));

            Assert.IsFalse(e.IsTrivial);
            Assert.AreEqual("(13<37)", e.ToString());
            Assert.AreEqual("LessThan", e.Name);
        }
        public static void SerializeLessThanExpression()
        {
            var v = new NumberLiteral(2);
            var a = new LessThanExpression(v, v);
            var b = SerializationUtil.Reserialize(a);

            Assert.AreEqual(a, b);
        }
예제 #3
0
        public void TestIntFloatFalse()
        {
            var expression = new LessThanExpression(
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)1.001),
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)1),
                ExpressiveOptions.None);

            Assert.AreEqual(false, expression.Evaluate(null));
        }
예제 #4
0
        public static void TestEvaluate(object lhs, object rhs, object expectedValue)
        {
            var expression = new LessThanExpression(
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == lhs),
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == rhs),
                new Context(ExpressiveOptions.None));

            Assert.That(expression.Evaluate(null), Is.EqualTo(expectedValue));
        }
예제 #5
0
        public void TestRightNull()
        {
            var expression = new LessThanExpression(
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)false),
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)null),
                ExpressiveOptions.None);

            Assert.AreEqual(null, expression.Evaluate(null));
        }
예제 #6
0
        private object LessThan(object l, object r)
        {
            var scope = new Scope();

            scope.SetVar("l", l);
            scope.SetVar("r", r);

            var exp = new LessThanExpression(
                new VariableExpression("l"),
                new VariableExpression("r")
                );

            return(exp.Evaluate(scope, new Bindings()).AsObject());
        }
예제 #7
0
        public void LessThan(int value, bool expected)
        {
            var expression = new LessThanExpression(
                new FieldExpression(0, "age"),
                new ValueExpression(10)
                );

            var json  = $"{{ \"age\": {value} }}";
            var bytes = Encoding.UTF8.GetBytes(json);

            var matcher = new SlowMatcher(new[] { expression });

            Assert.Equal(expected, matcher.Match(bytes));
        }
        public void Visit(LessThanExpression expression)
        {
            var leftArg = new QueryPhaseArgs()
            {
                BoolQueryArg = new QueryLessThan()
            };

            VisitChild(expression.Left, leftArg);

            var rightArg = new QueryPhaseArgs()
            {
                BoolQueryArg = new QueryLessThan()
            };

            VisitChild(expression.Right, rightArg);

            var parentArgs = _visitStack.Peek();

            parentArgs.RowResult = ValidateTypes(leftArg.BoolQueryArg, rightArg.BoolQueryArg, (l, r) => l < r);
        }
예제 #9
0
        public override AstNode VisitCompare([NotNull] QlParser.CompareContext context)
        {
            var op = context.op.Text;
            BinaryExpression binExp = null;
            var lhs = this.Visit(context.lhs) as Expression;
            var rhs = this.Visit(context.rhs) as Expression;

            switch (op)
            {
            case "<":
                binExp = new LessThanExpression(lhs, rhs);
                break;

            case "<=":
                binExp = new LessThanOrEqualExpression(lhs, rhs);
                break;

            case ">":
                binExp = new GreaterThanExpression(lhs, rhs);
                break;

            case ">=":
                binExp = new GreaterThanOrEqualExpression(lhs, rhs);
                break;

            case "==":
                binExp = new EqualExpression(lhs, rhs);
                break;

            case "!=":
                binExp = new NotEqualExpression(lhs, rhs);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(op), "Unsupported operator.");
            }

            return(binExp);
        }
예제 #10
0
 public virtual TResult Visit(LessThanExpression expression, TEnvironment environment)
 {
     return(this.Visit((BinaryExpression)expression, environment));
 }
예제 #11
0
        private bool ParseRelationalOperatorIfExists(Lexer lexer, Token token, Attributes attributes)
        {
            var successfullyParsed = true;

            successfullyParsed &= ParseAdditionOrSubstractionIfExists(lexer, token, attributes);

            if (lexer.GetCurrentToken().Is(TokenType.EqualOperator) ||
                lexer.GetCurrentToken().Is(TokenType.GreaterThanOperator) ||
                lexer.GetCurrentToken().Is(TokenType.GreaterThanOrEqualOperator) ||
                lexer.GetCurrentToken().Is(TokenType.LessThanOperator) ||
                lexer.GetCurrentToken().Is(TokenType.LessThanOrEqualOperator) ||
                lexer.GetCurrentToken().Is(TokenType.DistinctOperator))
            {
                BinaryExpression tree;

                if (lexer.GetCurrentToken().Is(TokenType.EqualOperator))
                {
                    tree = new EqualExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.GreaterThanOperator))
                {
                    tree = new GreaterThanExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.GreaterThanOrEqualOperator))
                {
                    tree = new GreaterThanOrEqualExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.LessThanOperator))
                {
                    tree = new LessThanExpression();
                }
                else if (lexer.GetCurrentToken().Is(TokenType.LessThanOrEqualOperator))
                {
                    tree = new LessThanOrEqualExpression();
                }
                else
                {
                    tree = new DistinctExpression();
                }

                tree.LeftOperand    = attributes["EXP"] as Expression;
                successfullyParsed &= ParseAdditionOrSubstractionIfExists(lexer, lexer.GetNextToken(), attributes);
                tree.RightOperand   = attributes["EXP"] as Expression;

                // SEM: Sólo pueden compararse expresiones del mismo tipo
                if (tree.LeftOperand.Type != tree.RightOperand.Type)
                {
                    LogTypeMismatch(lexer.GetCurrentToken(), tree.LeftOperand.Type, tree.RightOperand.Type);
                    successfullyParsed = false;
                }
                // SEM: Las comparaciones de tipo >, >=, <, <= sólo pueden realizarse entre enteros
                else if (!lexer.GetCurrentToken().Is(TokenType.EqualOperator) &&
                         !lexer.GetCurrentToken().Is(TokenType.DistinctOperator) && tree.LeftOperand.Type != DataType.Integer)
                {
                    LogTypeExpressionInvalid(lexer.GetCurrentToken(), DataType.Integer, tree.LeftOperand.Type);
                    successfullyParsed = false;
                }

                attributes["EXP"] = tree;
            }

            return(successfullyParsed);
        }
예제 #12
0
 private string GetExpression(LessThanExpression expression, ref List<OleDbParameter> parameters)
 {
     return " ( " + GetExpressionDispatch(expression.Children[0], ref parameters) + " < " +
       GetExpressionDispatch(expression.Children[1], ref parameters) + " ) ";
 }
 public override void Visit(LessThanExpression expression)
 {
     _expressionString.Append(" (");
     Visit(expression.Left);
     _expressionString.Append(" < ");
     Visit(expression.Right);
     _expressionString.Append(") ");
 }
예제 #14
0
 public virtual void VisitLessThanExpression(LessThanExpression lessThanExpression)
 {
     DefaultVisit(lessThanExpression);
 }
예제 #15
0
 private bool MatchLessThanExpression(LessThanExpression expression)
 {
     return(CompareExpressions(expression.LeftHandSide, expression.RightHandSide) < 0);
 }
 public void Visit(LessThanExpression expression)
 {
     DoBoolean(expression, CodeBinaryOperatorType.LessThan);
 }
예제 #17
0
 public ValueType Visit(LessThanExpression expression, ITypeEnvironment environment)
 {
     return(this.CheckBinaryComparisonExpression(expression, environment));
 }
예제 #18
0
 public IValue Visit(LessThanExpression expression, TypeEnvironment environment)
 {
     return(expression.LeftExpression
            .Accept(this, environment)
            .LessThan(expression.RightExpression.Accept(this, environment)));
 }
예제 #19
0
 public void Visit(LessThanExpression expression, CommonTree tree)
 {
     SetLine(expression, tree);
     Parent(tree).Children.Add(expression);
     VisitChildren(tree);
 }
 private string GetExpression(LessThanExpression expression, ref List <OleDbParameter> parameters)
 {
     return(" ( " + GetExpressionDispatch(expression.Children[0], ref parameters) + " < " +
            GetExpressionDispatch(expression.Children[1], ref parameters) + " ) ");
 }