コード例 #1
0
ファイル: ElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestReplaceWith()
        {
            var n1 = new HText("Content");
            var n2 = new HElement("span", n1);
            var n3 = new HElement("span", "Another content");
            var n4 = new HElement("div", n2, n3);

            Assert.Same(n2, n2.ReplaceWith(new HElement("div", "Div Content"), new HElement("p", "P content")));
            Assert.Equal("<div><div>Div Content</div><p>P content</p><span>Another content</span></div>", n4.ToString());

            Assert.Same(n3, n3.ReplaceWith(null));
            Assert.Equal("<div><div>Div Content</div><p>P content</p></div>", n4.ToString());

            n2 = null;
            Assert.Null(n2.ReplaceWith(new HElement("div", "Div Content"), new HElement("p", "P content")));
            Assert.Equal("<div><div>Div Content</div><p>P content</p></div>", n4.ToString());
        }
コード例 #2
0
ファイル: ElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestReplaceWithElements()
        {
            var n1 = new HText("Content");
            var n2 = new HElement("span", n1);
            var n3 = new HElement("span", "Another content");
            var n4 = new HElement("div", n2, n3);

            IEnumerable <HElement> elements = new HElement[] { n2, n3 };

            Assert.Same(elements, elements.ReplaceWith(new HElement("div", "Div Content"), new HElement("p", "P content")));
            Assert.Equal("<div><div>Div Content</div><p>P content</p><div>Div Content</div><p>P content</p></div>", n4.ToString());

            n4.Descendants("div").ReplaceWith(null, null, null);
            Assert.Equal("<div><p>P content</p><p>P content</p></div>", n4.ToString());

            elements = null;
            Assert.Null(elements.ReplaceWith(new HElement("div", "Div Content"), new HElement("p", "P content")));
            Assert.Equal("<div><p>P content</p><p>P content</p></div>", n4.ToString());
        }
コード例 #3
0
ファイル: ElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestReplaceWithElementsByCallback()
        {
            var n1 = new HText("Content");
            var n2 = new HElement("span", n1);
            var n3 = new HElement("span", "Another content");
            var n4 = new HElement("div", n2, n3);

            var elements = new HElement[] { n2, n3 };

            Assert.Same(elements, elements.ReplaceWith((e, i) => {
                return(new HNode[] { new HElement("div", "Div Content " + i.ToString()), new HElement("span", "Span Content " + i.ToString()) });
            }));
            Assert.Equal("<div><div>Div Content 0</div><span>Span Content 0</span><div>Div Content 1</div><span>Span Content 1</span></div>", n4.ToString());

            n4.Descendants("div").ReplaceWith((e, i) => null);
            Assert.Equal("<div><span>Span Content 0</span><span>Span Content 1</span></div>", n4.ToString());

            elements = null;
            Assert.Null(elements.ReplaceWith((e, i) => {
                return(new HNode[] { new HElement("div", "Div Content " + i.ToString()), new HElement("span", "Span Content " + i.ToString()) });
            }));
            Assert.Equal("<div><span>Span Content 0</span><span>Span Content 1</span></div>", n4.ToString());
        }