go(util): modify SanitiseFName, add test
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-17 21:50:19 +02:00
parent c9f15c9b99
commit fda5f46623
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 11 additions and 2 deletions

View File

@ -12,9 +12,9 @@
)
// SanitiseFName clears spaces from the string that is supposed to be a file
// name.
// name so that the result is safer to use with e.g. latex.
func SanitiseFName(s string) string {
return strings.ReplaceAll(s, " ", "_")
return strings.ReplaceAll(s, " ", "--")
}
// CreateFolder creates a folder at the specified path, if it doesn't already

View File

@ -41,3 +41,12 @@ func TestCreatePath(t *testing.T) {
t.Error("error cleaning up: ", err)
}
}
func TestSanitiseFname(t *testing.T) {
want := "Stochastic--Hill--Climbing"
got := SanitiseFName("Stochastic Hill Climbing")
if want != got {
t.Errorf("failed to sanitise file name, want: %s, got: %s", want, got)
}
}