public void DefineVariableWithInitialValue() { Context context = new Context(); DefineVariableCommand expr = new DefineVariableCommand(null, "a", new ConstantExpression(1)); Assert.AreEqual(1, expr.Execute(context)); Assert.IsTrue(context.HasVariable("a")); Assert.AreEqual(1, context.GetValue("a")); Assert.AreEqual("a", expr.Name); Assert.IsNull(expr.TypeExpression); }
public void DefineVariableWithTypeAndInitialValue() { Context context = new Context(); IExpression typeexpr = new VariableExpression("List"); DefineVariableCommand expr = new DefineVariableCommand(typeexpr, "a", new ConstantExpression(1)); Assert.AreEqual(1, expr.Execute(context)); Assert.IsTrue(context.HasVariable("a")); Assert.AreEqual(1, context.GetValue("a")); Assert.AreEqual("a", expr.Name); Assert.AreEqual(typeexpr, expr.TypeExpression); }
private ICommand ParseDefineVariableCommand(IExpression typeexpression, string name) { DefineVariableCommand command; if (this.TryParseToken("=", TokenType.Operator)) command = new DefineVariableCommand(typeexpression, name, this.ParseExpression()); else command = new DefineVariableCommand(typeexpression, name); this.ParseToken(";", TokenType.Separator); return command; }