public void MultiLayerWithNoInheritance()
        {
            string html = "<div style='font-family:arial;width:10px'><div><span>test</span></div></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.IsTrue(parser.Parse());
            parser.ParseStyles();

            Assert.IsNotNull(parser.Current);

            IHtmlNode node = parser.Current;

            node.AnalyzeNode("div", "<div><span>test</span></div>", html, null, false, true, 1, 1, 2);
            node.Attributes.CheckKeyValuePair(0, "style", "font-family:arial;width:10px");
            node.Styles.CheckKeyValuePair(0, "font-family", "arial");
            node.Styles.CheckKeyValuePair(1, "width", "10px");

            node.Children.ElementAt(0).AnalyzeNode("div", "<span>test</span>", "<div><span>test</span></div>", node, false, true, 1, 0, 0);
            Assert.AreEqual(1, node.Children.ElementAt(0).InheritedStyles.Count);
            node.Children.ElementAt(0).CheckInheritedStyle(0, "font-family", "arial");

            node.Children.ElementAt(0).Children.ElementAt(0).AnalyzeNode("span", "test", "<span>test</span>", node.Children.ElementAt(0), false, true, 1, 0, 0);
            Assert.AreEqual(1, node.Children.ElementAt(0).Children.ElementAt(0).InheritedStyles.Count);
            node.Children.ElementAt(0).Children.ElementAt(0).CheckInheritedStyle(0, "font-family", "arial");
        }
        public void BrWithNoSpaceAndSpan()
        {
            string html = @"<br/><span>1</span>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "br", "<br/>", "<br/>");
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(0, parser.Current.Children.Count());
            Assert.AreEqual(false, parser.Current.HasChildren);
            Assert.AreEqual(true, parser.Current.SelfClosing);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "span", "1", "<span>1</span>");
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(1, parser.Current.Children.Count());
            Assert.AreEqual(true, parser.Current.HasChildren);
            Assert.AreEqual(false, parser.Current.SelfClosing);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "#text", "1", "1");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.Count());
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).HasChildren);
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).SelfClosing);

            Assert.AreEqual(false, parser.Traverse());
            Assert.IsNull(parser.Current);
        }
        public void DivInsidePWithUpperCaseClose()
        {
            string html = "<div><p></P></DIV>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "div", "<p></P>", html);
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(true, parser.Current.HasChildren);
            Assert.AreEqual(1, parser.Current.Children.Count());
            Assert.AreEqual(false, parser.Current.SelfClosing);
            Assert.AreEqual(0, parser.Current.Attributes.Count);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "p", "", "<p></P>");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).HasChildren);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.Count());
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).SelfClosing);
            Assert.AreEqual(0, parser.Current.Attributes.Count);

            Assert.AreEqual(parser.Traverse(), false);
            Assert.IsNull(parser.Current);
        }
        public void TwoRowWithOneColumnEach()
        {
            string html = "<table><tr><td>test1</td></tr><tr><td>test2</td></tr></table>";

            HtmlTextParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());

            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "table", "<tr><td>test1</td></tr><tr><td>test2</td></tr>", html);
            Assert.IsNull(parser.Current.Parent);

            Assert.IsNotNull(parser.Current.Children);
            Assert.AreEqual(2, parser.Current.Children.Count());

            Assert.IsNotNull(parser.Current.Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "tr", "<td>test1</td>", "<tr><td>test1</td></tr>");
            Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(0).Parent);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children);
            Assert.AreEqual(1, parser.Current.Children.ElementAt(0).Children.Count());
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0), "td", "test1", "<td>test1</td>");
            Assert.AreEqual(parser.Current.Children.ElementAt(0), parser.Current.Children.ElementAt(0).Children.ElementAt(0).Parent);

            Assert.IsNotNull(parser.Current.Children.ElementAt(1));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(1), "tr", "<td>test2</td>", "<tr><td>test2</td></tr>");
            Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(1).Parent);

            Assert.IsNotNull(parser.Current.Children.ElementAt(1).Children);
            Assert.AreEqual(1, parser.Current.Children.ElementAt(1).Children.Count());
            Assert.IsNotNull(parser.Current.Children.ElementAt(1).Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(1).Children.ElementAt(0), "td", "test2", "<td>test2</td>");
            Assert.AreEqual(parser.Current.Children.ElementAt(1), parser.Current.Children.ElementAt(1).Children.ElementAt(0).Parent);
        }
        public void FontSizeLineHeightFontFamily()
        {
            string html = "<div style='font:25px/2pt arial'><div style='font-family:verdana'>test</div></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.IsTrue(parser.Parse());
            parser.ParseStyles();

            IHtmlNode node = parser.Current;
            Assert.IsNotNull(node);
            TestUtility.AnalyzeNode(node, "div", "<div style='font-family:verdana'>test</div>", html, null, false, true, 1, 1, 3);
            node.CheckStyle(0, "font-size", "25px");
            node.CheckStyle(1, "line-height", "2pt");
            node.CheckStyle(2, "font-family", "arial");

            IHtmlNode parent = node;
            node = node.Children.ElementAt(0);
            Assert.IsNotNull(node);
            TestUtility.AnalyzeNode(node, "div", "test", "<div style='font-family:verdana'>test</div>", parent, false, true, 1, 1, 1);
            node.CheckStyle(0, "font-family", "verdana");
            Assert.AreEqual(3, node.InheritedStyles.Count);
            node.CheckInheritedStyle(0, "font-size", "25px");
            node.CheckInheritedStyle(1, "line-height", "2pt");
            node.CheckInheritedStyle(2, "font-family", "verdana");
        }
		public void DivInsideTextA()
		{
			string html = "<div>test<a>ano</a></div>";

			HtmlParser parser = new HtmlTextParser(html);

			Assert.AreEqual(true, parser.Traverse());
			Assert.IsNotNull(parser.Current);
			TestUtility.AreEqual(parser.Current, "div", "test<a>ano</a>", "<div>test<a>ano</a></div>");
			Assert.IsNull(parser.Current.Previous);
			Assert.IsNull(parser.Current.Next);
			Assert.AreEqual(2, parser.Current.Children.Count());

			Assert.IsNotNull(parser.Current.Children.ElementAt(0));
			TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "#text", "test", "test");
			Assert.IsNull(parser.Current.Children.ElementAt(0).Previous);
			Assert.IsNotNull(parser.Current.Children.ElementAt(0).Next);
			Assert.AreEqual(parser.Current.Children.ElementAt(0).Next, parser.Current.Children.ElementAt(1));

			Assert.IsNotNull(parser.Current.Children.ElementAt(1));
			TestUtility.AreEqual(parser.Current.Children.ElementAt(1), "a", "ano", "<a>ano</a>");
			Assert.IsNull(parser.Current.Children.ElementAt(1).Next);
			Assert.IsNotNull(parser.Current.Children.ElementAt(1).Previous);
			Assert.AreEqual(parser.Current.Children.ElementAt(1).Previous, parser.Current.Children.ElementAt(0));
		}
        public void ClassAttribute()
        {
            string html = @"<style>
                                .cls
                                {
                                	color:red;
                                }
                                
                                [attr]
                                {
                                	color:blue;
                                }
                            </style>
                            <div class='cls' attr></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.IsTrue(parser.Parse());
            parser.ParseStyles();

            Assert.IsNotNull(parser.Current);

            IHtmlNode node = parser.Current;

            while (node.Tag != "div")
            {
                node = node.Next;
            }

            TestUtility.AnalyzeNode(node, "div", "", "<div class='cls' attr></div>", null, false, false, 0, 2, 1);
            TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(0), "class", "cls");
            TestUtility.CheckKeyValuePair(node.Attributes.ElementAt(1), "attr", "");
            TestUtility.CheckKeyValuePair(node.Styles.ElementAt(0), "color", "blue");
        }
        public void CommentWithMediaQuery()
        {
            string path = TestUtility.GetFolderPath("Html\\commentwithmediaquery.htm");
            string html = string.Empty;

            using (StreamReader sr = new StreamReader(path))
            {
                html = sr.ReadToEnd();
            }

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Parse());
            parser.ParseStyles();

            IHtmlNode node = parser.Current;

            while (node.Tag != "html")
                node = node.Next;

            node = node.Children.ElementAt(0);

            while (node.Tag != "body")
                node = node.Next;

            IHtmlNode body=node;

            node = node.Children.ElementAt(0);

            while (node.Tag != "p")
                node = node.Next;

            TestUtility.AnalyzeNode(node, "p", "test", "<p>test</p>", body, false, true, 1, 0, 0);
        }
        public void DivP()
        {
            string html = "<div><p></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "div", "<p>", "<div><p></div>");
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(1, parser.Current.Children.Count());
            Assert.AreEqual(true, parser.Current.HasChildren);
            Assert.AreEqual(false, parser.Current.SelfClosing);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "p", "", "<p>");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).HasChildren);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.Count());
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).SelfClosing);

            Assert.AreEqual(false, parser.Traverse());
            Assert.IsNull(parser.Current);
        }
        public void OpenOnlyDivAndValidDiv()
        {
            string html = "<div><div>test</div>";

            HtmlParser parser = new HtmlTextParser(html);

            if (parser.Traverse())
            {
                Assert.IsNotNull(parser.Current);

                TestUtility.AreEqual(parser.Current, "div", "<div>test</div>", "<div><div>test</div>");

                Assert.IsNull(parser.Current.Parent);

                Assert.IsNotNull(parser.Current.Children);

                Assert.AreEqual(parser.Current.Children.Count(), 1);

                Assert.IsNotNull(parser.Current.Children.ElementAt(0));

                IHtmlNode node = parser.Current.Children.ElementAt(0);

                Assert.IsNotNull(node.Parent);

                TestUtility.AreEqual(node, "div", "test", "<div>test</div>");
            }
            else
            {
                Assert.Fail("Fail to traverse");
            }

            Assert.AreEqual(parser.Traverse(), false);
        }
        public void DivInsidePAndB()
        {
            string html = "<div><p>one</p></div><b></b>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.IsTrue(parser.Parse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "div", "<p>one</p>", "<div><p>one</p></div>");
            Assert.IsTrue(parser.Current.HasChildren);
            Assert.AreEqual(1, parser.Current.Children.Count());
            Assert.IsNotNull(parser.Current.Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "p", "one", "<p>one</p>");
            Assert.IsNull(parser.Current.Children.ElementAt(0).Previous);
            Assert.IsNull(parser.Current.Children.ElementAt(0).Next);
            Assert.IsNull(parser.Current.Previous);
            Assert.IsNotNull(parser.Current.Next);
            TestUtility.AreEqual(parser.Current.Next, "b", "", "<b></b>");

            Assert.IsNull(parser.Current.Next.Next);
            Assert.IsNotNull(parser.Current.Next.Previous);
            Assert.AreEqual(parser.Current, parser.Current.Next.Previous);

            Assert.IsFalse(parser.Parse());
        }
