mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +00:00
build/ci: Update Go to v1.24, golangci-lint to v1.64.6 and fix issues (#1804)
* build/ci: Update Go to v1.24, golangci-lint to v1.64.5 and fix issues * Address shazbert's nitters * linter/config: Fix new linter issue and use versionSize const * Address gk's nitters and fix additional linter issue after rebase * Address glorious nits * staticcheck: Fix additional linter issues after upgrading to Go 1.24.1 and golangci-lint v1.64.6 Also addresses nits * Improve testing, assertify usage and use common.ErrParsingWSField * TestCreateNewStrategy: Replace must > should wording
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -156,131 +155,44 @@ func TestBoolPtr(t *testing.T) {
|
||||
|
||||
func TestFloatToHumanFriendlyString(t *testing.T) {
|
||||
t.Parallel()
|
||||
test := FloatToHumanFriendlyString(0, 3, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = FloatToHumanFriendlyString(100, 3, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = FloatToHumanFriendlyString(1000, 3, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = FloatToHumanFriendlyString(-1000, 3, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = FloatToHumanFriendlyString(-1000, 10, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = FloatToHumanFriendlyString(1000.1337, 1, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec := strings.Split(test, ".")
|
||||
if len(dec) == 1 {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
if dec[1] != "1" {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
assert.Equal(t, "0.000", FloatToHumanFriendlyString(0, 3, ".", ","))
|
||||
assert.Equal(t, "100.000", FloatToHumanFriendlyString(100, 3, ".", ","))
|
||||
assert.Equal(t, "1,000.000", FloatToHumanFriendlyString(1000, 3, ".", ","))
|
||||
assert.Equal(t, "-1,000.000", FloatToHumanFriendlyString(-1000, 3, ".", ","))
|
||||
assert.Equal(t, "-1,000.0000000000", FloatToHumanFriendlyString(-1000, 10, ".", ","))
|
||||
assert.Equal(t, "1!000.1", FloatToHumanFriendlyString(1000.1337, 1, ".", "!"))
|
||||
}
|
||||
|
||||
func TestDecimalToHumanFriendlyString(t *testing.T) {
|
||||
t.Parallel()
|
||||
test := DecimalToHumanFriendlyString(decimal.Zero, 0, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromInt(100), 0, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromInt(1000), 0, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.1337), 1, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec := strings.Split(test, ".")
|
||||
if len(dec) == 1 {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
if dec[1] != "1" {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(-1000.1337), 1, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(-1000.1337), 100000, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.1), 10, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec = strings.Split(test, ".")
|
||||
if len(dec) == 1 {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
if dec[1] != "1" {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
assert.Equal(t, "0", DecimalToHumanFriendlyString(decimal.Zero, 0, ".", ","))
|
||||
assert.Equal(t, "100", DecimalToHumanFriendlyString(decimal.NewFromInt(100), 0, ".", ","))
|
||||
assert.Equal(t, "1,000", DecimalToHumanFriendlyString(decimal.NewFromInt(1000), 0, ".", ","))
|
||||
assert.Equal(t, "-1,000", DecimalToHumanFriendlyString(decimal.NewFromInt(-1000), 0, ".", ","))
|
||||
assert.Equal(t, "-1~000!42", DecimalToHumanFriendlyString(decimal.NewFromFloat(-1000.42069), 2, "!", "~"))
|
||||
assert.Equal(t, "1,000.42069", DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.42069), 5, ".", ","))
|
||||
assert.Equal(t, "1,000.42069", DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.42069), 100, ".", ","))
|
||||
}
|
||||
|
||||
func TestIntToHumanFriendlyString(t *testing.T) {
|
||||
t.Parallel()
|
||||
test := IntToHumanFriendlyString(0, ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = IntToHumanFriendlyString(100, ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = IntToHumanFriendlyString(1000, ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = IntToHumanFriendlyString(-1000, ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = IntToHumanFriendlyString(1000000, ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec := strings.Split(test, ",")
|
||||
if len(dec) <= 2 {
|
||||
t.Error("expected two commas place")
|
||||
}
|
||||
assert.Equal(t, "0", IntToHumanFriendlyString(0, ","))
|
||||
assert.Equal(t, "100", IntToHumanFriendlyString(100, ","))
|
||||
assert.Equal(t, "1,000", IntToHumanFriendlyString(1000, ","))
|
||||
assert.Equal(t, "-1,000", IntToHumanFriendlyString(-1000, ","))
|
||||
assert.Equal(t, "-1!000", IntToHumanFriendlyString(-1000, "!"))
|
||||
}
|
||||
|
||||
func TestNumberToHumanFriendlyString(t *testing.T) {
|
||||
resp := numberToHumanFriendlyString("1", 1337, ".", ",", false)
|
||||
if strings.Contains(resp, ".") {
|
||||
t.Error("expected no comma")
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, "0", numberToHumanFriendlyString("0", 0, "", ",", false))
|
||||
assert.Equal(t, "1,337.69", numberToHumanFriendlyString("1337.69", 2, ".", ",", false))
|
||||
assert.Equal(t, "-1!000.1", numberToHumanFriendlyString("1000.1", 1, ".", "!", true))
|
||||
assert.Equal(t, "1,000", numberToHumanFriendlyString("1000", 20, ".", ",", false))
|
||||
}
|
||||
|
||||
func TestInterfaceToFloat64OrZeroValue(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user