Ejemplo n.º 1
0
        public void SwitchBlock_NoDefaultBlock()
        {
            var sst = new SwitchBlock
            {
                Reference = SSTUtil.VariableReference("a"),
                Sections  =
                {
                    new CaseBlock
                    {
                        Label = new ConstantValueExpression{
                            Value = "1"
                        },
                        Body =    { new BreakStatement(),            new BreakStatement() }
                    },
                    new CaseBlock {
                        Label = new ConstantValueExpression{
                            Value = "2"
                        }, Body = { new BreakStatement() }
                    }
                }
            };

            AssertPrint(
                sst,
                "switch (a)",
                "{",
                "    case 1:",
                "        break;",
                "        break;",
                "    case 2:",
                "        break;",
                "}");
        }
        public void ReferenceExpression()
        {
            var sst = new ReferenceExpression {
                Reference = SSTUtil.VariableReference("variable")
            };

            AssertPrint(sst, "variable");
        }
Ejemplo n.º 3
0
        public void InvocationExpression_NonStatic()
        {
            var a = SSTUtil.InvocationExpression("a1", GetMethod("B1"), Refs("c1"));

            Assert.AreEqual(SSTUtil.VariableReference("a1"), a.Reference);
            Assert.AreEqual(GetMethod("B1"), a.MethodName);
            Assert.AreEqual(Refs("c1"), a.Parameters);
        }
Ejemplo n.º 4
0
        public void Equality_DifferentReference()
        {
            var a = new VariableDeclaration {
                Reference = SSTUtil.VariableReference("a")
            };
            var b = new VariableDeclaration();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void FieldReference()
        {
            var sst = new FieldReference
            {
                FieldName = Names.Field("[FieldType,P] [DeclaringType,P].F"),
                Reference = SSTUtil.VariableReference("o")
            };

            AssertPrint(sst, "o.F");
        }
        public void MethodReference()
        {
            var sst = new MethodReference
            {
                MethodName = Names.Method("[ReturnType,P] [DeclaringType,P].M([ParameterType,P] p)"),
                Reference  = SSTUtil.VariableReference("o")
            };

            AssertPrint(sst, "o.M");
        }
        public void PropertyReference()
        {
            var sst = new PropertyReference
            {
                PropertyName = Names.Property("get set [PropertyType,P] [DeclaringType,P].P()"),
                Reference    = SSTUtil.VariableReference("o")
            };

            AssertPrint(sst, "o.P");
        }
        public void EventReference()
        {
            var sst = new EventReference
            {
                EventName = Names.Event("[EventType,P] [DeclaringType,P].E"),
                Reference = SSTUtil.VariableReference("o")
            };

            AssertPrint(sst, "o.E");
        }
        public void InvocationExpression_NullValue()
        {
            var sst = new InvocationExpression
            {
                Reference  = SSTUtil.VariableReference("this"),
                MethodName = Names.Method("[R,P] [D,P].M([T,P] p)"),
                Parameters = { Null() }
            };

            AssertPrint(sst, "this.M(null)");
        }
Ejemplo n.º 10
0
        public void Equality_ReallyEquals()
        {
            var a = new VariableDeclaration {
                Reference = SSTUtil.VariableReference("a"), Type = Names.Type("T1,P1")
            };
            var b = new VariableDeclaration {
                Reference = SSTUtil.VariableReference("a"), Type = Names.Type("T1,P1")
            };

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
Ejemplo n.º 11
0
        public void SettingValues()
        {
            var sut = new VariableDeclaration
            {
                Reference = SSTUtil.VariableReference("a"),
                Type      = Names.Type("T,P")
            };

            Assert.False(sut.IsMissing);
            Assert.AreEqual(SSTUtil.VariableReference("a"), sut.Reference);
            Assert.AreEqual(Names.Type("T,P"), sut.Type);
        }
        public void ComposedExpression()
        {
            var sst = new ComposedExpression
            {
                References =
                {
                    SSTUtil.VariableReference("a"),
                    SSTUtil.VariableReference("b"),
                    SSTUtil.VariableReference("c")
                }
            };

            AssertPrint(sst, "composed(a, b, c)");
        }
Ejemplo n.º 13
0
        public void LockBlock()
        {
            var sst = new LockBlock
            {
                Reference = SSTUtil.VariableReference("variable"),
                Body      = { new ContinueStatement() }
            };

            AssertPrint(
                sst,
                "lock (variable)",
                "{",
                "    continue;",
                "}");
        }
Ejemplo n.º 14
0
        public void UsingBlock()
        {
            var sst = new UsingBlock
            {
                Reference = SSTUtil.VariableReference("variable"),
                Body      = { new BreakStatement() }
            };

            AssertPrint(
                sst,
                "using (variable)",
                "{",
                "    break;",
                "}");
        }
        public void ExpressionStatement()
        {
            var invocation = new InvocationExpression
            {
                Reference  = SSTUtil.VariableReference("this"),
                MethodName = Names.Method("[ReturnType,P] [DeclaringType,P].M([ParameterType,P] p)"),
                Parameters = { new ConstantValueExpression {
                                   Value = "1"
                               } }
            };

            var sst = new ExpressionStatement {
                Expression = invocation
            };

            AssertPrint(sst, "this.M(1);");
        }
Ejemplo n.º 16
0
        public void ForEachLoop()
        {
            var sst = new ForEachLoop
            {
                Declaration     = SSTUtil.Declare("e", Names.Type("T,P")),
                LoopedReference = SSTUtil.VariableReference("elements"),
                Body            =
                {
                    new ContinueStatement()
                }
            };

            AssertPrint(
                sst,
                "foreach (T e in elements)",
                "{",
                "    continue;",
                "}");
        }
        public void EventSubscriptionStatement_Unsubscribe()
        {
            var sst = new EventSubscriptionStatement
            {
                Reference = new EventReference
                {
                    EventName = Names.Event("[EventType,P] [DeclaringType,P].SomeEvent"),
                    Reference = SSTUtil.VariableReference("o")
                },
                Expression = new ReferenceExpression
                {
                    Reference = new MethodReference
                    {
                        MethodName = Names.Method("[ReturnType,P] [DeclaringType,P].Handler()"),
                        Reference  = SSTUtil.VariableReference("this")
                    }
                },
                Operation = EventSubscriptionOperation.Remove
            };

            AssertPrint(sst, "o.SomeEvent -= this.Handler;");
        }
        public void VariableReference()
        {
            var sst = SSTUtil.VariableReference("variable");

            AssertPrint(sst, "variable");
        }