mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-25 05:49:13 +02:00
feat:#34 refactored function to intended service, fixed docker files
This commit is contained in:
145
services/data-manager/service/functions/string_test.go
Normal file
145
services/data-manager/service/functions/string_test.go
Normal file
@@ -0,0 +1,145 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package functions
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHashString(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{"empty string", args{""}, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
|
||||
{"non-empty string", args{"abc"}, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := HashString(tt.args.s); got != tt.want {
|
||||
t.Errorf("HashString() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSeparator(t *testing.T) {
|
||||
type args struct {
|
||||
separator []rune
|
||||
character rune
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{"empty separator", args{[]rune{}, 'a'}, false},
|
||||
{"separator with one rune equal", args{[]rune{'a'}, 'a'}, true},
|
||||
{"separator with one rune different", args{[]rune{'a'}, 'b'}, false},
|
||||
{"separator with two runes equal", args{[]rune{'a', 'b'}, 'a'}, true},
|
||||
{"separator with two runes equal second", args{[]rune{'a', 'b'}, 'b'}, true},
|
||||
{"separator with two runes different", args{[]rune{'a', 'b'}, 'c'}, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IsSeparator(tt.args.separator)(tt.args.character); got != tt.want {
|
||||
t.Errorf("IsSeparator()() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestContains(t *testing.T) {
|
||||
type args struct {
|
||||
s []string
|
||||
e string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{"empty slice", args{[]string{}, "a"}, false},
|
||||
{"slice with one element equal", args{[]string{"a"}, "a"}, true},
|
||||
{"slice with one element different", args{[]string{"a"}, "b"}, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := Contains(tt.args.s, tt.args.e); got != tt.want {
|
||||
t.Errorf("Contains() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeperateRoomString(t *testing.T) {
|
||||
type args struct {
|
||||
rooms string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{"empty string", args{""}, []string{}},
|
||||
{"one room", args{"a"}, []string{"a"}},
|
||||
{"two rooms", args{"a,b"}, []string{"a", "b"}},
|
||||
{"two rooms with whitespace", args{"a, b"}, []string{"a", "b"}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := SeperateRoomString(tt.args.rooms); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SeperateRoomString() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user