示例#1
0
        public void TestGetColrCount()
        {
            IHtmlTable ret = HtmlTableParser.Parse(@"<TABLE><TR><TH>H1</TH><TH>H2</TH></TR><TR><TD>C11</TD><TD>C12</TD></TR></TABLE>");

            Assert.IsNotNull(ret, "ret must be not null");

            Assert.AreEqual(ret.GetColCount(-1), 0, "Negative index for Row should return 0");
            Assert.AreEqual(ret.GetColCount(2), 0, "Too large index for Row should return 0");

            Assert.AreEqual(ret.GetColCount(0), 2, "Not the expected value for GetColCount");
            Assert.AreEqual(ret.GetColCount(1), 2, "Not the expected value for GetColCount");
        }
示例#2
0
        public void TestRangeGet()
        {
            IHtmlTable ret = HtmlTableParser.Parse(@"<TABLE><TR><TH>H1</TH><TH>H2</TH></TR><TR><TD>C11</TD><TD>C12</TD></TR></TABLE>");

            Assert.IsNotNull(ret, "ret must be not null");

            Assert.IsNull(ret[-1, 0], "Negative index for Row should return null");
            Assert.IsNull(ret[0, -1], "Negative index for Col should return null");
            Assert.IsNull(ret[2, 0], "Too large index for Row should return null");
            Assert.IsNull(ret[0, 2], "Too large index for Col should return null");

            Assert.IsNotNull(ret[0, 0], "In range index for Row and Col should not return null");
            Assert.IsNotNull(ret[1, 0], "In range index for Row and Col should not return null");
            Assert.IsNotNull(ret[0, 1], "In range index for Row and Col should not return null");
            Assert.IsNotNull(ret[1, 1], "In range index for Row and Col should not return null");
        }
示例#3
0
        public void TestCellsInfos()
        {
            //Test when table is not the first caracters
            //Row 1 : test header
            //Row 2 : test cell
            //Row 3 : test colspan
            //Row 4-5: test rowspan and next row completion
            //Row 6-7: test rowspan and next row missing data
            //Row 8-9: test rowspan and colspan averlap
            //Row 10-13: test multi rowspan with overlap

            IHtmlTable ret = HtmlTableParser.Parse(@"azertyui 
<Table>
<TR><TH>H1</TH><TH>H2</TH></TR>
<TR><TD>C11</TD><TD>C12</TD></TR>

<TR><TD colspan=2>C21</TD><TD>C23</TD></TR>

<TR><TD>C31</TD><TD rowspan=2>C32</TD></TR>
<TR><TD>C41</TD><TD>C43</TD></TR>

<TR><TD>C51</TD><TD rowspan=2>C52</TD></TR>
<TR></TR>

<TR><TD>C71</TD><TD rowspan=2>C72</TD></TR>
<TR><TD colspan=2>C81</TD><TD>C83</TD></TR>

<TR><TD rowspan=3 colspan=3>C91</TD></TR>
<TR><TD rowspan=3 colspan=3>CA4</TD></TR>
</Table>");

            Assert.IsNotNull(ret, "ret must be not null");

            Assert.AreEqual(ret.RowCount, 13, "RowCount must be 13");

            string[,] expectedValue =
            {
                { "H1",  "H2",  null,  null,  null,  null,  null },
                { "C11", "C12", null,  null,  null,  null,  null },
                { "C21", "C21", "C23", null,  null,  null,  null },
                { "C31", "C32", null,  null,  null,  null,  null },
                { "C41", "C32", "C43", null,  null,  null,  null },
                { "C51", "C52", null,  null,  null,  null,  null },
                { null,  "C52", null,  null,  null,  null,  null },
                { "C71", "C72", null,  null,  null,  null,  null },
                { "C81", "C81", "C83", null,  null,  null,  null },
                { "C91", "C91", "C91", null,  null,  null,  null },
                { "C91", "C91", "C91", "CA4", "CA4", "CA4", null },
                { "C91", "C91", "C91", "CA4", "CA4", "CA4", null },
                { null,  null,  null,  "CA4", "CA4", "CA4", null }
            };


            for (int i = 0; i < expectedValue.GetLength(0); i++)
            {
                for (int j = 0; j < expectedValue.GetLength(1); j++)
                {
                    IHtmlCell cell  = ret[i, j];
                    string    value = cell?.InnerText;
                    Assert.AreEqual(expectedValue[i, j], value, "Value different for ({0},{1}) : {2} vs {3}", i, j, value, expectedValue[i, j]);
                    Assert.AreEqual(cell?.ToString(), value);
                }
            }
        }
示例#4
0
        public void TestNotTableTag()
        {
            IHtmlTable ret = HtmlTableParser.Parse("azertyuiop");

            Assert.IsNull(ret, "ret must be empty");
        }