private void TestUnary(UnaryOperationKind kind) { string text; if (Operation.IsPrefixOperation(kind)) { text = Operation.GetText(kind) + "$a"; } else { text = "$a" + Operation.GetText(kind); } var expr = NSScript.ParseExpression(text) as UnaryExpression; Assert.NotNull(expr); Assert.Equal(SyntaxNodeKind.UnaryExpression, expr.Kind); Assert.Equal(kind, expr.OperationKind); var operand = expr.Operand as Variable; Assert.NotNull(operand); Assert.Equal("$a", operand.Name.FullName); Assert.Equal(text, expr.ToString()); }
public void TestConstant() { string text = "center"; var constant = NSScript.ParseExpression(text) as NamedConstant; Assert.NotNull(constant); Assert.Equal(SyntaxNodeKind.NamedConstant, constant.Kind); Assert.Equal(text, constant.Name.FullName); Assert.Equal(text, constant.ToString()); }
public void TestVariableReference() { string text = "SomeMethod($a);"; var invocation = NSScript.ParseExpression(text) as MethodCall; var arg = invocation.Arguments[0] as Variable; Assert.NotNull(arg); Assert.Equal(SyntaxNodeKind.Variable, arg.Kind); }
public void TestNumericLiteralExpression() { string literal = "42"; var expr = NSScript.ParseExpression(literal) as Literal; Assert.NotNull(expr); Assert.Equal(SyntaxNodeKind.Literal, expr.Kind); Assert.Equal(literal, expr.Text); Assert.Equal(42, expr.Value.RawValue); Assert.Equal(literal, expr.ToString()); }
public void TestVariableWithHashSigil() { string text = "#testVar"; var variable = NSScript.ParseExpression(text) as Variable; Assert.NotNull(variable); Assert.Equal(SyntaxNodeKind.Variable, variable.Kind); Assert.Equal(text, variable.Name.FullName); Assert.Equal("testVar", variable.Name.SimplifiedName); Assert.Equal(SigilKind.Hash, variable.Name.Sigil); Assert.Equal(text, variable.ToString()); }
public void TestMethodCall() { string text = "WaitKey(10000);"; var call = NSScript.ParseExpression(text) as MethodCall; Assert.NotNull(call); Assert.Equal(SyntaxNodeKind.MethodCall, call.Kind); Assert.Equal("WaitKey", call.TargetMethodName.FullName); Assert.Equal(call.TargetMethodName.FullName, call.TargetMethodName.SimplifiedName); Assert.Equal(SigilKind.None, call.TargetMethodName.Sigil); Assert.Equal(1, call.Arguments.Length); Assert.Equal(text, call.ToString()); }
private void TestAssignment(AssignmentOperationKind kind) { string text = "$a " + Operation.GetText(kind) + " 42"; var expr = NSScript.ParseExpression(text) as AssignmentExpression; Assert.NotNull(expr); Assert.Equal(SyntaxNodeKind.AssignmentExpression, expr.Kind); Assert.Equal(kind, expr.OperationKind); var target = expr.Target as Variable; Assert.NotNull(target); Assert.Equal("$a", target.Name.FullName); var value = expr.Value as Literal; Assert.NotNull(value); Assert.Equal(42, value.Value.RawValue); }
private void TestBinary(BinaryOperationKind kind) { string text = "$a " + Operation.GetText(kind) + " $b"; var expr = NSScript.ParseExpression(text) as BinaryExpression; Assert.NotNull(expr); Assert.Equal(SyntaxNodeKind.BinaryExpression, expr.Kind); Assert.Equal(kind, expr.OperationKind); var left = expr.Left as Variable; Assert.NotNull(left); Assert.Equal("$a", left.Name.FullName); var right = expr.Right as Variable; Assert.NotNull(right); Assert.Equal("$b", right.Name.FullName); Assert.Equal(text, expr.ToString()); }