Beispiel #12
0
        public void SimpleTable()
        {
            string html = "<table><tr><td>1</td></tr></table>";

            HtmlTextParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "table", "<tr><td>1</td></tr>", "<table><tr><td>1</td></tr></table>");
            Assert.IsNull(parser.Current.Parent);

            Assert.IsNotNull(parser.Current.Children);
            Assert.AreEqual(1, parser.Current.Children.Count());
            Assert.IsNotNull(parser.Current.Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "tr", "<td>1</td>", "<tr><td>1</td></tr>");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current.Children.ElementAt(0).Parent, parser.Current);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children);
            Assert.AreEqual(1, parser.Current.Children.ElementAt(0).Children.Count());
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0), "td", "1", "<td>1</td>");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Parent, parser.Current.Children.ElementAt(0));

            Assert.AreEqual(parser.Traverse(), false);
            Assert.IsNull(parser.Current);

        }
        public void DivAndInvalidDiv()
        {
            string html = "<div>test1</div><div>test2";

            HtmlParser parser = new HtmlTextParser(html);

            if (parser.Traverse())
            {
                Assert.IsNotNull(parser.Current);

                TestUtility.AreEqual(parser.Current, "div", "test1", "<div>test1</div>");
            }
            else
            {
                Assert.Fail("Fail to traverse");
            }

            if (parser.Traverse())
            {
                Assert.IsNotNull(parser.Current);

                TestUtility.AreEqual(parser.Current, "div", "test2", "<div>test2");
            }
            else
            {
                Assert.Fail("Fail to traverse");
            }

            Assert.AreEqual(parser.Traverse(), false);
        }
		public IHtmlNode FindBodyOrFirstElement()
		{
			MariGold.HtmlParser.HtmlParser parser = new HtmlTextParser(html);
            
            parser.UriSchema = uriSchema;
            parser.BaseURL = baseUrl;

			parser.Parse();
			parser.ParseStyles();
			
			IHtmlNode node = parser.Current;
			IHtmlNode body = null;
			
			while (node != null)
			{
				body = FindBody(node);
				
				if (body != null || node.Next == null)
				{
					break;
				}
				
				node = node.Next;
			}
			
			return body ?? parser.Current;
		}
        public void TextDivSpan()
        {
            string html = "test<div>this is a div</div><span>this is a span</span>";

            HtmlParser parser = new HtmlTextParser(html);

            if (parser.Traverse())
            {
                Assert.IsNotNull(parser.Current);

                if (parser.Current != null)
                {
                    Assert.AreEqual("#text", parser.Current.Tag);
                    Assert.AreEqual("test", parser.Current.Html);
                    Assert.AreEqual("test", parser.Current.InnerHtml);
                }
            }
            else
            {
                Assert.Fail("Fail to traverse");
            }

            if (parser.Traverse())
            {
                Assert.IsNotNull(parser.Current);

                if (parser.Current != null)
                {
                    Assert.AreEqual("div", parser.Current.Tag);
                    Assert.AreEqual("<div>this is a div</div>", parser.Current.Html);
                    Assert.AreEqual("this is a div", parser.Current.InnerHtml);
                }
            }
            else
            {
                Assert.Fail("Fail to traverse");
            }

            
            if (parser.Traverse())
            {
                Assert.IsNotNull(parser.Current);

                if (parser.Current != null)
                {
                    Assert.AreEqual("span", parser.Current.Tag);
                    Assert.AreEqual("<span>this is a span</span>", parser.Current.Html);
                    Assert.AreEqual("this is a span", parser.Current.InnerHtml);
                }
            }
            else
            {
                Assert.Fail("Fail to traverse");
            }

            Assert.AreEqual(parser.Traverse(), false);

        }
        public void DivPSpanTextInvalidSpanOpen()
        {
            string html = "<div><p><span>test<span></p></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "div", "<p><span>test<span></p>", html);
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(1, parser.Current.Children.Count());
            Assert.AreEqual(true, parser.Current.HasChildren);
            Assert.AreEqual(false, parser.Current.SelfClosing);
            Assert.AreEqual(0, parser.Current.Attributes.Count);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "p", "<span>test<span>", "<p><span>test<span></p>");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(0).Parent);
            Assert.AreEqual(1, parser.Current.Children.ElementAt(0).Children.Count());
            Assert.AreEqual(true, parser.Current.Children.ElementAt(0).HasChildren);
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).SelfClosing);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Attributes.Count);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0), "span", "test<span>", "<span>test<span>");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current.Children.ElementAt(0), parser.Current.Children.ElementAt(0).Children.ElementAt(0).Parent);
            Assert.AreEqual(2, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.Count());
            Assert.AreEqual(true, parser.Current.Children.ElementAt(0).Children.ElementAt(0).HasChildren);
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).Children.ElementAt(0).SelfClosing);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Attributes.Count);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0), "#text", "test", "test");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0).Parent);
            Assert.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0),
                parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0).Parent);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0).Children.Count());
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0).HasChildren);
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0).SelfClosing);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(0).Attributes.Count);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1));
            TestUtility.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1), "span", "", "<span>");
            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1).Parent);
            Assert.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0),
                parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1).Parent);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1).Children.Count());
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1).HasChildren);
            Assert.AreEqual(false, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1).SelfClosing);
            Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.ElementAt(1).Attributes.Count);

            Assert.AreEqual(false, parser.Traverse());
            Assert.IsNull(parser.Current);
        }
        public void InputWithEmptyQuote()
        {
            string html = "<input \"\" />";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Parse());
            Assert.IsNotNull(parser.Current);
            parser.Current.AnalyzeNode("input", html, html, null, true, false, 0, 0, 0);
        }
        public void InvalidQuote()
        {
            string html = "<div style=\"width:100%\" \">test</div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Parse());
            parser.ParseStyles();
            Assert.IsNotNull(parser.Current);
            parser.Current.AnalyzeNode("div", "test", html, null, false, true, 1, 1, 1);
        }
        public void InvalidInputAttribute()
        {
            string html = "<input =\"\" name=\"fld_quicksign\">";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Parse());
            Assert.IsNotNull(parser.Current);
            Assert.AreEqual(1, parser.Current.Attributes.Count);
            TestUtility.CheckKeyValuePair(parser.Current.Attributes.ElementAt(0), "name", "fld_quicksign");
        }
        public void EmptyHtml()
        {
            string html = " ";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.IsTrue(parser.Parse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "#text", html, html);
            Assert.IsNull(parser.Current.Previous);
            Assert.IsNull(parser.Current.Next);
        }
        public void SingleNode()
        {
            string html = "<div></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.IsTrue(parser.Parse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "div", "", html);
            Assert.IsNull(parser.Current.Previous);
            Assert.IsNull(parser.Current.Next);

            Assert.IsFalse(parser.Parse());
        }
		public void SingleNode()
		{
			string html = "<div>test</div>";

			HtmlParser parser = new HtmlTextParser(html);

			Assert.AreEqual(true, parser.Traverse());
			Assert.IsNotNull(parser.Current);
			TestUtility.AreEqual(parser.Current, "div", "test", html);
			Assert.IsNull(parser.Current.Previous);
			Assert.IsNull(parser.Current.Next);
			Assert.AreEqual(false, parser.Traverse());
			Assert.IsNull(parser.Current);
		}
        public void DivPDivSpan()
        {
            string html = "<div><p>t1</p></div><div><span>t2</span></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(parser.Traverse(), true);

            Assert.IsNotNull(parser.Current);

            TestUtility.AreEqual(parser.Current, "div", "<p>t1</p>", "<div><p>t1</p></div>");

            Assert.IsNull(parser.Current.Parent);

            Assert.IsNotNull(parser.Current.Children);

            Assert.AreEqual(1, parser.Current.Children.Count());

            Assert.IsNotNull(parser.Current.Children.ElementAt(0));

            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);

            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "p", "t1", "<p>t1</p>");



            Assert.AreEqual(parser.Traverse(), true);

            Assert.IsNotNull(parser.Current);

            TestUtility.AreEqual(parser.Current, "div", "<span>t2</span>", "<div><span>t2</span></div>");

            Assert.IsNull(parser.Current.Parent);

            Assert.IsNotNull(parser.Current.Children);

            Assert.AreEqual(parser.Current.Children.Count(), 1);

            Assert.IsNotNull(parser.Current.Children.ElementAt(0));

            Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);

            TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "span", "t2", "<span>t2</span>");

            Assert.AreEqual(parser.Traverse(), false);

            Assert.IsNull(parser.Current);
        }
        public void BrOnlyNoSpace()
        {
            string html = @"<br/>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "br", "<br/>", "<br/>");
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(0, parser.Current.Children.Count());
            Assert.AreEqual(false, parser.Current.HasChildren);
            Assert.AreEqual(true, parser.Current.SelfClosing);

            Assert.AreEqual(false, parser.Traverse());
            Assert.IsNull(parser.Current);
        }
        public void CommentWithDiv()
        {
            string html = "<!--<div>test</div>-->";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "#comment", html, html);
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(false, parser.Current.HasChildren);
            Assert.AreEqual(0, parser.Current.Children.Count());
            Assert.AreEqual(false, parser.Current.SelfClosing);
            Assert.AreEqual(0, parser.Current.Attributes.Count);
            Assert.AreEqual(false, parser.Traverse());
            Assert.IsNull(parser.Current);
        }
		public void MetaTag()
		{
			string html = "<html><head><meta charset=\"utf-8\" /></head><body></body></html>";
			
			HtmlParser parser = new HtmlTextParser(html);
			
			Assert.AreEqual(true, parser.Traverse());
			Assert.IsNotNull(parser.Current);
			TestUtility.AreEqual(parser.Current, "html", "<head><meta charset=\"utf-8\" /></head><body></body>", html);
			Assert.IsNull(parser.Current.Parent);
			Assert.AreEqual(true, parser.Current.HasChildren);
			Assert.AreEqual(2, parser.Current.Children.Count());
			Assert.AreEqual(false, parser.Current.SelfClosing);
			Assert.AreEqual(0, parser.Current.Attributes.Count);
			
			Assert.IsNotNull(parser.Current.Children.ElementAt(0));
			TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "head", "<meta charset=\"utf-8\" />", "<head><meta charset=\"utf-8\" /></head>");
			Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);
			Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(0).Parent);
			Assert.AreEqual(true, parser.Current.Children.ElementAt(0).HasChildren);
			Assert.AreEqual(1, parser.Current.Children.ElementAt(0).Children.Count());
			Assert.AreEqual(false, parser.Current.Children.ElementAt(0).SelfClosing);
			Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Attributes.Count);
			
			Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0));
			TestUtility.AreEqual(parser.Current.Children.ElementAt(0).Children.ElementAt(0), "meta", "<meta charset=\"utf-8\" />", "<meta charset=\"utf-8\" />");
			Assert.IsNotNull(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Parent);
			Assert.AreEqual(parser.Current.Children.ElementAt(0), parser.Current.Children.ElementAt(0).Children.ElementAt(0).Parent);
			Assert.AreEqual(false, parser.Current.Children.ElementAt(0).Children.ElementAt(0).HasChildren);
			Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Children.Count());
			Assert.AreEqual(true, parser.Current.Children.ElementAt(0).Children.ElementAt(0).SelfClosing);
			Assert.AreEqual(1, parser.Current.Children.ElementAt(0).Children.ElementAt(0).Attributes.Count);
			TestUtility.CheckKeyValuePair(parser.Current.Children.ElementAt(0).Children.ElementAt(0).Attributes.ElementAt(0), "charset", "utf-8");
			
			Assert.IsNotNull(parser.Current.Children.ElementAt(1));
			TestUtility.AreEqual(parser.Current.Children.ElementAt(1), "body", "", "<body></body>");
			Assert.IsNotNull(parser.Current.Children.ElementAt(1).Parent);
			Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(1).Parent);
			Assert.AreEqual(false, parser.Current.Children.ElementAt(1).HasChildren);
			Assert.AreEqual(0, parser.Current.Children.ElementAt(1).Children.Count());
			Assert.AreEqual(false, parser.Current.Children.ElementAt(1).SelfClosing);
			Assert.AreEqual(0, parser.Current.Children.ElementAt(1).Attributes.Count);
			
			Assert.AreEqual(false, parser.Traverse());
			Assert.IsNull(parser.Current);
		}
        public void DivWithUpperCaseOpen()
        {
            string html = "<DIV></div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Traverse());
            Assert.IsNotNull(parser.Current);
            TestUtility.AreEqual(parser.Current, "DIV", "", html);
            Assert.IsNull(parser.Current.Parent);
            Assert.AreEqual(false, parser.Current.HasChildren);
            Assert.AreEqual(0, parser.Current.Children.Count());
            Assert.AreEqual(false, parser.Current.SelfClosing);
            Assert.AreEqual(0, parser.Current.Attributes.Count);

            Assert.AreEqual(parser.Traverse(), false);
            Assert.IsNull(parser.Current);
        }
		public void TestTextOnly()
		{
			string html = "this is a test";

			HtmlParser parser = new HtmlTextParser(html);

			Assert.AreEqual(true, parser.Traverse());
			Assert.IsNotNull(parser.Current);
			TestUtility.AreEqual(parser.Current, "#text", "this is a test", "this is a test");
			Assert.AreEqual(true, parser.Current.IsText);
			Assert.AreEqual(false, parser.Current.SelfClosing);
			Assert.AreEqual(false, parser.Current.HasChildren);
			Assert.AreEqual(0, parser.Current.Children.Count());
			Assert.AreEqual(0, parser.Current.Attributes.Count);
			Assert.IsNull(parser.Current.Parent);

			Assert.AreEqual(parser.Traverse(), false);
		}
        public void CommentWithoutSpace()
        {
            string html = @"<style>/*styles*/.cls{color:red;}</style>
                            <div class='cls'>test</div>";

            HtmlParser parser = new HtmlTextParser(html);

            Assert.AreEqual(true, parser.Parse());
            parser.ParseStyles();

            IHtmlNode node = parser.Current;

            while (node.Tag != "div")
                node = node.Next;

            TestUtility.AnalyzeNode(node, "div", "test", "<div class='cls'>test</div>", null, false, true, 1, 1, 1);
            node.CheckStyle(0, "color", "red");
        }
		public void LinkSelfAndCloseTag()
		{
			string html = "<head><link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" /><link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\"></link></head>";
			
			HtmlParser parser = new HtmlTextParser(html);
			
			Assert.AreEqual(true, parser.Traverse());
			Assert.IsNotNull(parser.Current);
			TestUtility.AreEqual(parser.Current, "head", 
			                     "<link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" /><link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\"></link>", html);
			Assert.IsNull(parser.Current.Parent);
			Assert.AreEqual(true, parser.Current.HasChildren);
			Assert.AreEqual(2, parser.Current.Children.Count());
			Assert.AreEqual(false, parser.Current.SelfClosing);
			Assert.AreEqual(0, parser.Current.Attributes.Count);
			
			Assert.IsNotNull(parser.Current.Children.ElementAt(0));
			TestUtility.AreEqual(parser.Current.Children.ElementAt(0), "link", 
			 "<link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" />", "<link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" />");
			Assert.IsNotNull(parser.Current.Children.ElementAt(0).Parent);
			Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(0).Parent);
			Assert.AreEqual(false, parser.Current.Children.ElementAt(0).HasChildren);
			Assert.AreEqual(0, parser.Current.Children.ElementAt(0).Children.Count());
			Assert.AreEqual(true, parser.Current.Children.ElementAt(0).SelfClosing);
			Assert.AreEqual(3, parser.Current.Children.ElementAt(0).Attributes.Count);
			TestUtility.CheckKeyValuePair(parser.Current.Children.ElementAt(0).Attributes.ElementAt(0), "href", "/favicon.ico");
			TestUtility.CheckKeyValuePair(parser.Current.Children.ElementAt(0).Attributes.ElementAt(1), "rel", "shortcut icon");
			TestUtility.CheckKeyValuePair(parser.Current.Children.ElementAt(0).Attributes.ElementAt(2), "type", "image/x-icon");
			
			Assert.IsNotNull(parser.Current.Children.ElementAt(1));
			TestUtility.AreEqual(parser.Current.Children.ElementAt(1), "link", "<link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\">", "<link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\">");
			Assert.IsNotNull(parser.Current.Children.ElementAt(1).Parent);
			Assert.AreEqual(parser.Current, parser.Current.Children.ElementAt(1).Parent);
			Assert.AreEqual(false, parser.Current.Children.ElementAt(1).HasChildren);
			Assert.AreEqual(0, parser.Current.Children.ElementAt(1).Children.Count());
			Assert.AreEqual(true, parser.Current.Children.ElementAt(1).SelfClosing);
			Assert.AreEqual(3, parser.Current.Children.ElementAt(1).Attributes.Count);
			TestUtility.CheckKeyValuePair(parser.Current.Children.ElementAt(1).Attributes.ElementAt(0), "href", "/favicon.ico");
			TestUtility.CheckKeyValuePair(parser.Current.Children.ElementAt(1).Attributes.ElementAt(1), "rel", "shortcut icon");
			TestUtility.CheckKeyValuePair(parser.Current.Children.ElementAt(1).Attributes.ElementAt(2), "type", "image/x-icon");
			
			Assert.AreEqual(false, parser.Traverse());
			Assert.IsNull(parser.Current);
		}