80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
package report
|
|
|
|
import (
|
|
"html/template"
|
|
"testing"
|
|
)
|
|
|
|
func TestOffsetHTags(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
html string
|
|
amount int
|
|
expected string
|
|
}{
|
|
{
|
|
name: "simple offset",
|
|
html: `<h1>Main</h1><h2>Sub</h2>`,
|
|
amount: 2,
|
|
expected: `<h3>Main</h3><h4>Sub</h4>`,
|
|
},
|
|
{
|
|
name: "offset beyond h6",
|
|
html: `<h5>Almost max</h5><h6>Max</h6>`,
|
|
amount: 3,
|
|
expected: `<h6>Almost max</h6><h6>Max</h6>`,
|
|
},
|
|
{
|
|
name: "negative offset",
|
|
html: `<h2>Heading</h2><h3>Subheading</h3>`,
|
|
amount: -2,
|
|
expected: `<h1>Heading</h1><h1>Subheading</h1>`,
|
|
},
|
|
{
|
|
name: "no h tags",
|
|
html: `<p>Paragraph</p>`,
|
|
amount: 2,
|
|
expected: `<p>Paragraph</p>`,
|
|
},
|
|
{
|
|
name: "mixed content",
|
|
html: `<h1>Title</h1><div><h2>Inner</h2></div>`,
|
|
amount: 1,
|
|
expected: `<h2>Title</h2><div><h3>Inner</h3></div>`,
|
|
},
|
|
{
|
|
name: "real one",
|
|
html: `<p>Hello</p>
|
|
|
|
<pre><code class="language-info">duration: 1h 43min
|
|
</code></pre>
|
|
|
|
<h1 id="adökfjaösldkjflaa">adökfjaösldkjflaa</h1>
|
|
|
|
<h2 id="asdfads">ASDFADS</h2>
|
|
|
|
<h3 id="adllglggl">adllglggl</h3>`,
|
|
amount: 3,
|
|
expected: `<p>Hello</p>
|
|
|
|
<pre><code class="language-info">duration: 1h 43min
|
|
</code></pre>
|
|
|
|
<h4 id="adökfjaösldkjflaa">adökfjaösldkjflaa</h4>
|
|
|
|
<h5 id="asdfads">ASDFADS</h5>
|
|
|
|
<h6 id="adllglggl">adllglggl</h6>`,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := offsetHTags(tt.amount, template.HTML(tt.html))
|
|
if string(got) != tt.expected {
|
|
t.Errorf("OffsetHTags() = %q, want %q", got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|