PageRenderTime 66ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Runtime/Tests/ETScenarios/Miscellaneous/Comma.cs

#
C# | 56 lines | 43 code | 11 blank | 2 comment | 0 complexity | 7b82a3c359e9c78775dfa86a6377b94f MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. #if !CLR2
  2. using System.Linq.Expressions;
  3. #else
  4. using Microsoft.Scripting.Ast;
  5. #endif
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Reflection;
  9. namespace ETScenarios.Miscellaneous {
  10. using EU = ETUtils.ExpressionUtils;
  11. using Expr = Expression;
  12. using AstUtils = Microsoft.Scripting.Ast.Utils;
  13. public class Comma {
  14. // Pass no elements to the Comma
  15. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Comma 1", new string[] { "negative", "comma", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentException))]
  16. public static Expr Comma1(EU.IValidator V) {
  17. List<Expression> Expressions = new List<Expression>();
  18. Expressions.Add(EU.Throws<ArgumentException>(() => { Expr.Block(); }));
  19. return Expr.Empty();
  20. }
  21. // Using commas in multiple expressions that expect a value.
  22. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Comma 2", new string[] { "positive", "comma", "miscellaneous", "Pri1" })]
  23. public static Expr Comma2(EU.IValidator V) {
  24. List<Expression> Expressions = new List<Expression>();
  25. ParameterExpression Result = Expr.Variable(typeof(string), "");
  26. ParameterExpression TestValue = Expr.Variable(typeof(Int32), "");
  27. Expressions.Add(Expr.Assign(TestValue, Expr.Block(EU.ConcatEquals(Result, "C1"), Expr.Constant(1))));
  28. Expr Res =
  29. Expr.Add(
  30. Expr.Block(EU.ConcatEquals(Result, "C2"), Expr.Constant(1)),
  31. Expr.Block(EU.ConcatEquals(Result, "C3"), Expr.Constant(3)));
  32. Expressions.Add(
  33. Expr.Condition(
  34. Expr.LessThan(TestValue, Expr.Block(Expr.Constant(5))),
  35. Expr.Block(EU.ConcatEquals(Result, "C4"), Expr.Assign(TestValue, Expr.Constant(5)), Expr.Constant(true)),
  36. Expr.Block(EU.ConcatEquals(Result, "C5"), Expr.Constant(false))));
  37. Expressions.Add(EU.GenAreEqual(Res, Expr.Constant(4), "Comma 1"));
  38. Expressions.Add(EU.GenAreEqual(Result, Expr.Constant("C1C4C2C3"), "Comma 2"));
  39. Expressions.Add(EU.GenAreEqual(TestValue, Expr.Constant(5), "Comma 3"));
  40. var tree = EU.BlockVoid(new[] { Result, TestValue }, Expressions);
  41. V.Validate(tree);
  42. return tree;
  43. }
  44. }
  45. }