(t *testing.T)
| 692 | } |
| 693 | |
| 694 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…