public void GetLocalVariablesFromExpression() { AssignClassVarExpression cmd = new AssignClassVarExpression("one", new AssignExpression("a", new ConstantExpression(1))); var result = cmd.GetLocalVariables(); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.AreEqual("a", result[0]); }
public void ParseAssignClassVarCommand() { Parser parser = new Parser("@@a=2"); var expected = new AssignClassVarExpression("a", new ConstantExpression(2)); var result = parser.ParseCommand(); Assert.IsNotNull(result); Assert.AreEqual(expected, result); Assert.IsNull(parser.ParseCommand()); }
public void AssignValue() { AssignClassVarExpression cmd = new AssignClassVarExpression("one", new ConstantExpression(1)); DynamicClass cls = new DynamicClass(null); DynamicObject obj = new DynamicObject(cls); Context context = new Context(obj, null); var result = cmd.Evaluate(context); Assert.AreEqual(1, result); Assert.AreEqual(1, cls.GetValue("one")); }
public IExpression ParseExpression() { IExpression expr = this.ParseNoAssignExpression(); if (expr == null) { return(null); } if (!(expr is NameExpression) && !(expr is ClassVarExpression) && !(expr is InstanceVarExpression) && !(expr is DotExpression) && !(expr is IndexedExpression)) { return(expr); } var token = this.lexer.NextToken(); if (token == null) { return(expr); } if (token.Type != TokenType.Operator || token.Value != "=") { this.lexer.PushToken(token); return(expr); } IExpression assignexpr = null; if (expr is NameExpression) { assignexpr = new AssignExpression(((NameExpression)expr).Name, this.ParseExpression()); } else if (expr is DotExpression) { assignexpr = new AssignDotExpressions((DotExpression)expr, this.ParseExpression()); } else if (expr is InstanceVarExpression) { assignexpr = new AssignInstanceVarExpression(((InstanceVarExpression)expr).Name, this.ParseExpression()); } else if (expr is ClassVarExpression) { assignexpr = new AssignClassVarExpression(((ClassVarExpression)expr).Name, this.ParseExpression()); } else if (expr is IndexedExpression) { assignexpr = new AssignIndexedExpression(((IndexedExpression)expr).Expression, ((IndexedExpression)expr).IndexExpression, this.ParseExpression()); } return(assignexpr); }
public void Equals() { AssignClassVarExpression cmd1 = new AssignClassVarExpression("a", new ConstantExpression(1)); AssignClassVarExpression cmd2 = new AssignClassVarExpression("a", new ConstantExpression(2)); AssignClassVarExpression cmd3 = new AssignClassVarExpression("b", new ConstantExpression(1)); AssignClassVarExpression cmd4 = new AssignClassVarExpression("a", new ConstantExpression(1)); Assert.IsTrue(cmd1.Equals(cmd4)); Assert.IsTrue(cmd4.Equals(cmd1)); Assert.AreEqual(cmd1.GetHashCode(), cmd4.GetHashCode()); Assert.IsFalse(cmd1.Equals(null)); Assert.IsFalse(cmd1.Equals(cmd2)); Assert.IsFalse(cmd1.Equals(cmd3)); Assert.IsFalse(cmd1.Equals(123)); }
public void GetLocalVariables() { AssignClassVarExpression cmd = new AssignClassVarExpression("one", new ConstantExpression(1)); Assert.IsNull(cmd.GetLocalVariables()); }