Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public void CombinedUnary()
        {
            CompleteInClass(@"
                public void A(int i)
                {
                    var j = 0 + (-i);
                    $
                }
            ");

            var mA = NewMethodDeclaration(Fix.Void, "A", string.Format("[{0}] i", Fix.Int));

            mA.Body.Add(SSTUtil.Declare("j", Fix.Int));
            mA.Body.Add(SSTUtil.AssignmentToLocal("j", SSTUtil.ComposedExpression("i")));

            AssertAllMethods(mA);
        }
Exemplo n.º 5
0
        public void CombinedCast()
        {
            CompleteInClass(@"
                public void A(object o)
                {
                    var i = ((string) o) + ((string) 1.0);
                    $
                }
            ");

            var mA = NewMethodDeclaration(Fix.Void, "A", string.Format("[{0}] o", Fix.Object));

            mA.Body.Add(SSTUtil.Declare("i", Fix.String));
            mA.Body.Add(SSTUtil.AssignmentToLocal("i", SSTUtil.ComposedExpression("o")));

            AssertAllMethods(mA);
        }
Exemplo n.º 6
0
        public void Invocation_RealComposition()
        {
            CompleteInCSharpFile(@"
                namespace N {
                    public class H {
                        public int Get() {
                            return 1;
                        }
                    }
                    public class C {
                        public void A(H h1, H h2) {
                            var i = h1.Get() + h2.Get() + 1;
                            $
                        }
                    }
                }
            ");

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

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

            AssertAllMethods(mA);
        }
Exemplo n.º 7
0
        public void ArrayInit_Composed()
        {
            CompleteInClass(@"
                public void A()
                {
                    var n = 1;
                    var arr = new[] {1,2,n};
                    $
                }
            ");

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

            mA.Body.Add(SSTUtil.Declare("n", SSTAnalysisFixture.Int));
            mA.Body.Add(SSTUtil.AssignmentToLocal("n", new ConstantValueExpression()));
            mA.Body.Add(SSTUtil.Declare("arr", SSTAnalysisFixture.IntArray));
            mA.Body.Add(SSTUtil.AssignmentToLocal("arr", SSTUtil.ComposedExpression("n")));

            AssertAllMethods(mA);
        }
        public void Is_Reference()
        {
            CompleteInClass(@"
                public void A(object o)
                {
                    var isInstanceOf = o is string;
                    $
                }
            ");

            var mA = NewMethodDeclaration(
                SSTAnalysisFixture.Void,
                "A",
                string.Format("[{0}] o", SSTAnalysisFixture.Object));

            mA.Body.Add(SSTUtil.Declare("isInstanceOf", SSTAnalysisFixture.Bool));
            mA.Body.Add(SSTUtil.AssignmentToLocal("isInstanceOf", SSTUtil.ComposedExpression("o")));

            AssertAllMethods(mA);
        }
Exemplo n.º 9
0
        public void ArrayInit_WithArrays()
        {
            CompleteInClass(@"
                public void A()
                {
                    var arr = new[] {new[] {1, 2}, new[] {3, 4}};
                    $
                }
            ");

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

            mA.Body.Add(SSTUtil.Declare("arr", Names.Type("System.Int32[][], mscorlib, 4.0.0.0")));
            mA.Body.Add(SSTUtil.Declare("$0", SSTAnalysisFixture.IntArray));
            mA.Body.Add(SSTUtil.AssignmentToLocal("$0", new ConstantValueExpression()));
            mA.Body.Add(SSTUtil.Declare("$1", SSTAnalysisFixture.IntArray));
            mA.Body.Add(SSTUtil.AssignmentToLocal("$1", new ConstantValueExpression()));
            mA.Body.Add(SSTUtil.AssignmentToLocal("arr", SSTUtil.ComposedExpression("$0", "$1")));

            AssertAllMethods(mA);
        }
Exemplo n.º 10
0
        public void ArrayInit_WithCalls()
        {
            CompleteInClass(@"
                public void A(object o)
                {
                    var arr = new[] {1,2,o.GetHashCode()};
                    $
                }
            ");

            var mA = NewMethodDeclaration(
                SSTAnalysisFixture.Void,
                "A",
                string.Format("[{0}] o", SSTAnalysisFixture.Object));

            mA.Body.Add(SSTUtil.Declare("arr", SSTAnalysisFixture.IntArray));
            mA.Body.Add(SSTUtil.Declare("$0", SSTAnalysisFixture.Int));
            mA.Body.Add(SSTUtil.AssignmentToLocal("$0", SSTUtil.InvocationExpression("o", Fix.Object_GetHashCode)));
            mA.Body.Add(SSTUtil.AssignmentToLocal("arr", SSTUtil.ComposedExpression("$0")));

            AssertAllMethods(mA);
        }