Ejemplo n.º 1
0
        public void Switch_Compile_NestedSwitch3()
        {
            // NB: See design remark in code.

            var res =
                CSharpStatement.Switch(
                    Expression.Constant(1),
                    Expression.Label(),
                    CSharpStatement.SwitchCase(
                        new[] { 5 },
                        Expression.Switch(
                            Expression.Constant(2),
                            Expression.SwitchCase(CSharpStatement.GotoCase(3), Expression.Constant(4))
                            )
                        )
                    );

            var red = res.Reduce(); // This doesn't throw because we don't recurse into the nested Switch.

            Assert.AreNotSame(red, res);

            var f = Expression.Lambda <Action>(res);

            AssertEx.Throws <ArgumentException>(() => f.Compile()); // must be reducible node
        }
Ejemplo n.º 2
0
 public void GotoCase_Factory_ArgumentChecking()
 {
     AssertEx.Throws <ArgumentException>(() => CSharpStatement.GotoCase(0.0));
     AssertEx.Throws <ArgumentException>(() => CSharpStatement.GotoCase(0.0f));
     AssertEx.Throws <ArgumentException>(() => CSharpStatement.GotoCase(0.0m));
     AssertEx.Throws <ArgumentException>(() => CSharpStatement.GotoCase(TimeSpan.Zero));
 }
Ejemplo n.º 3
0
        public void GotoCase_Visitor()
        {
            var g = CSharpStatement.GotoCase(42);

            var v = new V();

            Assert.AreSame(g, v.Visit(g));
            Assert.AreEqual(g.Kind, v.VisitedKind);
        }
Ejemplo n.º 4
0
        public void GotoCase_Properties()
        {
            var o = (object)42;
            var g = CSharpStatement.GotoCase(o);

            Assert.AreEqual(typeof(void), g.Type);
            Assert.AreEqual(CSharpExpressionType.Goto, g.CSharpNodeType);
            Assert.AreEqual(CSharpGotoKind.GotoCase, g.Kind);
            Assert.AreSame(o, g.Value);

            Assert.IsFalse(g.CanReduce);
            AssertEx.Throws <InvalidOperationException>(() => g.Reduce());
        }
Ejemplo n.º 5
0
 public void Switch_Compile_GotoCase3()
 {
     AssertCompile <int>((log, v) =>
                         SwitchLogValue(log,
                                        v,
                                        Expression.Block(log("D"), CSharpStatement.GotoCase(2), log("X")),
                                        CSharpStatement.SwitchCase(new[] { 1 }, log("A")),
                                        CSharpStatement.SwitchCase(new[] { 2 }, log("B"))
                                        ),
                         new Asserts <int>
     {
         { 0, "E", "D", "B" },
         { 1, "E", "A" },
         { 2, "E", "B" },
         { 3, "E", "D", "B" },
     }
                         );
 }
Ejemplo n.º 6
0
 public void Switch_Compile_GotoCase_Null1()
 {
     AssertCompile <int?>((log, v) =>
                          SwitchLogValue(log,
                                         v,
                                         Expression.Block(log("D"), CSharpStatement.GotoCase(null), log("X")),
                                         CSharpStatement.SwitchCase(new[] { 1 }, log("A")),
                                         CSharpStatement.SwitchCase(new[] { 2 }, log("B")),
                                         CSharpStatement.SwitchCase(new[] { default(int?) }, log("N"))
                                         ),
                          new Asserts <int?>
     {
         { 0, "E", "D", "N" },
         { 1, "E", "A" },
         { 2, "E", "B" },
         { 3, "E", "D", "N" },
         { null, "E", "N" }
     }
                          );
 }
Ejemplo n.º 7
0
 public void Switch_Compile_NestedSwitch2()
 {
     AssertCompile <int>((log, v) =>
                         SwitchLogValue(log,
                                        v,
                                        CSharpStatement.SwitchCase(
                                            new[] { 1 },
                                            CSharpStatement.Switch(
                                                Expression.Constant(3),
                                                Expression.Label(),
                                                CSharpStatement.SwitchCase(new[] { 2 }, log("C")),
                                                CSharpStatement.SwitchCase(new[] { 3 }, log("A"), CSharpStatement.GotoCase(2), log("X"))
                                                )
                                            ),
                                        CSharpStatement.SwitchCase(new[] { 2 }, log("XC")),
                                        CSharpStatement.SwitchCase(new[] { 3 }, log("B"), CSharpStatement.GotoCase(2))
                                        ),
                         new Asserts <int>
     {
         { 0, "E" },
         { 1, "E", "A", "C" },
         { 2, "E", "XC" },
         { 3, "E", "B", "XC" },
     }
                         );
 }
Ejemplo n.º 8
0
        public void Switch_Compile_GotoCase_Error()
        {
            var res = CSharpStatement.Switch(Expression.Constant(1), Expression.Label(), CSharpStatement.SwitchCase(new[] { 1 }, CSharpStatement.GotoCase(2)));

            AssertEx.Throws <InvalidOperationException>(() => res.Reduce(), ex => ex.Message.Contains("goto case"));
        }