Example #1
0
        public static CodeRunnerInfo GenerateCodeRunnerInfo(int numStatements = 1, int level2Staements = 0)
        {
            CodeRunnerInfo info = new CodeRunnerInfo();

            info.Name          = "TestMethod";
            info.IsConstructor = false;

            info.blockInfo[0] = new BlockInfo();

            for (int i = 0; i < numStatements; i++)
            {
                StatementInfo sInfo = new StatementInfo();
                sInfo.LineNo = 9 + i;
                info.blockInfo[0].Add(sInfo);
            }

            if (level2Staements > 0)
            {
                info.blockInfo[1] = new BlockInfo();

                for (int i = 0; i < level2Staements; i++)
                {
                    StatementInfo sInfo = new StatementInfo();
                    sInfo.LineNo = 9 + i;
                    info.blockInfo[1].Add(sInfo);
                }
            }

            return(info);
        }
Example #2
0
        public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
        {
            int id = codeRunnerIds;
            CodeRunnerInfoCollector collector      = new CodeRunnerInfoCollector(root);
            CodeRunnerInfo          codeRunnerInfo = collector.Collect(node);

            CollectedClassInfo.AddCodeRunnerInfo(codeRunnerInfo, id);
            codeRunnerIds++;
            //base.VisitAccessorDeclaration(node);
        }
Example #3
0
        public void TestMethodBlockGenerator()
        {
            HookedRenderInfoGenerator generator = new HookedRenderInfoGenerator();
            ClassInfo      classInfo            = FactoryHelper.CreateClassInfo();
            CodeRunnerInfo codeRunnerInfo       = FactoryHelper.GenerateCodeRunnerInfo();

            classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0);
            int id = 0;

            CodeRunBlockRenderingInfo renderInfo = generator.CodeRunBlockRenderInfoForMethod(classInfo, id);

            Assert.IsTrue(renderInfo.renderingInfo[0][0].Contains("OnMethodEnter"));
            Assert.IsTrue(renderInfo.renderingInfo[0][1].Contains("LogLineRun"));
            Assert.IsTrue(renderInfo.renderingInfo[0][2].Contains("0"));
        }
Example #4
0
        private CodeRunnerInfo collectInfo(BaseMethodDeclarationSyntax node, string name, bool isConstructor = false)
        {
            var info = new CodeRunnerInfo();

            info.Name          = name;
            info.IsConstructor = isConstructor;

            // Collect all the statements and block infos
            info.blockInfo = collectBlocks(node.Body);

            // Check if the method is static
            info.IsStatic = CheckForStatic(node.Modifiers);

            // Collect all method arguments
            info.Arguments = CollectArguments(node.ParameterList);

            return(info);
        }
Example #5
0
        internal static TestCase GetLocalVarAssignmentCode()
        {
            string testMethod = @""" 
            class TestClass
            {
                void MethodA()
                {
                    int localVar1 = 99;
                    localVar1 = 45;
                }
            }
            """;

            ClassInfo      classInfo      = new ClassInfo();
            CodeRunnerInfo codeRunnerInfo = new CodeRunnerInfo();

            BlockInfo     block = new BlockInfo();
            StatementInfo s1    = new StatementInfo();

            s1.IsLocalVarDeclaration = true;
            block.StatementInfos.Add(s1);
            s1.LocalVarNames.Add("localVar1");
            s1.LineNo = 5;
            StatementInfo s2 = new StatementInfo();

            s2.IsLocalVarStateChanger = true;
            s2.LocalVarNames.Add("localVar1");
            block.StatementInfos.Add(s2);
            s1.LineNo = 6;

            codeRunnerInfo.blockInfo[0] = block;
            classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0);


            return(new TestCase
            {
                Code = testMethod,
                ClassInfo = classInfo
            });
        }
Example #6
0
        internal CodeRunnerInfo Collect(AccessorDeclarationSyntax node)
        {
            // Todo - Add unit tests for this

            var info = new CodeRunnerInfo();

            try
            {
                info.Name = getAccessorName(node);
            }
            catch
            {
            }

            // Collect all the statements and block infos
            info.blockInfo = collectBlocks(node.Body);

            // Check if the method is static
            info.IsStatic = CheckForStatic(node.Modifiers);

            return(info);
        }
