Files
Atay-Makhzan/modules/htmlutil/html_test.go
T

25 lines
707 B
Go
Raw Normal View History

2024-11-18 13:25:42 +08:00
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package htmlutil
import (
"html/template"
"testing"
"github.com/stretchr/testify/assert"
)
2025-06-27 17:12:25 +02:00
type testStringer struct{}
func (t testStringer) String() string {
return "&StringMethod"
}
2024-11-18 13:25:42 +08:00
func TestHTMLFormat(t *testing.T) {
assert.Equal(t, template.HTML("<a>&lt; < 1</a>"), HTMLFormat("<a>%s %s %d</a>", "<", template.HTML("<"), 1))
2025-06-27 17:12:25 +02:00
assert.Equal(t, template.HTML("%!s(<nil>)"), HTMLFormat("%s", nil))
assert.Equal(t, template.HTML("&lt;&gt;"), HTMLFormat("%s", template.URL("<>")))
assert.Equal(t, template.HTML("&amp;StringMethod &amp;StringMethod"), HTMLFormat("%s %s", testStringer{}, &testStringer{}))
2024-11-18 13:25:42 +08:00
}