public void ToString_ReturnsExpected(HtmlComment comment, string expected)
 {
     Assert.Equal(expected, comment.ToString());
     Assert.Equal(expected, comment.Serialize());
     Assert.Equal(expected, comment.Serialize(HtmlSerializeOptions.None));
     Assert.Equal(expected, comment.Serialize(HtmlSerializeOptions.NoFormatting));
 }
        public void Add_HtmlObject(bool isVoid)
        {
            HtmlElement parent = new HtmlElement("parent", isVoid);

            // Atribute
            HtmlAttribute attribute = new HtmlAttribute("attribute");
            parent.Add(attribute);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());

            if (!isVoid)
            {
                // Element
                HtmlElement element = new HtmlElement("element");
                parent.Add(element);
                Assert.Equal(parent, element.Parent);
                Assert.Equal(new HtmlElement[] { element }, parent.Elements());

                // Nodes
                HtmlComment comment = new HtmlComment("comment");
                parent.Add(comment);
                Assert.Equal(parent, comment.Parent);
                Assert.Equal(new HtmlObject[] { element, comment }, parent.Nodes());
            }
        }
        public void AddFirst_NonEmptyHtmlObject(bool isVoid)
        {
            HtmlElement   parent     = new HtmlElement("parent", isVoid);
            HtmlAttribute attribute1 = new HtmlAttribute("attribute1");

            parent.Add(attribute1);

            // Attributes
            HtmlAttribute attribute2 = new HtmlAttribute("attribute2");

            parent.AddFirst(attribute2);
            Assert.Equal(parent, attribute2.Parent);
            Assert.Equal(new HtmlAttribute[] { attribute2, attribute1 }, parent.Attributes());

            if (!isVoid)
            {
                HtmlElement element1 = new HtmlElement("element1");
                parent.Add(element1);

                // Elements
                HtmlElement element2 = new HtmlElement("element2");
                parent.AddFirst(element2);
                Assert.Equal(parent, element2.Parent);
                Assert.Equal(new HtmlElement[] { element2, element1 }, parent.Elements());

                // Nodes
                HtmlComment comment = new HtmlComment("comment");
                parent.AddFirst(comment);
                Assert.Equal(parent, comment.Parent);
                Assert.Equal(new HtmlObject[] { comment, element2, element1 }, parent.Nodes());
            }
        }
        public void AddFirst_EmptyHtmlObject(bool isVoid)
        {
            HtmlElement parent = new HtmlElement("parent", isVoid);

            // Attributes
            HtmlAttribute attribute = new HtmlAttribute("attribute1");

            parent.AddFirst(attribute);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());

            if (!isVoid)
            {
                // Elements
                HtmlElement element = new HtmlElement("element1");
                parent.AddFirst(element);
                Assert.Equal(parent, element.Parent);
                Assert.Equal(new HtmlElement[] { element }, parent.Elements());

                // Nodes
                HtmlComment comment = new HtmlComment("comment");
                parent.AddFirst(comment);
                Assert.Equal(parent, comment.Parent);
                Assert.Equal(new HtmlObject[] { comment, element }, parent.Nodes());
            }
        }
Beispiel #5
0
        public void LastNode_Comment_ReturnsExpected()
        {
            HtmlComment comment = new HtmlComment("comment");
            HtmlElement parent  = new HtmlElement("parent", new HtmlElement("element"), comment);

            Assert.Equal(comment, parent.LastNode);
        }
Beispiel #6
0
 public void ToString_ReturnsExpected(HtmlComment comment, string expected)
 {
     Assert.Equal(expected, comment.ToString());
     Assert.Equal(expected, comment.Serialize());
     Assert.Equal(expected, comment.Serialize(HtmlSerializeOptions.None));
     Assert.Equal(expected, comment.Serialize(HtmlSerializeOptions.NoFormatting));
 }
Beispiel #7
0
        public void ToXComment_Test(HtmlComment comment, XComment expected)
        {
            // Act
            var actual = comment.ToXComment();

            // Assert
            Assert.That(actual, Is.EqualTo(expected).Using <XNode>(XNode.EqualityComparer));
        }
