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,
			)
		}
	}
}
