gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package utils
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestSanitizeFlashErrorString(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. arg string
  12. want string
  13. }{
  14. {
  15. name: "no error",
  16. arg: "",
  17. want: "",
  18. },
  19. {
  20. name: "normal error",
  21. arg: "can not open file: \"abc.exe\"",
  22. want: "can not open file: "abc.exe"",
  23. },
  24. {
  25. name: "line break error",
  26. arg: "some error:\n\nawesome!",
  27. want: "some error:<br><br>awesome!",
  28. },
  29. }
  30. for _, tt := range tests {
  31. t.Run(tt.name, func(t *testing.T) {
  32. got := SanitizeFlashErrorString(tt.arg)
  33. assert.Equal(t, tt.want, got)
  34. })
  35. }
  36. }