Beispiel #8
0
        public void ToXComment_Test(HtmlComment htmlComment, XComment expectedXComment)
        {
            // Act
            var xComment = htmlComment.ToXComment();

            // Assert
            Assert.That(xComment, Is.EqualTo(expectedXComment).Using <XNode>(XNode.EqualityComparer));
        }
 public void Equals_ReturnsExpected(HtmlComment comment, object other, bool expected)
 {
     if (other is HtmlComment || other == null)
     {
         Assert.Equal(expected, comment.GetHashCode().Equals(other?.GetHashCode()));
         Assert.Equal(expected, comment.Equals((HtmlComment)other));
     }
     Assert.Equal(expected, comment.Equals(other));
 }
        public void PreviousNodes_IgnoresAttributes()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlComment comment  = new HtmlComment("comment");
            HtmlElement element2 = new HtmlElement("element2");
            HtmlElement parent   = new HtmlElement("parent", element1, comment, new HtmlAttribute("attribute"), element2);

            Assert.Equal(new HtmlNode[] { comment, element1 }, element2.PreviousNodes());
        }
        public void NextNodes_IgnoresAttributes()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlComment comment  = new HtmlComment("comment");
            HtmlElement element2 = new HtmlElement("element2");
            HtmlElement parent   = new HtmlElement("parent", element1, comment, new HtmlAttribute("attribute"), element2);

            Assert.Equal(new HtmlElement[] { element2 }, comment.NextNodes());
        }
Beispiel #12
0
 public void Equals_ReturnsExpected(HtmlComment comment, object other, bool expected)
 {
     if (other is HtmlComment || other == null)
     {
         Assert.Equal(expected, comment.GetHashCode().Equals(other?.GetHashCode()));
         Assert.Equal(expected, comment.Equals((HtmlComment)other));
     }
     Assert.Equal(expected, comment.Equals(other));
 }
Beispiel #13
0
            protected override void Write(HtmlComment node)
            {
                // Keep comment
                Write("<!--");
                var comment = node.Slice.ToString();

                Write(comment);
                Write("-->");
            }
        public void PreviousNode_Get_ReturnsExpected()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlComment comment  = new HtmlComment("comment");
            HtmlElement element2 = new HtmlElement("element2");
            HtmlElement parent   = new HtmlElement("parent", element1, comment, element2);

            Assert.Null(element1.PreviousNode);
            Assert.Equal(element1, comment.PreviousNode);
            Assert.Equal(comment, element2.PreviousNode);
        }
        public void PreviousNodes_ReturnsExpected()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlComment comment  = new HtmlComment("comment");
            HtmlElement element2 = new HtmlElement("element2");
            HtmlElement parent   = new HtmlElement("parent", element1, comment, element2);

            Assert.Empty(element1.PreviousNodes());
            Assert.Equal(new HtmlNode[] { element1 }, comment.PreviousNodes());
            Assert.Equal(new HtmlNode[] { comment, element1 }, element2.PreviousNodes());
        }
Beispiel #16
0
        public void TryGetElement_IgnoresNodes()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlComment comment  = new HtmlComment("comment");
            HtmlElement element2 = new HtmlElement("element2");
            HtmlElement parent   = new HtmlElement("parent", element1, comment, element2);

            HtmlElement element;

            Assert.False(parent.TryGetElement("comment", out element));
            Assert.Null(element);
        }
        public void Add_ParamsHtmlObject_NonVoidElement()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement element = new HtmlElement("element");
            HtmlAttribute attribute = new HtmlAttribute("attribute");
            HtmlComment comment = new HtmlComment("comment");
            parent.Add(new HtmlObject[] { element, attribute, comment });

            Assert.Equal(parent, element.Parent);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlObject[] { element }, parent.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());
            Assert.Equal(new HtmlObject[] { element, comment }, parent.Nodes());
        }
        public void RenderWorksAsExpected()
        {
            // --- Arrange
            const string TEXT     = "It's a comment";
            const string EXPECTED = "<!-- It's a comment -->";
            var          comment  = new HtmlComment(TEXT);

            // --- Act
            var rendered = comment.Render();

            // --- Assert
            rendered.ShouldHaveCountOf(1);
            rendered[0].ToString().ShouldEqual(EXPECTED);
        }
        public void Add_ParamsHtmlObject_NonVoidElement()
        {
            HtmlElement   parent    = new HtmlElement("parent");
            HtmlElement   element   = new HtmlElement("element");
            HtmlAttribute attribute = new HtmlAttribute("attribute");
            HtmlComment   comment   = new HtmlComment("comment");

            parent.Add(new HtmlObject[] { element, attribute, comment });

            Assert.Equal(parent, element.Parent);
            Assert.Equal(parent, attribute.Parent);
            Assert.Equal(new HtmlObject[] { element }, parent.Elements());
            Assert.Equal(new HtmlAttribute[] { attribute }, parent.Attributes());
            Assert.Equal(new HtmlObject[] { element, comment }, parent.Nodes());
        }
        public void AddAfterSelf_HtmlNode()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement child1 = new HtmlElement("child1");

            parent.Add(child1);

            // Element
            HtmlElement child2 = new HtmlElement("child2");

            child1.AddAfterSelf(child2);
            Assert.Equal(parent, child2.Parent);
            Assert.Equal(new HtmlElement[] { child1, child2 }, parent.Elements());

            // Comment
            HtmlComment comment = new HtmlComment("comment");

            child1.AddAfterSelf(comment);
            Assert.Equal(parent, comment.Parent);
            Assert.Equal(new HtmlObject[] { child1, comment, child2 }, parent.Nodes());
        }
