public void Bra_A_Eq_Minus_12_Bra() { ExpressionEval evaluator = new ExpressionEval(); // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT. evaluator.SetLang(Language.En); string expr = "(A=-12)"; //-1---parse the string, return a syntax tree ParseResult parseResult = evaluator.Parse(expr); Assert.IsFalse(parseResult.HasError, "the expression process should return success"); // check the root node ExprComparison rootBinExpr = parseResult.RootExpr as ExprComparison; Assert.IsNotNull(rootBinExpr, "The root node type should be BoolBinExpr"); // check the left part of the root node ExprFinalOperand operandLeft = rootBinExpr.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 root node ExprFinalOperand operandRight = rootBinExpr.ExprRight as ExprFinalOperand; Assert.IsNotNull(operandRight, "The left root node type should be BoolBinExprOperand"); Assert.AreEqual(operandRight.Operand, "-12", "The left operand should be -12"); // check the root node operator Assert.AreEqual(rootBinExpr.Operator, OperatorComparisonCode.Equals, "The root operator should be ="); }
public void OP_not_a_CP_ok() { string expr = "(not a)"; List <ExprToken> listTokens = TestCommon.AddTokens("(", "not", "a", ")"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildDefaultConfig(); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The tokens (not a) should be decoded with success"); // check the root node ExprLogicalNot rootBinExpr = result.RootExpr as ExprLogicalNot; Assert.IsNotNull(rootBinExpr, "The root node type should be a ExprLogicalNot"); // the inner expr is an operand ExprFinalOperand exprOperandInner = rootBinExpr.ExprBase as ExprFinalOperand; Assert.IsNotNull(exprOperandInner, "The root node type should be BoolBinExprOperand"); Assert.AreEqual("a", exprOperandInner.Operand, "The left operand should be a"); }
public void CheckOperand_objectname() { string expr = "a"; List <ExprToken> listTokens = TestCommon.AddTokens("a"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildDefaultConfig(); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The tokens (A=B) should be decoded with success"); // check the root node ExprFinalOperand rootBinExpr = result.RootExpr as ExprFinalOperand; Assert.IsNotNull(rootBinExpr, "The root node type should be BoolBinExprOperand"); Assert.AreEqual("a", rootBinExpr.Operand, "The left operand should be a"); Assert.AreEqual(OperandType.ObjectName, rootBinExpr.ContentType, "The operand type should be an object name"); }
public void Expr_4_Mul_5_Plus_1_ok() { ExpressionEval evaluator = new ExpressionEval(); // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT. evaluator.SetLang(Language.En); string expr = "4*5-1"; //-1---parse the string, return a syntax tree ParseResult parseResult = evaluator.Parse(expr); Assert.IsFalse(parseResult.HasError, "the expression process should finish successfully"); // check the root node ExprCalculation rootExprCalc = parseResult.RootExpr as ExprCalculation; Assert.IsNotNull(rootExprCalc, "The root node type should be an ExprCalculation"); // the calc expr should contains 3 operands and 2 operators Assert.AreEqual(3, rootExprCalc.ListExprOperand.Count, "The ExprCalculation should contains 3 operands"); Assert.AreEqual(2, rootExprCalc.ListOperator.Count, "The ExprCalculation should contains 2 operators"); // check (just) the fisrt operator: */Mul ExprOperatorCalculation operatorTwo = rootExprCalc.ListOperator[0] as ExprOperatorCalculation; Assert.IsNotNull(operatorTwo, "The left root node type should be a ExprFinalOperand"); Assert.AreEqual(OperatorCalculationCode.Multiplication, operatorTwo.Operator, "The Second operator should be: *"); // check (just) the last operand: 1 ExprFinalOperand operandThree = rootExprCalc.ListExprOperand[2] as ExprFinalOperand; Assert.IsNotNull(operandThree, "The left root node type should be a ExprFinalOperand"); Assert.AreEqual(1, operandThree.ValueInt, "The left operand should be 11"); }
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 CheckOperand_double_separatorDot() { string expr = "12.34"; List <ExprToken> listTokens = TestCommon.AddTokens("12.34"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildConfig(DecimalAndFunctionSeparators.Standard); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The tokens 12.34 should be decoded with success"); // check the root node ExprFinalOperand rootBinExpr = result.RootExpr as ExprFinalOperand; Assert.IsNotNull(rootBinExpr, "The root node type should be BoolBinExprOperand"); Assert.AreEqual("12.34", rootBinExpr.Operand, "The left operand should be 12.34"); Assert.AreEqual(OperandType.ValueDouble, rootBinExpr.ContentType, "The operand type should be a double"); }
public void OP_a_or_b_CP_and_not_OP_c_CP() { string expr = "(a or b) and not (c)"; List <ExprToken> listTokens = TestCommon.AddTokens("(", "a", "or", "b", ")"); TestCommon.AddTokens(listTokens, "and", "not", "("); TestCommon.AddTokens(listTokens, "c", ")"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildDefaultConfig(); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The tokens (a and not b) should be decoded with success"); // check the root node: bin expr ExprLogical binExpr = result.RootExpr as ExprLogical; Assert.IsNotNull(binExpr, "The root node type should be ExprLogical"); // the operator is: and Assert.AreEqual(OperatorLogicalCode.And, binExpr.Operator, "The operator should be and"); //----the left part is : (a or b) ExprLogical exprLeftLogical = binExpr.ExprLeft as ExprLogical; Assert.IsNotNull(exprLeftLogical, "The root node type should be exprLeftLogical"); // the operator is: or Assert.AreEqual(OperatorLogicalCode.Or, exprLeftLogical.Operator, "The operator should be or"); // a ExprFinalOperand exprLeftLogicalLeftOperand = exprLeftLogical.ExprLeft as ExprFinalOperand; Assert.AreEqual("a", exprLeftLogicalLeftOperand.Operand, "The left operand should be a"); // b ExprFinalOperand exprLeftLogicalRightOperand = exprLeftLogical.ExprRight as ExprFinalOperand; Assert.AreEqual("b", exprLeftLogicalRightOperand.Operand, "The right operand should be b"); //----the right part is: not(c) ExprLogicalNot notExpr = binExpr.ExprRight as ExprLogicalNot; Assert.IsNotNull(notExpr, "The expr type should be ExprLogicalNot"); ExprFinalOperand notExprOperandFinal = notExpr.ExprBase as ExprFinalOperand; Assert.AreEqual("c", notExprOperandFinal.Operand, "The not operand should be c"); }
public void OP_not_OP_a_and_CP_CP_ok() { string expr = "(not (a and b))"; List <ExprToken> listTokens = TestCommon.AddTokens("(", "not", "("); TestCommon.AddTokens(listTokens, "a", "and", "b"); TestCommon.AddTokens(listTokens, ")", ")"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildDefaultConfig(); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The tokens (not a) should be decoded with success"); // check the root node: Not expr ExprLogicalNot rootBinExpr = result.RootExpr as ExprLogicalNot; Assert.IsNotNull(rootBinExpr, "The root node type should be BoolBinExprNot"); // the inner expr is a logical expr: (a and b) ExprLogical binExpr = rootBinExpr.ExprBase as ExprLogical; Assert.IsNotNull(binExpr, "The root node type should be BoolBinExpr"); // a ExprFinalOperand exprOperandLeft = binExpr.ExprLeft as ExprFinalOperand; Assert.IsNotNull(exprOperandLeft, "The root node type should be BoolBinExprOperand"); Assert.AreEqual("a", exprOperandLeft.Operand, "The left operand should be a"); // b ExprFinalOperand exprOperandRight = binExpr.ExprRight as ExprFinalOperand; Assert.IsNotNull(exprOperandRight, "The root node type should be BoolBinExprOperand"); Assert.AreEqual("b", exprOperandRight.Operand, "The right operand should be b"); // check the operator Assert.AreEqual(OperatorLogicalCode.And, binExpr.Operator, "The operator should be and"); }
public void Expr_OP_a_Minus_2_CP_Eq_7_ok() { ExpressionEval evaluator = new ExpressionEval(); // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT. evaluator.SetLang(Language.En); string expr = "(a-2) = 7"; //-1---parse the string, return a syntax tree ParseResult parseResult = evaluator.Parse(expr); Assert.IsFalse(parseResult.HasError, "the expression process should finish successfully"); // check the root node ExprComparison rootExpr = parseResult.RootExpr as ExprComparison; Assert.IsNotNull(rootExpr, "The root node type should be an ExprComparison"); Assert.AreEqual(OperatorComparisonCode.Equals, rootExpr.Operator, "The operator qqhould: plus"); //----left part (a-2) // check the left part ExprCalculation operandLeft = rootExpr.ExprLeft as ExprCalculation; Assert.IsNotNull(operandLeft, "The left root node type should be an ExprCalculation"); Assert.AreEqual(OperatorCalculationCode.Minus, operandLeft.ListOperator[0].Operator, "The operator should: minus"); // check the right part ExprFinalOperand operandLeftRight = operandLeft.ListExprOperand[0] as ExprFinalOperand; Assert.IsNotNull(operandLeftRight, "The left root node type should be a ExprFinalOperand"); Assert.AreEqual("a", operandLeftRight.Operand, "The left operand should be: a"); // check the right part of the root node ExprFinalOperand operandRightRight = operandLeft.ListExprOperand[1] as ExprFinalOperand; Assert.IsNotNull(operandRightRight, "The left root node type should be a ExprFinalOperand"); Assert.AreEqual(2, operandRightRight.ValueInt, "The left operand should be 2"); //----right part: 7 // check the left part ExprFinalOperand operandRight = rootExpr.ExprRight as ExprFinalOperand; Assert.IsNotNull(operandRight, "The left root node type should be a ExprFinalOperand"); Assert.AreEqual(7, operandRight.ValueInt, "The left operand should be 7"); }
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 ExprIsA() { ExpressionEval evaluator = new ExpressionEval(); // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT. evaluator.SetLang(Language.En); string expr = "A"; ParseResult parseResult = evaluator.Parse(expr); Assert.IsFalse(parseResult.HasError, "the expression process should finish successfully"); // check the syntax tree // check the root node ExprFinalOperand rootBinExprOperand = parseResult.RootExpr as ExprFinalOperand; Assert.IsNotNull(rootBinExprOperand, "The root node type should be a ExprFinalOperand"); Assert.AreEqual(rootBinExprOperand.Operand, "A", "The left operand should be A"); }
public void Expr_Minus_6_Ret_Minus_6_ok() { ExpressionEval evaluator = new ExpressionEval(); // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT. evaluator.SetLang(Language.En); string expr = "-6"; //-1---parse the string, return a syntax tree ParseResult parseResult = evaluator.Parse(expr); Assert.IsFalse(parseResult.HasError, "the expression process should finish successfully"); // check the root node ExprFinalOperand rootExpr = parseResult.RootExpr as ExprFinalOperand; Assert.IsNotNull(rootExpr, "The root node type should be a ExprFinalOperand"); Assert.AreEqual(-6, rootExpr.ValueInt, "The left operand should be -6"); }
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"); }
public void Expr_12_Plus_5_Ret_17_ok() { ExpressionEval evaluator = new ExpressionEval(); // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT. evaluator.SetLang(Language.En); string expr = "12+5"; //-1---parse the string, return a syntax tree ParseResult parseResult = evaluator.Parse(expr); Assert.IsFalse(parseResult.HasError, "the expression process should finish successfully"); // check the root node ExprCalculation rootExprCalc = parseResult.RootExpr as ExprCalculation; Assert.IsNotNull(rootExprCalc, "The root node type should be an ExprCalculation"); // has two operands Assert.AreEqual(2, rootExprCalc.ListExprOperand.Count, "should have 2 operands"); Assert.AreEqual(1, rootExprCalc.ListOperator.Count, "should have 1 operator"); // check the left part of the root node //ExprFinalOperand operandLeft = rootExprCalc.ExprLeft as ExprFinalOperand; ExprFinalOperand operandLeft = rootExprCalc.ListExprOperand[0] as ExprFinalOperand; Assert.IsNotNull(operandLeft, "The left root node type should be a ExprFinalOperand"); Assert.AreEqual(12, operandLeft.ValueInt, "The left operand should be 12"); // check the right part of the root node //ExprFinalOperand operandRight = rootExprCalc.ExprRight as ExprFinalOperand; ExprFinalOperand operandRight = rootExprCalc.ListExprOperand[1] as ExprFinalOperand; Assert.IsNotNull(operandRight, "The left root node type should be a ExprFinalOperand"); Assert.AreEqual(5, operandRight.ValueInt, "The left operand should be 5"); // check the root node operator Assert.AreEqual(rootExprCalc.ListOperator[0].Operator, OperatorCalculationCode.Plus, "The root operator should be Plus"); }
public void BRA_A_And_B_BRA() { string expr = "(A and B)"; List <ExprToken> listTokens = TestCommon.AddTokens("(", "A", "and", "B", ")"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildDefaultConfig(); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The expr should be decoded with success"); // check the root node, its a binary expression ExprLogical rootBinExpr = result.RootExpr as ExprLogical; Assert.IsNotNull(rootBinExpr, "The root node type should be ExprLogical"); // check the left part of the root node ExprFinalOperand operandLeft = rootBinExpr.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 root node ExprFinalOperand operandRight = rootBinExpr.ExprRight as ExprFinalOperand; Assert.IsNotNull(operandRight, "The left root node type should be BoolBinExprOperand"); Assert.AreEqual(operandRight.Operand, "B", "The left operand should be B"); // check the root node operator Assert.AreEqual(rootBinExpr.Operator, OperatorLogicalCode.And, "The root operator should be and"); }
public void A_Eq_B() { string expr = "A=B"; List <ExprToken> listTokens = TestCommon.AddTokens("A", "=", "B"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildDefaultConfig(); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The tokens (A=B) should be decoded with success"); //----check the root node ExprComparison rootBinExpr = result.RootExpr as ExprComparison; Assert.IsNotNull(rootBinExpr, "The root node type should be BoolBinExpr"); //----check the left part of the root node ExprFinalOperand operandLeft = rootBinExpr.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 root node ExprFinalOperand operandRight = rootBinExpr.ExprRight as ExprFinalOperand; Assert.IsNotNull(operandRight, "The left root node type should be BoolBinExprOperand"); Assert.AreEqual(operandRight.Operand, "B", "The left operand should be B"); // check the root node operator Assert.AreEqual(rootBinExpr.Operator, OperatorComparisonCode.Equals, "The root operator should be ="); }
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"); }
public void a_Plus_12() { string expr = "a+12"; List <ExprToken> listTokens = TestCommon.AddTokens("a", "+", "12"); // decoder, renvoie un arbre de node ExprTokensParser parser = new ExprTokensParser(); // the default list: =, <, >, >=, <=, <> var dictOperators = TestCommon.BuildDefaultConfig(); parser.SetConfiguration(dictOperators); // decode the list of tokens ParseResult result = parser.Parse(expr, listTokens); //----check the root node ExprCalculation rootExpr = result.RootExpr as ExprCalculation; Assert.IsNotNull(rootExpr, "The root node type should be BoolBinExpr"); //----check the left part of the root node //ExprFinalOperand operandLeft = rootExpr.ExprLeft as ExprFinalOperand; ExprFinalOperand operandLeft = rootExpr.ListExprOperand[0] as ExprFinalOperand; Assert.IsNotNull(operandLeft, "The left root node type should be a final operand"); Assert.AreEqual(operandLeft.Operand, "a", "The left operand should be A"); //----check the right part of the root node //ExprFinalOperand operandRight = rootExpr.ExprRight as ExprFinalOperand; ExprFinalOperand operandRight = rootExpr.ListExprOperand[1] as ExprFinalOperand; Assert.IsNotNull(operandRight, "The left root node type should be a Final operand"); Assert.AreEqual(operandRight.Operand, "12", "The left operand should be 12"); // check the root node operator Assert.AreEqual(rootExpr.ListOperator[0].Operator, OperatorCalculationCode.Plus, "The root operator should be ="); }
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"); }