Example #7
0
        public static TestCase GetSimple2LineMethodCase()
        {
            string    testMethod = @""" 
            class TestClass
            {
                void MethodA()
                {
                    int count = 0;
                    count ++;
                }
            }
            """;
            ClassInfo classInfo  = FactoryHelper.CreateClassInfo();

            classInfo.RelativeFilePath = "TestFile.cs";

            CodeRunnerInfo codeRunnerInfo = new CodeRunnerInfo();

            codeRunnerInfo.Name          = "MethodA";
            codeRunnerInfo.IsConstructor = false;

            codeRunnerInfo.blockInfo[0] = new BlockInfo();
            codeRunnerInfo.blockInfo[0].CloseBraceLineNo = 7;
            StatementInfo sInfo = new StatementInfo();

            sInfo = new StatementInfo {
                LineNo = 5
            };
            codeRunnerInfo.blockInfo[0].Add(sInfo);
            sInfo = new StatementInfo {
                LineNo = 6
            };
            codeRunnerInfo.blockInfo[0].Add(sInfo);

            classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0);

            CSfileInfo cSfileInfo = new CSfileInfo();

            cSfileInfo.Classes.Add(classInfo);

            Dictionary <int, List <string> > renderingInfo = new Dictionary <int, List <string> >()
            {
            };

            renderingInfo[0] = new List <string>()
            {
                "OnMethodEnter();",
                "LogLineRun()",
                "0",
                "LogLineRun()",
                "1",
                "LogLineRun()",
            };

            List <string> expectedStatementSubStrings = new List <string>()
            {
                "OnMethodEnter",
                "LogLineRun",
                "int count",
                "LogLineRun",
                "count ++",
            };

            SyntaxNode methSyntax = Helpers.GetFirstMethodSyntax(testMethod);

            SyntaxTree root = Helpers.GetRoot(testMethod);

            return(new TestCase
            {
                Code = testMethod,
                ClassInfo = classInfo,
                ExpectedStatements = expectedStatementSubStrings,
                ExpectedStatementCount = 6,
                Node = methSyntax,
                RenderInfo = renderingInfo,
                Root = root,
                FileName = classInfo.RelativeFilePath,
                CSFileInfo = cSfileInfo,
            });
        }
Example #8
0
        public static TestCase GetSingleIfMethod()
        {
            string testMethod = @""" 
            class TestClass
            {
                void MethodA()
                {
                    int b=3;
                    if(true)
                    {
                        int count = 0;
                    }
                }
            }
            """;
            MethodDeclarationSyntax methSyntax = Helpers.GetFirstMethodSyntax(testMethod);
            ClassInfo classInfo = FactoryHelper.CreateClassInfo();

            classInfo.RelativeFilePath = "TestFile.cs";

            CodeRunnerInfo codeRunnerInfo = new CodeRunnerInfo();

            codeRunnerInfo.Name          = "MethodA";
            codeRunnerInfo.IsConstructor = false;

            codeRunnerInfo.blockInfo[0] = new BlockInfo();
            codeRunnerInfo.blockInfo[0].CloseBraceLineNo = 9;
            codeRunnerInfo.blockInfo[1] = new BlockInfo();
            codeRunnerInfo.blockInfo[1].CloseBraceLineNo = 10;
            StatementInfo sInfo = new StatementInfo();

            sInfo = new StatementInfo {
                LineNo = 5
            };
            codeRunnerInfo.blockInfo[0].Add(sInfo);
            sInfo = new StatementInfo {
                LineNo = 6
            };
            codeRunnerInfo.blockInfo[0].Add(sInfo);
            sInfo = new StatementInfo {
                LineNo = 8
            };
            codeRunnerInfo.blockInfo[1].Add(sInfo);

            classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0);

            CSfileInfo cSfileInfo = new CSfileInfo();

            cSfileInfo.Classes.Add(classInfo);

            SyntaxTree root = Helpers.GetRoot(testMethod);

            List <string> expectedStatementSubStrings = new List <string>()
            {
                "OnMethodEnter",
                "LogLineRun",
                "int b",
                "LogLineRun",
                "if(true)",
                "LogLineRun",
                "LogLineRun",
                "int count",
                "LogLineRun",
            };

            return(new TestCase
            {
                Code = testMethod,
                ClassInfo = classInfo,
                ExpectedStatements = expectedStatementSubStrings,
                ExpectedStatementCount = 9,
                Node = methSyntax,
                Root = root,
                CSFileInfo = cSfileInfo,
                FileName = classInfo.RelativeFilePath
            });
        }