Beispiel #1
0
        static void DoSimpleSingleFileTest(
            string testName,
            string fileNamePrefix,
            string fileNameSuffix
            )
        {
            string       fileName = @"..\..\Input\" + fileNamePrefix + fileNameSuffix;
            ParameterSet pset     = new ParameterSet();

            pset.mUseTabsToIndent = true;

            TestFileWrapper regressionFile = new TestFileWrapper(fileName);

            EnvDTE.EditPoint tp1 = regressionFile.CreateEditPoint(null);
            tp1.StartOfDocument();
            EnvDTE.EditPoint tp2 = regressionFile.CreateEditPoint(null);
            tp2.EndOfDocument();
            CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2);
            regressionFile.WriteToFile(@"..\..\Output\" + fileNamePrefix + ".out" + fileNameSuffix);
            int lineNum = fileCompare(@"..\..\Output\" + fileNamePrefix + ".out" + fileNameSuffix,
                                      @"..\..\Compare\" + fileNamePrefix + ".compare" + fileNameSuffix);

            if (lineNum != -1)
            {
                throw new System.ApplicationException(
                          testName + " regression file does not match compare at line " + lineNum);
            }

            //now apply again and ensure consitancy
            tp1.StartOfDocument();
            tp2.EndOfDocument();
            CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2);
            regressionFile.WriteToFile(@"..\..\Output\" + fileNamePrefix + ".out2" + fileNameSuffix);
            lineNum = fileCompare(@"..\..\Output\" + fileNamePrefix + ".out2" + fileNameSuffix,
                                  @"..\..\Compare\" + fileNamePrefix + ".compare" + fileNameSuffix);
            if (lineNum != -1)
            {
                throw new System.ApplicationException(
                          testName + " 2nd run regression file does not match compare at line " + lineNum);
            }
            Console.WriteLine(testName + " tests PASSED.");
        }
Beispiel #2
0
        static void DoBlockTests()
        {
            string          fileName       = @"..\..\Input\Regression.cpp";
            TestFileWrapper regressionFile = new TestFileWrapper(fileName);

            /////////////////////////////////////////
            // first detection tests
            /////////////////////////////////////////
            foreach (GetBlockFromPointRegression val in mBlockPointValues)
            {
                val.doTest(regressionFile, fileName);
            }

            //////////////////////////////////////////
            // now formatting tests one by one
            //////////////////////////////////////////
            ParameterSet pset = new ParameterSet();

            pset.mUseTabsToIndent = true;
            EnvDTE.EditPoint[] tp = new EnvDTE.EditPoint[mBlockPointValues.Length];
            for (int i = 0; i < mBlockPointValues.Length; i++)
            {
                tp[i] = regressionFile.CreateEditPoint(null);
                tp[i].MoveToLineAndOffset(mBlockPointValues[i].retStartLine, 1);
            }
            for (int i = 0; i < tp.Length; i++)
            {
                try
                {
                    CommentReflowerObj.WrapBlockContainingPoint(pset, fileName, tp[i]);
                }
                catch (Exception)
                {
                    if (mBlockPointValues[i].retSuccess == true)
                    {
                        throw;
                    }
                }
            }
            regressionFile.WriteToFile(@"..\..\Output\Regression.out.cpp");
            int lineNum = fileCompare(@"..\..\Output\Regression.out.cpp", @"..\..\Compare\Regression.compare.cpp");

            if (lineNum != -1)
            {
                throw new System.ApplicationException(
                          "One by One Block regression file does not match compare at line " + lineNum);
            }

            ////////////////////////////////////////
            // now formatting tests all at once
            ////////////////////////////////////////
            TestFileWrapper regressionFile2 = new TestFileWrapper(fileName);

            EnvDTE.EditPoint tp1 = regressionFile2.CreateEditPoint(null);
            tp1.StartOfDocument();
            EnvDTE.EditPoint tp2 = regressionFile2.CreateEditPoint(null);
            tp2.EndOfDocument();
            CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2);
            regressionFile2.WriteToFile(@"..\..\Output\Regression.out2.cpp");
            lineNum = fileCompare(@"..\..\Output\Regression.out2.cpp", @"..\..\Compare\Regression.compare.cpp");
            if (lineNum != -1)
            {
                throw new System.ApplicationException(
                          "Whole block regression file does not match compare at line " + lineNum);
            }

            //now apply again and ensure consitancy
            tp1.StartOfDocument();
            tp2.EndOfDocument();
            CommentReflowerObj.WrapAllBlocksInSelection(pset, fileName, tp1, tp2);
            regressionFile2.WriteToFile(@"..\..\Output\Regression.out3.cpp");
            lineNum = fileCompare(@"..\..\Output\Regression.out3.cpp", @"..\..\Compare\Regression.compare.cpp");
            if (lineNum != -1)
            {
                throw new System.ApplicationException(
                          "Whole block second run regression file does not match compare at line " + lineNum);
            }


            Console.WriteLine("Block detection and formatting tests PASSED.");
        }
        /**
         * Determines if a block contains the given point, and is fo returns the
         * CommentBlock and MatchedBlockData for the match.
         */
        static public bool GetBlockContainingPoint(
            ParameterSet pset,
            string fileName,
            EnvDTE.TextPoint pt,
            out CommentBlock retblock,
            out MatchedBlockData bdata)
        {
            retblock           = null;
            bdata              = new MatchedBlockData();
            bdata.mEndLine     = 0;
            bdata.mStartLine   = 0;
            bdata.mIndentation = 0;

            EnvDTE.EditPoint ep     = pt.CreateEditPoint();
            EnvDTE.EditPoint enddoc = pt.CreateEditPoint();
            enddoc.EndOfDocument();
            string line = GetUntabbedLine(enddoc, ep.Line);

            foreach (CommentBlock block in pset.getBlocksForFileName(fileName))
            {
                if (block.lineHasBlockPattern(line, out bdata.mIndentation))
                {
                    int currentLineNumber = ep.Line;
                    // scan up for block start
                    bool foundStart = false;
                    for ( ; currentLineNumber >= 1; currentLineNumber--)
                    {
                        string currentLine  = GetUntabbedLine(enddoc, currentLineNumber);
                        string previousLine = GetUntabbedLine(enddoc, currentLineNumber - 1);
                        string nextLine     = GetUntabbedLine(enddoc, currentLineNumber + 1);
                        if (block.lineIsStartOfBlock(currentLine,
                                                     previousLine,
                                                     bdata.mIndentation,
                                                     out bdata.mMatchedBlockStart,
                                                     out bdata.mSpacesTrimmedOffBlockStart))
                        {
                            bdata.mStartLine = currentLineNumber;
                            foundStart       = true;
                            break;
                        }
                        else if (!block.lineIsBlockContinuation(currentLine, bdata.mIndentation) &&
                                 !block.lineIsEndOfBlock(currentLine, nextLine, bdata.mIndentation, out bdata.mMatchedBlockEnd))
                        {
                            break;
                        }
                    }
                    if (foundStart)
                    {
                        bool foundEnd = false;
                        for ( ; currentLineNumber <= enddoc.Line; currentLineNumber++)
                        {
                            string currentLine = GetUntabbedLine(enddoc, currentLineNumber);
                            string nextLine    = GetUntabbedLine(enddoc, currentLineNumber + 1);
                            if (block.lineIsEndOfBlock(currentLine, nextLine, bdata.mIndentation, out bdata.mMatchedBlockEnd))
                            {
                                bdata.mEndLine = currentLineNumber;
                                foundEnd       = true;
                                break;
                            }
                            else if ((currentLineNumber != bdata.mStartLine) &&
                                     (!block.lineIsBlockContinuation(currentLine, bdata.mIndentation)))
                            {
                                break;
                            }
                        }
                        if (foundEnd)
                        {
                            retblock = block;
                            return(true);
                        }
                        // else try next block
                    }
                    // else try next block
                }
            }
            return(false);
        }