mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
Add common StringReplace function
This commit is contained in:
@@ -159,6 +159,11 @@ func TrimString(input, cutset string) string {
|
||||
return strings.Trim(input, cutset)
|
||||
}
|
||||
|
||||
// ReplaceString replaces a string with another
|
||||
func ReplaceString(input, old, new string, n int) string {
|
||||
return strings.Replace(input, old, new, n)
|
||||
}
|
||||
|
||||
// StringToUpper changes strings to uppercase
|
||||
func StringToUpper(input string) string {
|
||||
return strings.ToUpper(input)
|
||||
|
||||
@@ -310,6 +310,28 @@ func TestTrimString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// ReplaceString replaces a string with another
|
||||
func TestReplaceString(t *testing.T) {
|
||||
t.Parallel()
|
||||
currency := "BTC-USD"
|
||||
expectedOutput := "BTCUSD"
|
||||
|
||||
actualResult := ReplaceString(currency, "-", "", -1)
|
||||
if expectedOutput != actualResult {
|
||||
t.Errorf(
|
||||
"Test failed. Expected '%s'. Actual '%s'", expectedOutput, actualResult,
|
||||
)
|
||||
}
|
||||
|
||||
currency = "BTC-USD--"
|
||||
actualResult = ReplaceString(currency, "-", "", 3)
|
||||
if expectedOutput != actualResult {
|
||||
t.Errorf(
|
||||
"Test failed. Expected '%s'. Actual '%s'", expectedOutput, actualResult,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoundFloat(t *testing.T) {
|
||||
t.Parallel()
|
||||
originalInput := float64(1.4545445445)
|
||||
|
||||
Reference in New Issue
Block a user