PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms 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
 1#if !CLR2
 2using System.Linq.Expressions;
 3#else
 4using Microsoft.Scripting.Ast;
 5#endif
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Reflection;
10
11namespace ETScenarios.Miscellaneous {
12    using EU = ETUtils.ExpressionUtils;
13    using Expr = Expression;
14    using AstUtils = Microsoft.Scripting.Ast.Utils;
15
16    public class Comma {
17        // Pass no elements to the Comma
18        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Comma 1", new string[] { "negative", "comma", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentException))]
19        public static Expr Comma1(EU.IValidator V) {
20            List<Expression> Expressions = new List<Expression>();
21
22            Expressions.Add(EU.Throws<ArgumentException>(() => { Expr.Block(); }));
23
24            return Expr.Empty();
25        }
26
27        // Using commas in multiple expressions that expect a value.
28        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Comma 2", new string[] { "positive", "comma", "miscellaneous", "Pri1" })]
29        public static Expr Comma2(EU.IValidator V) {
30            List<Expression> Expressions = new List<Expression>();
31            ParameterExpression Result = Expr.Variable(typeof(string), "");
32            ParameterExpression TestValue = Expr.Variable(typeof(Int32), "");
33
34            Expressions.Add(Expr.Assign(TestValue, Expr.Block(EU.ConcatEquals(Result, "C1"), Expr.Constant(1))));
35
36            Expr Res =
37                Expr.Add(
38                    Expr.Block(EU.ConcatEquals(Result, "C2"), Expr.Constant(1)),
39                    Expr.Block(EU.ConcatEquals(Result, "C3"), Expr.Constant(3)));
40
41            Expressions.Add(
42                Expr.Condition(
43                    Expr.LessThan(TestValue, Expr.Block(Expr.Constant(5))),
44                    Expr.Block(EU.ConcatEquals(Result, "C4"), Expr.Assign(TestValue, Expr.Constant(5)), Expr.Constant(true)),
45                    Expr.Block(EU.ConcatEquals(Result, "C5"), Expr.Constant(false))));
46
47            Expressions.Add(EU.GenAreEqual(Res, Expr.Constant(4), "Comma 1"));
48            Expressions.Add(EU.GenAreEqual(Result, Expr.Constant("C1C4C2C3"), "Comma 2"));
49            Expressions.Add(EU.GenAreEqual(TestValue, Expr.Constant(5), "Comma 3"));
50
51            var tree = EU.BlockVoid(new[] { Result, TestValue }, Expressions);
52            V.Validate(tree);
53            return tree;
54        }
55    }
56}