public override Expression Parse(IEnumerable <Token> postFixTokens, ExpressionFactory expressionFactory) { Stack <Expression> expTree = new Stack <Expression>(); List <Expression> children = new List <Expression>(4); foreach (Token t in postFixTokens) { for (int i = 0; i < t.GetChildCount(); i++) { try { children.Add(expTree.Pop()); } catch (InvalidOperationException emptyStackError) { throw new InvalidExpressionException("InvalidExpression TODO", emptyStackError); } } children.Reverse(); expTree.Push(expressionFactory.CreateExpression(t, children)); children = new List <Expression>(); } if (expTree.Count != 1) { throw new InvalidExpressionException("InvalidExpression Or Expressions consists of multiple uncombinable expressions. TODO"); } return(expTree.Pop()); }
public void CreateExpression_ExpressionNotImplemented() { var expressionOperator = _fixture.Create <string>(); var expressionFactory = new ExpressionFactory(new List <ITransportCommandFactory>()); expressionFactory.CreateExpression($"[{expressionOperator}] text", Transport); }
public void CreateExpression_GetInternalOperator() { var expressionOperator = "MessageContains"; var expressionFactory = new ExpressionFactory(new List <ITransportCommandFactory>()); var result = expressionFactory.CreateExpression($"[{expressionOperator}] text", Transport); Assert.IsNotNull(result); Assert.AreEqual(expressionOperator, result.Operator); }
public void CreateExpression_GetExternalOperator() { var internalOperator = "ExternalCommand"; var externalOperator = "SendMessage"; var commandFactory = new Mock <ITransportCommandFactory>(); commandFactory.Setup(x => x.TransportName).Returns(Transport); commandFactory.Setup(x => x.CreateCommand(It.IsAny <string>())) .Returns(new Mock <ITransportCommand>().Object); var expressionFactory = new ExpressionFactory(new List <ITransportCommandFactory> { commandFactory.Object }); var result = expressionFactory.CreateExpression($"[{internalOperator}] [{externalOperator}] text", Transport); Assert.IsNotNull(result); Assert.AreEqual(internalOperator, result.Operator); }