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 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 override Expr ToExpression() { if (this.Category == EnumFilterCategory.NoFilter) { return(null); } else if (this.Category == EnumFilterCategory.IsNull) { return(this.CreateIsNullExpr()); } else if (this.Category == EnumFilterCategory.IsNotNull) { return(this.CreateIsNotNullExpr()); } else if (this.Category == EnumFilterCategory.IsOneOf) { var expr_or = new ExprLogicalOr(); foreach (var item in this.one_of_value) { var t_value = (T)item; string t_string_value = t_value.ToString(); var expr_t = new ExprLiteralString(t_string_value); var expr_compare = Expr.GetExprComparison(this.expr_field, expr_t, ComparisonOperation.Equals); expr_or.Add(expr_compare); } if (this.Not) { var expr_not = new ExprLogicalNot(expr_or); return(expr_not); } else { return(expr_or); } } else { string msg = string.Format("Unhandled datetime enum category: \"{0}\"", this.Category); throw new System.ArgumentException(msg); } }
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"); }