예제 #1
0
        public void TestReset()
        {
            MockTermTable table = new MockTermTable("file1");
            MockTerm      term  = new MockTerm("foo", 1, "fooClass", "fooComment", "fooRecommended", table);

            table.AddSearchTerm(term);

            CodeSweep.Scanner.MatchFinder_Accessor accessor = new CodeSweep.Scanner.MatchFinder_Accessor(new ITermTable[] { table });

            IList <IScanHit> hits1 = InternalScanText("foo bar ", accessor);

            Assert.AreEqual(1, hits1.Count, "First search returned wrong number of hits.");
            Assert.AreEqual(0, hits1[0].Column, "Column property of first hit is incorrect.");

            IList <IScanHit> hits2 = InternalScanText("foo bar", accessor);

            // This is what happens if you DON'T call Reset...
            Assert.AreEqual(1, hits2.Count, "Second search returned wrong number of hits.");
            Assert.AreEqual(8, hits2[0].Column, "Column property of second hit is incorrect.");

            accessor.Reset();

            IList <IScanHit> hits3 = InternalScanText("foo bar", accessor);

            Assert.AreEqual(1, hits3.Count, "Third search returned wrong number of hits.");
            Assert.AreEqual(0, hits3[0].Column, "Column property of third hit is incorrect.");
        }
예제 #2
0
        private static IList <IScanHit> InternalScanText(string fileContent, CodeSweep.Scanner.MatchFinder_Accessor accessor)
        {
            List <IScanHit> hits = new List <IScanHit>();

            MatchFoundCallback_Shadow shadow = delegate(ISearchTerm term, int line, int column, string lineText, string warning)
            {
                hits.Add(new MockScanHit("", line, column, lineText, term, warning));
            };

            CodeSweep.Scanner.MatchFoundCallback_Accessor callback = new MatchFoundCallback_Accessor(shadow.Target, shadow.Method.MethodHandle.GetFunctionPointer());

            foreach (char c in fileContent)
            {
                accessor.AnalyzeNextCharacter(c, callback);
            }

            accessor.Finish(callback);

            return(hits);
        }
예제 #3
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        private IList <IScanHit> InternalScanText(string fileContent, IList <ITermTable> list)
        {
            CodeSweep.Scanner.MatchFinder_Accessor accessor = new CodeSweep.Scanner.MatchFinder_Accessor(list);

            return(InternalScanText(fileContent, accessor));
        }