mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Added new function in common.
This commit is contained in:
committed by
Adrian Gallagher
parent
cd398bd35f
commit
fa041104b2
@@ -155,6 +155,17 @@ func StringDataCompare(haystack []string, needle string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// StringDataContainsUpper checks the substring array with an input and returns
|
||||
// a bool irrespective of lower or upper case strings
|
||||
func StringDataContainsUpper(haystack []string, needle string) bool {
|
||||
for _, data := range haystack {
|
||||
if strings.Contains(StringToUpper(data), StringToUpper(needle)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// JoinStrings joins an array together with the required separator and returns
|
||||
// it as a string
|
||||
func JoinStrings(input []string, separator string) string {
|
||||
|
||||
@@ -281,6 +281,25 @@ func TestStringDataCompare(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringDataContainsUpper(t *testing.T) {
|
||||
t.Parallel()
|
||||
originalHaystack := []string{"bLa", "BrO", "sUp"}
|
||||
originalNeedle := "Bla"
|
||||
anotherNeedle := "ning"
|
||||
expectedOutput := true
|
||||
expectedOutputTwo := false
|
||||
actualResult := StringDataContainsUpper(originalHaystack, originalNeedle)
|
||||
if actualResult != expectedOutput {
|
||||
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
|
||||
expectedOutput, actualResult)
|
||||
}
|
||||
actualResult = StringDataContainsUpper(originalHaystack, anotherNeedle)
|
||||
if actualResult != expectedOutputTwo {
|
||||
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
|
||||
expectedOutput, actualResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinStrings(t *testing.T) {
|
||||
t.Parallel()
|
||||
originalInputOne := []string{"hello", "moto"}
|
||||
|
||||
Reference in New Issue
Block a user