package host import ( "strings" "testing" ) func TestInjectReloadScript_BeforeBody(t *testing.T) { html := []byte(` Test

Hello

`) result := InjectReloadScript(html) // Should contain the script if !strings.Contains(string(result), "livereload") { t.Error("Expected result to contain livereload script") } // Script should be before bodyIndex := strings.Index(string(result), "") scriptIndex := strings.Index(string(result), "") { t.Error("Expected script to be appended at the end") } } func TestInjectReloadScript_ContainsReconnect(t *testing.T) { html := []byte(``) result := InjectReloadScript(html) // Should contain reconnection logic if !strings.Contains(string(result), "reconnect") { t.Error("Expected script to contain reconnection logic") } } func TestIsHTMLContent(t *testing.T) { tests := []struct { contentType string expected bool }{ {"text/html", true}, {"text/html; charset=utf-8", true}, {"application/json", false}, {"text/css", false}, {"application/javascript", false}, } for _, tt := range tests { result := IsHTMLContent(tt.contentType) if result != tt.expected { t.Errorf("IsHTMLContent(%q) = %v, want %v", tt.contentType, result, tt.expected) } } }