A web blog and personal homepage engine written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
1.0 KiB

package mogrify_test
import (
"testing"
"git.kirsle.net/apps/gophertype/pkg/mogrify"
)
func TestLazyLoadImages(t *testing.T) {
var tests = []struct {
In string
Expect string
}{
{
In: `<img src="logo.jpg">`,
Expect: `<img src="logo.jpg" loading="lazy">`,
},
{
In: `<img src="https://example.com/image.png" loading="eager">`,
Expect: `<img src="https://example.com/image.png" loading="eager">`,
},
{
In: `Hello world`,
Expect: `Hello world`,
},
{
In: `<img src="a"><img src="b"><img src="a">`,
Expect: `<img src="a" loading="lazy"><img src="b" loading="lazy"><img src="a" loading="lazy">`,
},
{
In: `<img src="a"><img src="b" loading="eager"><img src="a">`,
Expect: `<img src="a" loading="lazy"><img src="b" loading="eager"><img src="a" loading="lazy">`,
},
}
for _, test := range tests {
actual := mogrify.LazyLoadImages(test.In)
if actual != test.Expect {
t.Errorf("for input {%s} I expected {%s} but got: {%s}",
test.In, test.Expect, actual,
)
}
}
}