Beispiel #21
0
        public void HtmlComment_ParseTest()
        {
            string        text1  = "<!-- foo#bar -->";
            ITextProvider tp     = new StringTextProvider(text1);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);

            // Parse "<!--"
            {
                HtmlComment hc = new HtmlComment();
                Assert.IsTrue(hc.Parse(new ItemFactory(tp, null), tp, tokens));
                Assert.AreEqual(1, hc.Children.Count);
                Assert.AreEqual(CssTokenType.OpenHtmlComment, ((TokenItem)hc.Children[0]).TokenType);
            }

            // Parse "foo#bar"
            {
                Assert.AreEqual(CssTokenType.Identifier, tokens.Advance(1).TokenType);
                Assert.AreEqual(CssTokenType.HashName, tokens.Advance(1).TokenType);
            }

            // Parse "-->"
            {
                HtmlComment hc = new HtmlComment();
                Assert.IsTrue(hc.Parse(new ItemFactory(tp, null), tp, tokens));
                Assert.AreEqual(1, hc.Children.Count);
                Assert.AreEqual(CssTokenType.CloseHtmlComment, ((TokenItem)hc.Children[0]).TokenType);
            }

            string     text2  = "<!-- @namespace foo \"www.foo.com\" -->";
            CssParser  parser = new CssParser();
            StyleSheet sheet  = parser.Parse(text2, true);

            Assert.IsTrue(sheet.ComplexItemFromRange(14, 0) is NamespaceDirective);
            Assert.IsTrue(sheet.ComplexItemFromRange(2, 0) is HtmlComment);
            Assert.IsTrue(sheet.ComplexItemFromRange(35, 0) is HtmlComment);
        }
 public void Ctor_String(string comment)
 {
     HtmlComment htmlComment = new HtmlComment(comment);
     Assert.Equal(comment, htmlComment.Comment);
 }
        public void TryGetElement_IgnoresNodes()
        {
            HtmlElement element1 = new HtmlElement("element1");
            HtmlComment comment = new HtmlComment("comment");
            HtmlElement element2 = new HtmlElement("element2");
            HtmlElement parent = new HtmlElement("parent", element1, comment, element2);

            HtmlElement element;
            Assert.False(parent.TryGetElement("comment", out element));
            Assert.Null(element);
        }
 public void ObjectType_Get_ReturnsComment()
 {
     HtmlComment comment = new HtmlComment("comment");
     Assert.Equal(HtmlObjectType.Comment, comment.ObjectType);
 }
Beispiel #25
0
        public void ObjectType_Get_ReturnsComment()
        {
            HtmlComment comment = new HtmlComment("comment");

            Assert.Equal(HtmlObjectType.Comment, comment.ObjectType);
        }
Beispiel #26
0
 private HtmlStringBuilder Append(HtmlComment comment) =>
 Append("<!-- ").Append(comment.Value).Append(" -->");
 public void LastNode_Comment_ReturnsExpected()
 {
     HtmlComment comment = new HtmlComment("comment");
     HtmlElement parent = new HtmlElement("parent", new HtmlElement("element"), comment);
     Assert.Equal(comment, parent.LastNode);
 }
        public void AddFirst_NonEmptyHtmlObject(bool isVoid)
        {
            HtmlElement parent = new HtmlElement("parent", isVoid);
            HtmlAttribute attribute1 = new HtmlAttribute("attribute1");
            parent.Add(attribute1);

            // Attributes
            HtmlAttribute attribute2 = new HtmlAttribute("attribute2");
            parent.AddFirst(attribute2);
            Assert.Equal(parent, attribute2.Parent);
            Assert.Equal(new HtmlAttribute[] { attribute2, attribute1 }, parent.Attributes());

            if (!isVoid)
            {
                HtmlElement element1 = new HtmlElement("element1");
                parent.Add(element1);

                // Elements
                HtmlElement element2 = new HtmlElement("element2");
                parent.AddFirst(element2);
                Assert.Equal(parent, element2.Parent);
                Assert.Equal(new HtmlElement[] { element2, element1 }, parent.Elements());

                // Nodes
                HtmlComment comment = new HtmlComment("comment");
                parent.AddFirst(comment);
                Assert.Equal(parent, comment.Parent);
                Assert.Equal(new HtmlObject[] { comment, element2, element1 }, parent.Nodes());
            }
        }
Beispiel #29
0
        public void Ctor_String(string comment)
        {
            HtmlComment htmlComment = new HtmlComment(comment);

            Assert.Equal(comment, htmlComment.Comment);
        }