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 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_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 a_Eq_A() { string expr = "a=A"; List <ExprToken> listTokens = TestCommon.AddTokens("a", "=", "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); ExprSyntaxTreeAnalyzer analyzer = new ExprSyntaxTreeAnalyzer(); analyzer.Analyze(result); // finished with no error Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success"); // check the list of variables present in the expression Assert.AreEqual(1, result.ListExprVarUsed.Count, "The expression should have 1 variable"); ExprObjectUsedBase obj1 = result.ListExprVarUsed.Find(o => o.Name.Equals("a")); Assert.IsNotNull(obj1, "The var a should exists"); Assert.AreEqual(ExprObjectType.Variable, obj1.ExprObjectType, "The obj a should be a variable"); }
public void a_Eq_12_checkVarSyntax_0var_err() { string expr = "0var"; List <ExprToken> listTokens = TestCommon.AddTokens("0var"); // 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); ExprSyntaxTreeAnalyzer analyzer = new ExprSyntaxTreeAnalyzer(); analyzer.Analyze(result); // finished with an error Assert.AreEqual(1, result.ListError.Count, "The tokens should be decoded with an error"); // check the list of variables present in the expression Assert.AreEqual(0, result.ListExprVarUsed.Count, "The expression should have any variable"); // todo: check error code Assert.AreEqual(ErrorCode.ValueNumberBadFormed, result.ListError[0].Code, "The error code should be: ValueNumberBadFormed"); }
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_number_badformed() { string expr = "12az"; List <ExprToken> listTokens = TestCommon.AddTokens("12az"); // 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(1, result.ListError.Count, "The tokens 12az should be decoded with one error"); Assert.AreEqual(ErrorCode.ValueNumberBadFormed, result.ListError[0].Code, "the parse should failed: ValueNumberBadFormed"); //// check the root node //ExprFinalOperand rootBinExpr = result.RootExpr as ExprFinalOperand; //Assert.IsNotNull(rootBinExpr, "The root node type should be BoolBinExprOperand"); //Assert.AreEqual("12az", rootBinExpr.Operand, "The left operand should be 12az"); //Assert.AreEqual(OperandType.ValueNumberBadFormed, rootBinExpr.ContentType, "The operand type should be a string"); }
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 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 BRA_A_And_B_Wrong() { 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); Assert.AreEqual(1, result.ListError.Count, "The expr should be decoded with error"); Assert.AreEqual(ErrorCode.BadExpressionBracketOpenCloseMismatch, result.ListError[0].Code, "The errorCode should be: BadExpressionBracketOpenCloseMismatch"); }
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 BRA_a_Eq_not_b_BRA() { string expr = "(a = not b)"; List <ExprToken> listTokens = TestCommon.AddTokens("(", "a", "="); TestCommon.AddTokens(listTokens, "not", "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); Assert.AreEqual(1, result.ListError.Count, "The expr should be decoded with error"); Assert.AreEqual(ErrorCode.UnexpectedTokenBeforeNot, result.ListError[0].Code, "The expr should be decoded with error"); }
public void OP_A_Eq_12_wrong() { 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); // should have an error Assert.AreEqual(1, result.ListError.Count, "Parse of the tokens (A=12 should be return an error."); Assert.AreEqual(ErrorCode.BadExpressionBracketOpenCloseMismatch, result.ListError[0].Code, "The error code should be: BadExpressionBracketOpenCloseMismatch"); }
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 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 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_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 OP_a_not_not_b_CP_wrong() { string expr = "(a not not b)"; List <ExprToken> listTokens = TestCommon.AddTokens("(", "a", "not", "not", "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); Assert.AreEqual(1, result.ListError.Count, "Should failed"); // todo: revoir le code d'erreur renvoyé Assert.AreEqual(ErrorCode.ExprNotBeforeNotIsUnanthorized, result.ListError[0].Code, "The expr should be decoded with error"); }