gitea源码

html_test.go 707B

12345678910111213141516171819202122232425
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package htmlutil
  4. import (
  5. "html/template"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. type testStringer struct{}
  10. func (t testStringer) String() string {
  11. return "&StringMethod"
  12. }
  13. func TestHTMLFormat(t *testing.T) {
  14. assert.Equal(t, template.HTML("<a>&lt; < 1</a>"), HTMLFormat("<a>%s %s %d</a>", "<", template.HTML("<"), 1))
  15. assert.Equal(t, template.HTML("%!s(<nil>)"), HTMLFormat("%s", nil))
  16. assert.Equal(t, template.HTML("&lt;&gt;"), HTMLFormat("%s", template.URL("<>")))
  17. assert.Equal(t, template.HTML("&amp;StringMethod &amp;StringMethod"), HTMLFormat("%s %s", testStringer{}, &testStringer{}))
  18. }