87 string splitting by separator, not whitespace

This commit is contained in:
survellow
2023-12-03 14:41:30 +01:00
parent a991e56115
commit ed99568fb1
7 changed files with 82 additions and 33 deletions

View File

@@ -1,6 +1,8 @@
package functions
import "testing"
import (
"testing"
)
func TestOnlyWhitespace(t *testing.T) {
type args struct {
@@ -52,3 +54,29 @@ func TestHashString(t *testing.T) {
})
}
}
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)
}
})
}
}