mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-08 04:39:13 +02:00
23 fix only whitespaces + conditional attributes
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
package functions
|
||||
|
||||
import "unicode"
|
||||
import "strings"
|
||||
|
||||
// check if course is empty or contains only whitespaces
|
||||
// check if string is empty or contains only whitespaces
|
||||
func OnlyWhitespace(word string) bool {
|
||||
for _, letter := range word {
|
||||
if !unicode.IsSpace(letter) || !(letter == int32(160)) {
|
||||
return false
|
||||
}
|
||||
if len(strings.TrimSpace(word)) == 0 {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
func Contains(s []string, e string) bool {
|
||||
|
33
backend/service/functions/string_test.go
Normal file
33
backend/service/functions/string_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package functions
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestOnlyWhitespace(t *testing.T) {
|
||||
type args struct {
|
||||
word string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{"empty string", args{""}, true},
|
||||
{"whitespace", args{" "}, true},
|
||||
{"whitespaces", args{" "}, true},
|
||||
{"whitespaces and tabs", args{" \t"}, true},
|
||||
{"whitespaces and tabs and newlines", args{" \t\n"}, true},
|
||||
{"whitespaces and tabs and newlines and non-breaking spaces", args{" \t\n\u00A0"}, true},
|
||||
{"non-whitespace", args{"a"}, false},
|
||||
{"non-whitespaces", args{"abc"}, false},
|
||||
{"non-whitespaces and tabs", args{"abc\t"}, false},
|
||||
{"non-whitespaces and tabs and newlines", args{"abc\t\n"}, false},
|
||||
{"non-whitespaces and tabs and newlines and non-breaking spaces", args{"abc\t\n\u00A0"}, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := OnlyWhitespace(tt.args.word); got != tt.want {
|
||||
t.Errorf("OnlyWhitespace() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user