Example #1
0
        void CheckPredicate(string from, string to)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            MacroScopeParser parser     = Factory.CreateParser(from);
            IExpression      expression = parser.predicate();

            Assert.IsNotNull(expression);
            Assert.AreEqual(to, TestUtil.Stringify(expression));
        }
Example #2
0
        public void TestPredicate()
        {
            MacroScopeParser parser     = Factory.CreateParser("a >= b");
            Expression       expression = parser.predicate() as Expression;

            Assert.IsNotNull(expression);
            Assert.AreEqual("a", TestUtil.Stringify(expression.Left));
            Assert.AreSame(ExpressionOperator.GreaterOrEqual,
                           expression.Operator);
            Assert.AreEqual("b", TestUtil.Stringify(expression.Right));

            parser     = Factory.CreateParser("c is null");
            expression = parser.predicate() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual("c", TestUtil.Stringify(expression.Left));
            Assert.AreSame(ExpressionOperator.IsNull,
                           expression.Operator);
            Assert.IsNull(expression.Right);

            CheckPredicate("c IS NOT NULL");

            parser     = Factory.CreateParser("d like 'Smith%'");
            expression = parser.predicate() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual("d", TestUtil.Stringify(expression.Left));
            Assert.AreSame(ExpressionOperator.Like,
                           expression.Operator);

            PatternExpression patternExpression = expression.Right as PatternExpression;

            Assert.IsNotNull(patternExpression);
            Assert.AreEqual("'Smith%'", TestUtil.Stringify(patternExpression.Expression));
            Assert.IsNull(patternExpression.Escape);

            parser     = Factory.CreateParser("comment LIKE '%30!%%' ESCAPE '!'");
            expression = parser.predicate() as Expression;
            Assert.IsNotNull(expression);

            patternExpression = expression.Right as PatternExpression;
            Assert.IsNotNull(patternExpression);
            Assert.AreEqual("'%30!%%'", TestUtil.Stringify(patternExpression.Expression));
            Assert.AreEqual("'!'", TestUtil.Stringify(patternExpression.Escape));

            parser     = Factory.CreateParser("e between 1 and 10");
            expression = parser.predicate() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreSame(ExpressionOperator.Between, expression.Operator);
            Assert.AreEqual("e BETWEEN 1 AND 10", TestUtil.Stringify(expression));

            parser     = Factory.CreateParser("f in(+2, +3, +5, +7)");
            expression = parser.predicate() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual("f IN (2, 3, 5, 7)", TestUtil.Stringify(expression));

            string idempotent = "g1 NOT IN (SELECT name\r\nFROM week)";

            parser     = Factory.CreateParser(idempotent);
            expression = parser.predicate() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual(idempotent, TestUtil.Stringify(expression));

            CheckPredicate("EXISTS (SELECT *\r\nFROM warehouse)");
        }