public void fct_BO_12_BC_ok()
        {
            string           expr       = "fct(12)";
            List <ExprToken> listTokens = TestCommon.AddTokens("fct", "(", "12", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprFunctionCall rootExpr = result.RootExpr as ExprFunctionCall;

            Assert.IsNotNull(rootExpr, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", rootExpr.FunctionName, "The function name should be: fct");
            Assert.AreEqual(1, rootExpr.ListExprParameters.Count, "The function call should have one parameter");

            // check the parameter: its a final operand: name and type!!
            ExprFinalOperand const12 = rootExpr.ListExprParameters[0] as ExprFinalOperand;

            Assert.AreEqual("12", const12.Operand, "The parameter name should be: 12");
            Assert.IsTrue(const12.ContentType == OperandType.ValueInt, "The parameter type should be: int");
        }
        public void fct_OP_CP_ok()
        {
            string           expr       = "fct()";
            List <ExprToken> listTokens = TestCommon.AddTokens("fct", "(", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprFunctionCall rootExpr = result.RootExpr as ExprFunctionCall;

            Assert.IsNotNull(rootExpr, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", rootExpr.FunctionName, "The function name should be: fct");
            Assert.AreEqual(0, rootExpr.ListExprParameters.Count, "The function call should have any parameter");
        }
        public void fct_OP_a_CP_And_b_ok()
        {
            string           expr       = "fct(a) And b";
            List <ExprToken> listTokens = TestCommon.AddTokens("fct", "(", "a", ")", "And");

            TestCommon.AddTokens(listTokens, "b");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprLogical exprLogical = result.RootExpr as ExprLogical;

            Assert.IsNotNull(exprLogical, "The root node type should be Logical");


            //----check the left part of the comparison: the function call
            ExprFunctionCall exprFunction = exprLogical.ExprLeft as ExprFunctionCall;

            Assert.IsNotNull(exprFunction, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", exprFunction.FunctionName, "The function name should be: fct");
            Assert.AreEqual(1, exprFunction.ListExprParameters.Count, "The function call should have one parameter");

            // check the parameter: its a final operand
            ExprFinalOperand paraFunction = exprFunction.ListExprParameters[0] as ExprFinalOperand;

            Assert.AreEqual("a", paraFunction.Operand, "The parameter name should be: a");
            Assert.IsTrue(paraFunction.ContentType == OperandType.ObjectName, "The parameter type should be: ObjectName");

            //----check the right part of the root node
            ExprFinalOperand operandRight = exprLogical.ExprRight as ExprFinalOperand;

            Assert.IsNotNull(operandRight, "The left root node type should be BoolBinExprOperand");
            Assert.AreEqual(operandRight.Operand, "b", "The left operand should be A");
        }
        public void fct_OP_a_Eq_b_CP_ok()
        {
            string           expr       = "fct(a=b)";
            List <ExprToken> listTokens = TestCommon.AddTokens("fct", "(", "a", "=", "b", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprFunctionCall rootExpr = result.RootExpr as ExprFunctionCall;

            Assert.IsNotNull(rootExpr, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", rootExpr.FunctionName, "The function name should be: fct");
            Assert.AreEqual(1, rootExpr.ListExprParameters.Count, "The function call should have one parameter");

            // check the parameter: its a comparison expression
            ExprComparison exprComparison = rootExpr.ListExprParameters[0] as ExprComparison;

            Assert.AreEqual(OperatorComparisonCode.Equals, exprComparison.Operator, "The operator name should be: =");

            // check the left part: its a final operand: a
            ExprFinalOperand operandLeft = exprComparison.ExprLeft as ExprFinalOperand;

            Assert.AreEqual("a", operandLeft.Operand, "should be: a");
            Assert.IsTrue(operandLeft.ContentType == OperandType.ObjectName, "The type should be: ObjectName");

            // check the right part: its a final operand: a
            ExprFinalOperand operandRight = exprComparison.ExprRight as ExprFinalOperand;

            Assert.AreEqual("b", operandRight.Operand, "should be: b");
            Assert.IsTrue(operandLeft.ContentType == OperandType.ObjectName, "The type should be: ObjectName");
        }
        public void fct_OP_a_sep_b_CP_ok()
        {
            string           expr       = "fct(a,b)";
            List <ExprToken> listTokens = TestCommon.AddTokens("fct", "(", "a", ",", "b");

            TestCommon.AddTokens(listTokens, ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprFunctionCall rootExpr = result.RootExpr as ExprFunctionCall;

            Assert.IsNotNull(rootExpr, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", rootExpr.FunctionName, "The function name should be: fct");
            Assert.AreEqual(2, rootExpr.ListExprParameters.Count, "The function call should have one parameter");

            // check the parameter: its a final operand: name and type!!
            ExprFinalOperand paraFunction = rootExpr.ListExprParameters[0] as ExprFinalOperand;

            Assert.AreEqual("a", paraFunction.Operand, "The parameter name should be: a");
            Assert.IsTrue(paraFunction.ContentType == OperandType.ObjectName, "The parameter type should be: ObjectName");

            // check the parameter 2: its a final operand: name and type!!
            ExprFinalOperand paraFunction2 = rootExpr.ListExprParameters[1] as ExprFinalOperand;

            Assert.AreEqual("b", paraFunction2.Operand, "The parameter name should be: b");
            Assert.IsTrue(paraFunction2.ContentType == OperandType.ObjectName, "The parameter type should be: ObjectName");
        }
Example #6
0
        public void fct_OP_a_Eq_b_CP_ok()
        {
            string           expr       = "fct(not a)";
            List <ExprToken> listTokens = TestCommon.AddTokens("fct", "(", "not", "a", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprFunctionCall rootExpr = result.RootExpr as ExprFunctionCall;

            Assert.IsNotNull(rootExpr, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", rootExpr.FunctionName, "The function name should be: fct");
            Assert.AreEqual(1, rootExpr.ListExprParameters.Count, "The function call should have one parameter");

            // check the parameter: its a logical Not expression
            ExprLogicalNot exprLogicalNot = rootExpr.ListExprParameters[0] as ExprLogicalNot;

            Assert.IsNotNull(exprLogicalNot, "The funct param should a Logical Not expression");



            // check the left part: its a final operand: a
            ExprFinalOperand paramFunc = exprLogicalNot.ExprBase as ExprFinalOperand;

            Assert.AreEqual("a", paramFunc.Operand, "should be: a");
            Assert.IsTrue(paramFunc.ContentType == OperandType.ObjectName, "The type should be: ObjectName");
        }
        public void a_Gt_fct_OP_CP_ok()
        {
            string           expr       = "a > fct()";
            List <ExprToken> listTokens = TestCommon.AddTokens("a", ">", "fct", "(", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprComparison exprComparison = result.RootExpr as ExprComparison;

            Assert.IsNotNull(exprComparison, "The root node type should be Comparison");

            //----check the left part of the root node
            ExprFinalOperand operandLeft = exprComparison.ExprLeft as ExprFinalOperand;

            Assert.IsNotNull(operandLeft, "The left root node type should be BoolBinExprOperand");
            Assert.AreEqual(operandLeft.Operand, "a", "The left operand should be A");


            //----check the right part of the comparison: the function call
            ExprFunctionCall exprFunction = exprComparison.ExprRight as ExprFunctionCall;

            Assert.IsNotNull(exprFunction, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", exprFunction.FunctionName, "The function name should be: fct");
            Assert.AreEqual(0, exprFunction.ListExprParameters.Count, "The function call should have any parameter");
        }