コード例 #1
0
        public void MatchCount()
        {
            HtmlProfiler profiler;
            int          count;

            // Normal test
            HtmlSectionTemplate template = new HtmlSectionTemplate();

            template.Tags     = "T";
            template.Template = "<table><tr><td>Test</td><td>1</td><td>2</td></tr></table>";
            profiler          = new HtmlProfiler(template);

            count =
                profiler.MatchCount(
                    "<table><tr><td>Test</td><td>1</td><td>2</td></tr></table><div><div><div><table><tr><td>Test</td><td>1</td><td>2</td></tr></table><span><span><span><table><tr><td>Test</td><td>1</td><td>2</td><td>3</td></tr></table>");

            Assert.IsTrue(count == 2);

            // Regex test
            template.Template = "<table><tr><td>Test</td><td>1</td><td>2</td><Z(><td>3</td></Z)?></tr></table>";
            profiler          = new HtmlProfiler(template);

            count =
                profiler.MatchCount(
                    "<table><tr><td>Test</td><td>1</td><td>2</td></tr></table><div><div><div><table><tr><td>Test</td><td>1</td><td>2</td></tr></table><span><span><span><table><tr><td>Test</td><td>1</td><td>2</td><td>3</td></tr></table>");

            Assert.IsTrue(count == 3);
        }
コード例 #2
0
        public void ParseSection2()
        {
            // Start and End for tag
            HtmlSectionTemplate template = new HtmlSectionTemplate();

            template.Tags     = "T";
            template.Template =
                "<table><tr><td>Title:<#TITLE>(</td><td><#START></td><td><#DESCRIPTION></td><Z(><td><#GENRE></td></Z)?></tr></table>";

            HtmlSectionParser elements = new HtmlSectionParser(template);

            ParserData  data   = new ParserData();
            IParserData idata  = (IParserData)data;
            string      source = "<table><tr><td>Test</td><td>123</td><td>blah blah</td></tr></table>";

            elements.ParseSection(source, ref idata);

            Assert.IsTrue(data.GetElement("#TITLE") == "Test");
            Assert.IsTrue(data.GetElement("#START") == "123");
            Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");

            data   = new ParserData();
            idata  = (IParserData)data;
            source = "<table><tr><td>Title:Test(1:2)</td><td>123</td><td>blah blah</td></tr></table>";
            elements.ParseSection(source, ref idata);

            Assert.IsTrue(data.GetElement("#TITLE") == "Test");
            Assert.IsTrue(data.GetElement("#START") == "123");
            Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");
        }
コード例 #3
0
        public void ParseSection3()
        {
            // Multiple tags
            HtmlSectionTemplate template = new HtmlSectionTemplate();

            template.Tags     = "T";
            template.Template =
                "<table><tr><td><#TITLE>-<#SUBTITLE></td><td><#START></td><td><#DESCRIPTION></td><Z(><td><#GENRE></td></Z)?></tr></table>";

            HtmlSectionParser elements = new HtmlSectionParser(template);
            ParserData        data     = new ParserData();
            IParserData       idata    = (IParserData)data;
            string            source   = "<table><tr><td>Test-Sub</td><td>123</td><td>blah blah</td></tr></table>";

            elements.ParseSection(source, ref idata);

            Assert.IsTrue(data.GetElement("#TITLE") == "Test");
            Assert.IsTrue(data.GetElement("#SUBTITLE") == "Sub");
            Assert.IsTrue(data.GetElement("#START") == "123");
            Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");
        }