public void Invocation_SimpleComposition()
        {
            CompleteInCSharpFile(@"
                namespace N {
                    public class H {
                        public int Get() {
                            return 1;
                        }
                    }
                    public class C {
                        public void A(H h) {
                            var i = 1 + h.Get();
                            $
                        }
                    }
                }
            ");

            var mA = NewMethodDeclaration(Fix.Void, "A", "[N.H, TestProject] h");

            mA.Body.Add(SSTUtil.Declare("i", Fix.Int));
            mA.Body.Add(SSTUtil.Declare("$0", Fix.Int));
            mA.Body.Add(
                SSTUtil.AssignmentToLocal(
                    "$0",
                    SSTUtil.InvocationExpression(
                        "h",
                        Names.Method("[{0}] [N.H, TestProject].Get()", Fix.Int))));
            mA.Body.Add(SSTUtil.AssignmentToLocal("i", SSTUtil.ComposedExpression("$0")));

            AssertAllMethods(mA);
        }
Example #2
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 CombinedInlineIfElse()
        {
            CompleteInClass(@"
                public void A()
                {
                    var i = (true ? 1 : 2) + 3;
                    $
                }
            ");

            var mA = NewMethodDeclaration(Fix.Void, "A");

            mA.Body.Add(SSTUtil.Declare("i", Fix.Int));
            mA.Body.Add(SSTUtil.Declare("$0", Fix.Int));
            mA.Body.Add(
                SSTUtil.AssignmentToLocal(
                    "$0",
                    new IfElseExpression
            {
                Condition      = new ConstantValueExpression(),
                ThenExpression = new ConstantValueExpression(),
                ElseExpression = new ConstantValueExpression()
            }));
            mA.Body.Add(SSTUtil.AssignmentToLocal("i", SSTUtil.ComposedExpression("$0")));

            AssertAllMethods(mA);
        }
        public void ReferenceExpression()
        {
            var sst = new ReferenceExpression {
                Reference = SSTUtil.VariableReference("variable")
            };

            AssertPrint(sst, "variable");
        }
Example #5
0
        public void InvocationExpression_Static()
        {
            var a = SSTUtil.InvocationExpression(GetStaticMethod("B2"), Refs("c2"));

            Assert.AreEqual(new VariableReference(), a.Reference);
            Assert.AreEqual(GetStaticMethod("B2"), a.MethodName);
            Assert.AreEqual(Refs("c2"), a.Parameters);
        }
        public void Assignment()
        {
            var sst = SSTUtil.AssignmentToLocal("var", new ConstantValueExpression {
                Value = "true"
            });

            AssertPrint(sst, "var = true;");
        }
Example #7
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);
        }
Example #8
0
        public void ComposedExpression()
        {
            var actual   = SSTUtil.ComposedExpression("a", "b");
            var expected = new ComposedExpression {
                References = Lists.NewList(Ref("a"), Ref("b"))
            };

            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void Return()
        {
            var actual   = SSTUtil.Return(new ConstantValueExpression());
            var expected = new ReturnStatement
            {
                Expression = new ConstantValueExpression()
            };

            Assert.AreEqual(expected, actual);
        }
Example #10
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());
        }
Example #11
0
        public void SettingValues()
        {
            var a = SSTUtil.InvocationExpression("a1", GetMethod("A2"), Refs("a3"));

            Assert.AreEqual(new VariableReference {
                Identifier = "a1"
            }, a.Reference);
            Assert.AreEqual(GetMethod("A2"), a.MethodName);
            Assert.AreEqual(Refs("a3"), a.Parameters);
        }
        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 FieldReference()
        {
            var sst = new FieldReference
            {
                FieldName = Names.Field("[FieldType,P] [DeclaringType,P].F"),
                Reference = SSTUtil.VariableReference("o")
            };

            AssertPrint(sst, "o.F");
        }
        public void Equality_ReallyTheSame()
        {
            Assert.AreEqual(GetMethod("a"), GetMethod("a"));

            var a = SSTUtil.InvocationExpression("o", GetMethod("A"), RefExprs("a", "b", "c"));
            var b = SSTUtil.InvocationExpression("o", GetMethod("A"), RefExprs("a", "b", "c"));

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
        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");
        }
