2025-05-08 18:54:23 +01:00
|
|
|
/**
|
|
|
|
|
* Owl - file renaming tool
|
|
|
|
|
* Copyright (C) 2025 User SixteenThousand of github.com
|
|
|
|
|
* Email: thomsixteenthousand@gmail.com
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
2025-05-17 15:44:39 +01:00
|
|
|
"strings"
|
2025-05-08 18:54:23 +01:00
|
|
|
)
|
|
|
|
|
|
2025-05-17 15:44:39 +01:00
|
|
|
func sliceToString(slice []string) string {
|
|
|
|
|
var b strings.Builder
|
|
|
|
|
b.WriteString("[\n")
|
|
|
|
|
for _, s := range slice {
|
|
|
|
|
b.WriteString(" ")
|
|
|
|
|
b.WriteString(s)
|
|
|
|
|
b.WriteRune('\n')
|
|
|
|
|
}
|
|
|
|
|
b.WriteRune(']')
|
|
|
|
|
return b.String()
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-08 18:54:23 +01:00
|
|
|
func TestRestrictRuneset(t *testing.T) {
|
|
|
|
|
removeTCases := map[string]string{
|
2025-05-15 10:54:05 +01:00
|
|
|
"::?\\": "_EMPTY_",
|
|
|
|
|
"The Salmon \U0001f41f Of Doubt": "The Salmon \U0001f41f Of Doubt",
|
|
|
|
|
"Why put questions in file names?": "Why put questions in file names",
|
|
|
|
|
"This* causes ~problems~": "This causes ~problems~",
|
2025-05-15 12:16:10 +01:00
|
|
|
"There are* *alot ** of c*veats * here": "There are alot of cveats here",
|
2025-05-08 18:54:23 +01:00
|
|
|
}
|
|
|
|
|
representTCases := map[string]string{
|
2025-05-15 10:54:05 +01:00
|
|
|
"::?\\": "_U3A__U3A__U3F__U5C_",
|
|
|
|
|
"Why put questions in file names?": "Why put questions in file names_U3F_",
|
|
|
|
|
"The Salmon \U0001f41f Of Doubt": "The Salmon \U0001f41f Of Doubt",
|
|
|
|
|
"This*-causes-~problems~": "This_U2A_-causes-~problems~",
|
2025-05-08 18:54:23 +01:00
|
|
|
}
|
|
|
|
|
for input, want := range removeTCases {
|
2025-05-17 15:44:39 +01:00
|
|
|
have := restrictRuneset(input, "remove")
|
|
|
|
|
if ; have != want {
|
2025-05-08 18:54:23 +01:00
|
|
|
t.Errorf(
|
|
|
|
|
"With strategy \"remove\":\n\twant <<%s>>\n\thave <<%s>>\n",
|
|
|
|
|
want,
|
|
|
|
|
have,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for input, want := range representTCases {
|
2025-05-15 10:54:05 +01:00
|
|
|
if have:=restrictRuneset(input, "represent"); have != want {
|
2025-05-08 18:54:23 +01:00
|
|
|
t.Errorf(
|
|
|
|
|
"With strategy \"represent\":\n\twant <<%s>>\n\thave <<%s>>\n",
|
|
|
|
|
want,
|
|
|
|
|
have,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|