2017-12-07 12:30:09 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-12-07 12:30:09 +05:30
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-06-30 02:30:02 +05:30
|
|
|
func TestSanitizeFlashErrorString(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
arg string
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no error",
|
|
|
|
arg: "",
|
|
|
|
want: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "normal error",
|
|
|
|
arg: "can not open file: \"abc.exe\"",
|
|
|
|
want: "can not open file: "abc.exe"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "line break error",
|
|
|
|
arg: "some error:\n\nawesome!",
|
|
|
|
want: "some error:<br><br>awesome!",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := SanitizeFlashErrorString(tt.arg); got != tt.want {
|
|
|
|
t.Errorf("SanitizeFlashErrorString() = '%v', want '%v'", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|