MCPcopy
hub / github.com/PuerkitoBio/goquery / TestHtmlWithNonElementNode

Function TestHtmlWithNonElementNode

manipulation_test.go:694–739  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

692}
693
694func TestHtmlWithNonElementNode(t *testing.T) {
695 const data = `
696<html>
697 <head>
698 </head>
699 <body>
700 <p>
701 This is <span>some</span><b>text</b>.
702 </p>
703 </body>
704</html>
705`
706
707 cases := map[string]func(*Selection, string) *Selection{
708 "AfterHtml": (*Selection).AfterHtml,
709 "AppendHtml": (*Selection).AppendHtml,
710 "BeforeHtml": (*Selection).BeforeHtml,
711 "PrependHtml": (*Selection).PrependHtml,
712 "ReplaceWithHtml": (*Selection).ReplaceWithHtml,
713 "SetHtml": (*Selection).SetHtml,
714 }
715 for nm, fn := range cases {
716 // this test is only to make sure that the HTML parsing/manipulation
717 // methods do not raise panics when executed over Selections that contain
718 // non-Element nodes.
719 t.Run(nm, func(t *testing.T) {
720 doc := loadString(t, data)
721 sel := doc.Find("p").Contents()
722 func() {
723 defer func() {
724 if err := recover(); err != nil {
725 t.Fatal(err)
726 }
727 }()
728 fn(sel, "<div></div>")
729 }()
730
731 // print the resulting document in verbose mode
732 h, err := OuterHtml(doc.Selection)
733 if err != nil {
734 log.Fatal(err)
735 }
736 t.Log(h)
737 })
738 }
739}

Callers

nothing calls this directly

Calls 4

loadStringFunction · 0.85
OuterHtmlFunction · 0.85
ContentsMethod · 0.80
FindMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…