mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
Add support for *suffix in filterhelpers.go
This commit is contained in:
committed by
Dan Christian Bogos
parent
05e2377d3c
commit
c2bb67bafa
@@ -313,6 +313,16 @@ func SplitPrefix(prefix string, minLength int) []string {
|
||||
return subs
|
||||
}
|
||||
|
||||
func SplitSuffix(suffix string) []string {
|
||||
length := len(suffix)
|
||||
subs := make([]string, length)
|
||||
max := len(suffix) - 1
|
||||
for i := 0; i < length; i++ {
|
||||
subs[i] = suffix[max-i:]
|
||||
}
|
||||
return subs
|
||||
}
|
||||
|
||||
func CopyHour(src, dest time.Time) time.Time {
|
||||
if src.Hour() == 0 && src.Minute() == 0 && src.Second() == 0 {
|
||||
return src
|
||||
|
||||
@@ -522,14 +522,35 @@ func TestRoundDuration(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSplitPrefix(t *testing.T) {
|
||||
exp := []string{"0123456789", "012345678", "01234567", "0123456", "012345", "01234", "0123", "012", "01", "0"}
|
||||
if a := SplitPrefix("0123456789", 1); len(a) != 10 {
|
||||
t.Error("Error splitting prefix: ", a)
|
||||
} else if !reflect.DeepEqual(a, exp) {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, a)
|
||||
}
|
||||
exp = []string{"0123456789", "012345678", "01234567", "0123456", "012345", "01234"}
|
||||
if a := SplitPrefix("0123456789", 5); len(a) != 6 {
|
||||
t.Error("Error splitting prefix: ", a)
|
||||
} else if !reflect.DeepEqual(a, exp) {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, a)
|
||||
}
|
||||
exp = []string{}
|
||||
if a := SplitPrefix("", 1); len(a) != 0 {
|
||||
t.Error("Error splitting prefix: ", a)
|
||||
} else if !reflect.DeepEqual(a, exp) {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitSuffix(t *testing.T) {
|
||||
exp := []string{"9", "89", "789", "6789", "56789", "456789", "3456789", "23456789", "123456789", "0123456789"}
|
||||
if a := SplitSuffix("0123456789"); len(a) != 10 {
|
||||
t.Error("Error splitting prefix: ", ToJSON(a))
|
||||
} else if !reflect.DeepEqual(a, exp) {
|
||||
t.Errorf("Expecting: %v, received: %v", exp, a)
|
||||
}
|
||||
if a := SplitSuffix(""); len(a) != 0 {
|
||||
t.Error("Error splitting prefix: ", a)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user