Example #17
0
        public void Declare()
        {
            var actual   = SSTUtil.Declare("a", Names.UnknownType);
            var expected = new VariableDeclaration
            {
                Reference = Ref("a"),
                Type      = Names.UnknownType
            };

            Assert.AreEqual(expected, actual);
        }
        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)");
        }
Example #19
0
        public void ReferenceExprToVariable()
        {
            var actual   = SSTUtil.ReferenceExprToVariable("a");
            var expected = new ReferenceExpression
            {
                Reference = new VariableReference {
                    Identifier = "a"
                }
            };

            Assert.AreEqual(expected, actual);
        }
Example #20
0
        public void LockBlock()
        {
            var actual   = SSTUtil.LockBlock("a");
            var expected = new LockBlock
            {
                Reference = new VariableReference {
                    Identifier = "a"
                }
            };

            Assert.AreEqual(expected, actual);
        }
Example #21
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);
        }
Example #22
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());
        }
        public void ComposedExpression()
        {
            var sst = new ComposedExpression
            {
                References =
                {
                    SSTUtil.VariableReference("a"),
                    SSTUtil.VariableReference("b"),
                    SSTUtil.VariableReference("c")
                }
            };

            AssertPrint(sst, "composed(a, b, c)");
        }
Example #24
0
        public void InvocationStatement_Static()
        {
            var actual   = SSTUtil.InvocationStatement(GetStaticMethod("B2"), Refs("c2"));
            var expected = new ExpressionStatement
            {
                Expression = new InvocationExpression
                {
                    MethodName = GetStaticMethod("B2"),
                    Parameters = { VarRefExpr("c2") }
                }
            };

            Assert.AreEqual(expected, actual);
        }
Example #25
0
        public void UsingBlock()
        {
            var sst = new UsingBlock
            {
                Reference = SSTUtil.VariableReference("variable"),
                Body      = { new BreakStatement() }
            };

            AssertPrint(
                sst,
                "using (variable)",
                "{",
                "    break;",
                "}");
        }
Example #26
0
        public void LockBlock()
        {
            var sst = new LockBlock
            {
                Reference = SSTUtil.VariableReference("variable"),
                Body      = { new ContinueStatement() }
            };

            AssertPrint(
                sst,
                "lock (variable)",
                "{",
                "    continue;",
                "}");
        }
        public void CompositionOfTypeOf()
        {
            CompleteInClass(@"
                public void A()
                {
                    var t = typeof(int) == typeof(string);
                    $
                }
            ");

            var mA = NewMethodDeclaration(SSTAnalysisFixture.Void, "A");

            mA.Body.Add(SSTUtil.Declare("t", SSTAnalysisFixture.Bool));
            mA.Body.Add(SSTUtil.AssignmentToLocal("t", new ConstantValueExpression()));

            AssertAllMethods(mA);
        }
        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);");
        }
Example #29
0
        public void ArrayInit_Constant()
        {
            CompleteInClass(@"
                public void A()
                {
                    var arr = new[] {1,2,3};
                    $
                }
            ");

            var mA = NewMethodDeclaration(Fix.Void, "A");

            mA.Body.Add(SSTUtil.Declare("arr", Fix.IntArray));
            mA.Body.Add(SSTUtil.AssignmentToLocal("arr", new ConstantValueExpression()));

            AssertAllMethods(mA);
        }
        public void Is_Const()
        {
            CompleteInClass(@"
                public void A()
                {
                    var isInstanceOf = 1 is double;
                    $
                }
            ");

            var mA = NewMethodDeclaration(SSTAnalysisFixture.Void, "A");

            mA.Body.Add(SSTUtil.Declare("isInstanceOf", SSTAnalysisFixture.Bool));
            mA.Body.Add(SSTUtil.AssignmentToLocal("isInstanceOf", new ConstantValueExpression()));

            AssertAllMethods(mA);
        }