package web_test import ( "context" "strings" "testing" "github.com/qor5/web" h "github.com/theplant/htmlgo" "github.com/theplant/testingutils" ) var cases = []struct { name string operation func(b *web.PageInjector) expected string }{ { name: "title", operation: func(b *web.PageInjector) { b.Title("Hello") }, expected: `Hello `, }, { name: "title and charset", operation: func(b *web.PageInjector) { b.Title("Hello") b.Meta(web.MetaKey("charset"), "charset", "shiftjis") }, expected: `Hello `, }, { name: "title and charset double", operation: func(b *web.PageInjector) { b.Title("Hello") b.Meta(web.MetaKey("charset"), "charset", "shiftjis") b.Meta(web.MetaKey("charset"), "charset", "utf8") b.MetaNameContent("keywords", "Hello") }, expected: `Hello `, }, { name: "script tag", operation: func(b *web.PageInjector) { b.HeadHTML(` `) }, expected: ` `, }, } func TestDefaultPageInjector(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { var b web.PageInjector c.operation(&b) web.SetDefault(&b, "") diff := testingutils.PrettyJsonDiff( strings.TrimSpace(c.expected), strings.TrimSpace(h.MustString(b.GetHeadHTMLComponent(), context.TODO()))) if len(diff) > 0 { t.Error(diff) } }) } }