public override void CodeGen(CodeBuilder builder) { builder.AppendToken("if ("); builder.ForceNoWhitespace(); ConditionalExpression.CodeGen(builder); builder.AppendToken(")"); builder.BeginBlock(); ThenStatement.CodeGen(builder); builder.EndBlock(); if (ElseStatement != null) { builder.EndOfLine(); // Nur einfachen Zeilenumbruch erzwingen builder.AppendToken("else"); builder.BeginBlock(); ElseStatement.CodeGen(builder); builder.EndBlock(); } }
internal override string ToString(string indent) { StringBuilder sb = new StringBuilder(128); if (Predicate.OneLine()) { sb.AppendFormat("{0}IF {1}\r\n", indent, Predicate.ToString("")); } else { sb.AppendFormat("{0}IF \r\n", indent); sb.Append(Predicate.ToString(indent + " ")); sb.Append("\r\n"); } sb.Append(ThenStatement.ToString(indent + " ")); if (ElseStatement != null) { sb.Append("\r\n"); sb.AppendFormat("{0}ELSE\r\n", indent); sb.Append(ElseStatement.ToString(indent + " ")); } return(sb.ToString()); }
public override string GenCode() { Condition.GenCode(); string elseLabel = ""; var afterLabel = Compiler.GenerateLabel(); if (ElseStatement != null) { elseLabel = Compiler.GenerateLabel(); Compiler.EmitCode($"brfalse {elseLabel}"); } else { Compiler.EmitCode($"brfalse {afterLabel}"); } ThenStatement.GenCode(); if (ElseStatement != null) { Compiler.EmitCode($"br {afterLabel}"); Compiler.EmitCode("nop", true, elseLabel); ElseStatement.GenCode(); } Compiler.EmitCode("nop", true, afterLabel); return(""); }
public static ThenStatement LogoutIfSessionTokenIsPresent(this ThenStatement thenStatement, string testKey = null) { try { thenStatement.GetStatementLogger() .Information( "[{ContextStatement}] Trying to logout" + (testKey != null ? $" with test key {testKey}" : ""), thenStatement.GetType().Name); var session = thenStatement.GetResultData <string>(BddKeyConstants.SessionTokenKey + testKey); _facade.PostLogout(session).AssertSuccess(); } catch (KeyNotFoundException e) { thenStatement.GetStatementLogger() .Warning($"[{{ContextStatement}}] Could not find session token in 'When' results dictionary. {e}", thenStatement.GetType().Name); } catch (Exception e) { thenStatement.GetStatementLogger() .Warning($"[{{ContextStatement}}] An error occured during logout. {e}", thenStatement.GetType().Name); } return(thenStatement); }
public override REBase Copy() { REExpression _condition = (Condition != null)? (REExpression)Condition.Copy() : null; REStatement _thenStatement = (ThenStatement != null)? (REStatement)ThenStatement.Copy() : null; REStatement _elseStatement = (ElseStatement != null)? (REStatement)ElseStatement.Copy() : null; return(new REIfStatement(_condition, _thenStatement, _elseStatement)); }
public static ThenStatement SessionTokenIsPresent(this ThenStatement thenStatement, string testKey = null) { thenStatement.GetStatementLogger() .Information("[{ContextStatement}] Looking for session token in the 'When' dictionary", thenStatement.GetType().Name); Assert.That(thenStatement.GetResultData <string>(BddKeyConstants.SessionTokenKey + testKey), Is.Not.Empty, "Expected to have session token, but found none."); return(thenStatement); }
public static ThenStatement SessionTokenIsInvalid(this ThenStatement thenStatement, string testKey = null) { thenStatement.GetStatementLogger() .Information("[{ContextStatement}] Looking for session token in the 'When' dictionary", thenStatement.GetType().Name); var session = thenStatement.GetResultData <string>(BddKeyConstants.SessionTokenKey + testKey); _facade.GetMe(session).AssertError(HttpStatusCode.Unauthorized); return(thenStatement); }
public static ThenStatement CurrentUserIsEqualTo(this ThenStatement thenStatement, TestUserModel expectedUser) { thenStatement.GetStatementLogger() .Information("[{ContextStatement}] Comparing 'GetMe' response with expected user model", thenStatement.GetType().Name); var currentUser = thenStatement.GetResultData <TestUserModel>(BddKeyConstants.CurrentUserResponse); Assert.IsEmpty(ProfileHelper.CompareUserProfiles(expectedUser, currentUser)); return(thenStatement); }
public static ThenStatement UsersApiKeysDoNotContainGiven(this ThenStatement thenStatement, string testKey = null) { thenStatement.GetStatementLogger() .Information("[{ContextStatement}] Looking for given apiKey in the 'When' dictionary", thenStatement.GetType().Name); var givenApiKeyId = thenStatement.GetGivenData <string>(BddKeyConstants.ApiKeyToRemove + testKey); var userApiKeys = thenStatement.GetResultData <TestApiKeysList>(BddKeyConstants.UserApiKeys + testKey); Assert.False(userApiKeys.Entities.Select(e => e.Id).Contains(givenApiKeyId), $"Expected '{givenApiKeyId}' api key to be absent in user keys."); return(thenStatement); }
public static ThenStatement UsersApiKeysContainGiven(this ThenStatement thenStatement, string testKey = null) { thenStatement.GetStatementLogger() .Information("[{ContextStatement}] Looking for given apiKey in the 'When' dictionary", thenStatement.GetType().Name); var givenApiKey = thenStatement.GetGivenData <TestUserApiKeyJsonEntity>(BddKeyConstants.NewApiKey + testKey); var userApiKeys = thenStatement.GetResultData <TestApiKeysList>(BddKeyConstants.UserApiKeys + testKey); Assert.That(userApiKeys.Entities.Select(e => e.Description), Contains.Item(givenApiKey.Description)); return(thenStatement); }
public override void Compile(CompileContext context) { context.Add(Tokens.If); Condition.Compile(context); context.Add(Tokens.Then); ThenStatement.Compile(context); if (ElseStatement != null) { context.Add(Tokens.Else); ElseStatement.Compile(context); } context.Add(Tokens.End); }
public static ThenStatement CurrentUserIsEqualToExpected(this ThenStatement thenStatement) { thenStatement.GetStatementLogger() .Information("[{ContextStatement}] Comparing given user credentials with response from 'GetMe'", thenStatement.GetType().Name); var currentUser = thenStatement.GetResultData <TestUserModel>(BddKeyConstants.CurrentUserResponse); var expectedUser = thenStatement.GetGivenData <TestLoginModel>(); Assert.That(currentUser.Email, Is.EqualTo(expectedUser.Email)); Assert.That(currentUser.Password, Is.Null, "Expected user password to be hidden"); Assert.That(currentUser.Id, Is.Not.Null, "Expected current user to have any Id"); return(thenStatement); }
public override void AcceptChildren(WSqlFragmentVisitor visitor) { if (Predicate != null) { Predicate.Accept(visitor); ThenStatement.Accept(visitor); } if (ElseStatement != null) { ElseStatement.Accept(visitor); } base.AcceptChildren(visitor); }
/// <inheritdoc /> protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame) { var condition = Condition.Eval(context, env, frame); if (condition.IsErrorValue) { return(condition); } // TODO:ST: I don't think this condition is correct. // In this case the result would be 1: const x = 1; const y = if (false) {x++;}else{x++;} // if statement is a statement, the result always should be void or undefined. return(Expression.IsTruthy(condition) ? ThenStatement.Eval(context, env, frame) : ((ElseStatement == null) ? EvaluationResult.Undefined : ElseStatement.Eval(context, env, frame))); }
public virtual void Execute(IDictionary <string, object> context) { if (Condition(context)) { if (ThenStatement != null) { ThenStatement.Execute(context); } } else { if (ElseStatement != null) { ElseStatement.Execute(context); } } }
public void ExecuteHandler(ThenStatement handler, string arg1) { bool allOK = true; foreach (Operator condition in conditions) { if (!condition.Execute()) { allOK = false; break; } } if (allOK) { handler(arg1); } }
public override void Execute ( PftContext context ) { if (Condition.Evaluate(context)) { if (ThenStatement != null) { ThenStatement.Execute(context); } } else { if (ElseStatement != null) { ElseStatement.Execute(context); } } }
public static ThenStatement TimeSeriesIsNotPresentInUserTimeSeries(this ThenStatement thenStatement, TestTimeSeriesMetadataModel expected, string testKey = null) { List <TestTimeSeriesMetadataModel> actual = null; try { actual = thenStatement.GetResultData <List <TestTimeSeriesMetadataModel> >( BddKeyConstants.UserTimeSeries + testKey); } catch (KeyNotFoundException e) { Assert.Fail("Was unable to get user time-series due to request failure."); } Assert.That(!actual.Any(model => Equals(model, expected)), $"Expected {expected} to be removed from user time-series"); return(thenStatement); }
public static ThenStatement TimeSeriesIsPresentInUserTimeSeries(this ThenStatement thenStatement, TestTimeSeriesMetadataModel expected, string testKey = null) { List <TestTimeSeriesMetadataModel> actual = null; try { actual = thenStatement.GetResultData <List <TestTimeSeriesMetadataModel> >( BddKeyConstants.UserTimeSeries + testKey); } catch (KeyNotFoundException e) { Assert.Fail("Was unable to get user time-series due to request failure."); } Assert.Contains(expected, actual); return(thenStatement); }
public static ThenStatement TimeSeriesByIdIsEqualTo(this ThenStatement thenStatement, TestTimeSeriesMetadataModel expected, string testKey = null) { TestTimeSeriesMetadataModel actual = null; try { actual = thenStatement.GetResultData <TestTimeSeriesMetadataModel>( BddKeyConstants.UserTimeSeriesById + testKey); } catch (KeyNotFoundException e) { Assert.Fail("Was unable to get user time-series due to request failure."); } Assert.That(actual, Is.EqualTo(expected)); return(thenStatement); }
public static ThenStatement CreatedTimeSeriesIsEqualToExpected(this ThenStatement thenStatement, string testKey = null) { var expected = thenStatement.GetGivenData <TestTimeSeriesMetadataModel>(BddKeyConstants.TimeSeriesToCreate + testKey); TestTimeSeriesMetadataModel actual = null; try { actual = thenStatement.GetResultData <TestTimeSeriesMetadataModel>( BddKeyConstants.CreatedTimeSeries + testKey); } catch (KeyNotFoundException e) { Assert.Fail("Was unable to get created time-series due to request failure."); } var currentUser = _profileApiFacade.GetMe(thenStatement.GetGivenData <string>(BddKeyConstants.SessionTokenKey + testKey)) .Map <TestUserModel>(); Assert.That(actual, Is.EqualTo(expected)); Assert.That(actual.DateCreated, Is.Not.Empty); Assert.That(actual.InfluxId, Is.Not.Empty); Assert.That(actual.UserId, Is.EqualTo(currentUser.Id)); try { var creationTime = DateTimeOffset.Parse(actual.DateCreated); Assert.That(DateTimeOffset.UtcNow - creationTime, Is.LessThan(TimeSpan.FromHours(1))); } catch { Assert.Fail($"Could not parse createdDate {actual.DateCreated}"); } return(thenStatement); }
internal override void CompileBy(FunctionCompiler compiler) { Condition.CompileBy(compiler, false); if (_elseStatement == null) { var endLabel = compiler.Emitter.DefineLabel(); compiler.Emitter.Emit(OpCode.GotoIfFalse, endLabel); ThenStatement.CompileBy(compiler); compiler.Emitter.MarkLabel(endLabel); } else { var endLabel = compiler.Emitter.DefineLabel(); var falseLabel = compiler.Emitter.DefineLabel(); compiler.Emitter.Emit(OpCode.GotoIfFalse, falseLabel); _thenStatement.CompileBy(compiler); compiler.Emitter.Emit(OpCode.Goto, endLabel); compiler.Emitter.MarkLabel(falseLabel); _elseStatement.CompileBy(compiler); compiler.Emitter.MarkLabel(endLabel); } compiler.MarkEndOfStatement(); }
public override XElement ToXML() { var conditionXml = new XElement("Condition"); if (IsComparison) { if (IsComparisonToConstant) { conditionXml.Add(new XElement("Type", "ComparisonToConstant")); } else if (IsComparisonToVariable) { conditionXml.Add(new XElement("Type", "ComparisonToVariable")); } if (this.SelectedVariable != null && this.SelectedVariable.LinkedVariable != null) { conditionXml.Add(new XElement("Left", this.SelectedVariable.LinkedVarId)); } if (this.IsEquals) { conditionXml.Add(new XElement("Comparison", "EQ")); } else if (this.IsNotEquals) { conditionXml.Add(new XElement("Comparison", "NEQ")); } else if (this.IsLessThan) { conditionXml.Add(new XElement("Comparison", "LT")); } else if (this.IsLessThanOrEqualTo) { conditionXml.Add(new XElement("Comparison", "LTE")); } else if (this.IsGreaterThan) { conditionXml.Add(new XElement("Comparison", "GT")); } else if (this.IsGreaterThanOrEqualTo) { conditionXml.Add(new XElement("Comparison", "GTE")); } if (this.IsComparisonToVariable && this.VariableToCompare != null && this.VariableToCompare.LinkedVariable != null) { conditionXml.Add(new XElement("Right", this.VariableToCompare.LinkedVarId)); if (this.IsDateTime) { conditionXml.Add(new XElement("VarType", "DateTime")); } else if (this.IsNumber) { conditionXml.Add(new XElement("VarType", "Number")); } else if (this.IsString) { conditionXml.Add(new XElement("VarType", "String")); } } if (this.IsComparisonToConstant) { if (this.IsDateTime) { conditionXml.Add(new XElement("Right", this.DateTimeToCompareTo.ToString())); conditionXml.Add(new XElement("VarType", "DateTime")); } else if (this.IsNumber) { conditionXml.Add(new XElement("Right", this.NumberToCompareTo.ToString())); conditionXml.Add(new XElement("VarType", "Number")); } else if (this.IsString) { conditionXml.Add(new XElement("Right", this.StringToCompareTo)); conditionXml.Add(new XElement("VarType", "String")); } } } if (ItemIsNotNull) { conditionXml.Add(new XElement("Type", "ItemIsNotNull")); conditionXml.Add(new XElement("VarRef", this.SelectedVariable.LinkedVarId)); } if (ItemIsClass) { conditionXml.Add(new XElement("Type", "ItemIsClass")); conditionXml.Add(new XElement("VarRef", this.SelectedVariable.LinkedVarId)); conditionXml.Add(new XElement("ClassName", this.SelectedClassName)); } if (PlayerHasItem) { conditionXml.Add(new XElement("Type", "PlayerHasItem")); conditionXml.Add(new XElement("ItemRef", this.SelectedItem.LinkedItemId)); } return(new XElement("If", conditionXml, new XElement("Then", ThenStatement.ToXML()), new XElement("Else", ElseStatement.ToXML()))); }
/// <inheritdoc /> public override string ToDebugString() { var @else = ElseStatement != null ? "else " + ElseStatement.ToDebugString() : string.Empty; return(I($"if ({Condition.ToDebugString()}) {ThenStatement.ToDebugString()}{@else}")); }
/// <inheritdoc /> protected override void DoSerialize(BuildXLWriter writer) { Condition.Serialize(writer); ThenStatement.Serialize(writer); Serialize(ElseStatement, writer); }