diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-01-28 22:11:05 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-01-28 22:17:22 +0100 |
commit | 982d9513e71b3d48e20cfa38454a0e1215a8d963 (patch) | |
tree | 47ece9af143bfbd52fa0e5174f9349b8c04c3211 /markup | |
parent | 6dedb4efc7b6a9fbe58a2daf0f77182638840fd9 (diff) | |
download | hugo-982d9513e71b3d48e20cfa38454a0e1215a8d963.tar.gz hugo-982d9513e71b3d48e20cfa38454a0e1215a8d963.zip |
testing: Simplify some integration tests
Diffstat (limited to 'markup')
-rw-r--r-- | markup/goldmark/codeblocks/codeblocks_integration_test.go | 46 | ||||
-rw-r--r-- | markup/goldmark/goldmark_integration_test.go | 89 | ||||
-rw-r--r-- | markup/goldmark/images/images_integration_test.go | 32 | ||||
-rw-r--r-- | markup/highlight/highlight_integration_test.go | 16 |
4 files changed, 23 insertions, 160 deletions
diff --git a/markup/goldmark/codeblocks/codeblocks_integration_test.go b/markup/goldmark/codeblocks/codeblocks_integration_test.go index 5597fc507..8ed691302 100644 --- a/markup/goldmark/codeblocks/codeblocks_integration_test.go +++ b/markup/goldmark/codeblocks/codeblocks_integration_test.go @@ -87,13 +87,7 @@ echo "l8"; §§§ ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` Goat SVG:<svg class='diagram' @@ -152,13 +146,7 @@ fmt.Println("Hello, World!"); ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "Inner: |<span class=\"line\"><span class=\"cl\"><span class=\"nx\">fmt</span><span class=\"p\">.</span><span class=\"nf\">Println</span><span class=\"p\">(</span><span class=\"s\">"Hello, World!"</span><span class=\"p\">);</span></span></span>|", @@ -188,13 +176,7 @@ title: "p1" ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` # Issue 9627: For the Position in code blocks we try to match the .Inner with the original source. This isn't always possible. @@ -223,13 +205,7 @@ echo "p1"; ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "|echo \"p1\";|") } @@ -257,12 +233,7 @@ Position: {{ .Position | safeHTML }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", filepath.FromSlash("Position: \"/content/p1.md:7:1\"")) } @@ -290,12 +261,7 @@ Hello, World! Attributes: {{ .Attributes }}|Type: {{ .Type }}| ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "<h2 id=\"issue-10118\">Issue 10118</h2>\nAttributes: map[foo:bar]|Type: |") } diff --git a/markup/goldmark/goldmark_integration_test.go b/markup/goldmark/goldmark_integration_test.go index c9c6ef338..ffeb763a7 100644 --- a/markup/goldmark/goldmark_integration_test.go +++ b/markup/goldmark/goldmark_integration_test.go @@ -50,13 +50,7 @@ foo {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` <h2 class="a" id="heading"> @@ -85,13 +79,7 @@ title: "p1" >{{ .Text | safeHTML }}</h{{ .Level }}> ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` <h2 data-foo="bar" id="heading">Heading</h2> @@ -111,13 +99,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` class="a < b" @@ -141,13 +123,7 @@ safeHTML: |{{- range $k, $v := .Attributes -}}{{ $k }}: {{ $v | safeHTML }}|{{ e {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` plain: |class: Smith & Wesson|id: heading-attribute-which-needs-escaping| @@ -178,13 +154,7 @@ title: "p1" ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "<h2 id=\"hello-testhttpsexamplecom\">\n Hello <a href=\"https://example.com\">Test</a>\n\n <a class=\"anchor\" href=\"#hello-testhttpsexamplecom\">#</a>\n</h2>", @@ -252,12 +222,7 @@ LINE8 ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"cl\">LINE1\n</span></span></code></pre></div>", @@ -397,7 +362,6 @@ FENCE runBenchmark(files, b) }) - } // Iisse #8959 @@ -406,7 +370,6 @@ func TestHookInfiniteRecursion(t *testing.T) { for _, renderFunc := range []string{"markdownify", ".Page.RenderString"} { t.Run(renderFunc, func(t *testing.T) { - files := ` -- config.toml -- -- layouts/_default/_markup/render-link.html -- @@ -436,11 +399,8 @@ [email protected] b.Assert(err, qt.IsNotNil) b.Assert(err.Error(), qt.Contains, "text is already rendered, repeating it may cause infinite recursion") - }) - } - } // Issue 9594 @@ -460,12 +420,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ` <img src="b.jpg" alt=""a""> @@ -476,7 +431,6 @@ func TestLinkifyProtocol(t *testing.T) { t.Parallel() runTest := func(protocol string, withHook bool) *hugolib.IntegrationTestBuilder { - files := ` -- config.toml -- [markup.goldmark] @@ -507,7 +461,6 @@ Link https procol: https://www.example.org TxtarString: files, }, ).Build() - } for _, withHook := range []bool{false, true} { @@ -564,12 +517,7 @@ a <!-- b --> c {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", // Issue 9650 @@ -621,12 +569,7 @@ sc3_begin|{{ .Inner }}|sc3_end {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", // Issue #7332 @@ -657,12 +600,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", "<p>:x:</p>") } @@ -680,12 +618,7 @@ title: "p1" {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContentExact("public/p1/index.html", "<p>:x:</p>") } diff --git a/markup/goldmark/images/images_integration_test.go b/markup/goldmark/images/images_integration_test.go index 8b0ba99c1..387287e7a 100644 --- a/markup/goldmark/images/images_integration_test.go +++ b/markup/goldmark/images/images_integration_test.go @@ -45,13 +45,7 @@ This is an inline image: ![Inline Image](/inline.jpg). Some more text. <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}|{{ .Ordinal }}" /> {{ end }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image|0\" />\n. Some more text.</p>", @@ -70,13 +64,7 @@ This is an inline image: ![Inline Image](/inline.jpg). Some more text. <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" /> {{ end }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image\" />\n. Some more text.</p>", @@ -86,26 +74,14 @@ This is an inline image: ![Inline Image](/inline.jpg). Some more text. t.Run("No Hook, no wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false") - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "<p>This is an inline image: <img src=\"/inline.jpg\" alt=\"Inline Image\">. Some more text.</p>\n<img src=\"/block.jpg\" alt=\"Block Image\" class=\"b\">") }) t.Run("No Hook, wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true") - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "<p class=\"b\"><img src=\"/block.jpg\" alt=\"Block Image\"></p>") }) diff --git a/markup/highlight/highlight_integration_test.go b/markup/highlight/highlight_integration_test.go index b53b585c0..d36bc820a 100644 --- a/markup/highlight/highlight_integration_test.go +++ b/markup/highlight/highlight_integration_test.go @@ -67,13 +67,7 @@ HighlightCodeBlock: Wrapped:{{ $result.Wrapped }}|Inner:{{ $result.Inner }} {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "Inline:<code class=\"code-inline language-emacs\"><span class=\"p\">(</span><span class=\"nf\">message</span> <span class=\"s\">"this highlight shortcode"</span><span class=\"p\">)</span></code>:End.", @@ -103,13 +97,7 @@ xəx := 0 {{ .Content }} ` - b := hugolib.NewIntegrationTestBuilder( - hugolib.IntegrationTestConfig{ - T: t, - TxtarString: files, - NeedsOsFS: false, - }, - ).Build() + b := hugolib.Test(t, files) b.AssertFileContent("public/index.html", ` <span class="nx">xəx</span> |