mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* tag optional sonic and allow full library conversion * Add workflow and disallow arm and darwin usage * Add basic hotswap benchmark * linter: fix * use bash * linter: fix? * Fix whoopsie, add to make file, also add mention in features list. * test enforcement * actually read documentation see if this works * linter: fix * linter: fix * sonic: bump tagged version * encoding/json: drop build tag arch and os filters * encoding/json: consolidate tests * encoding/json: log build tag usage * rm superfluous builds * glorious/nits: add template change and regen docs * glorious/nits: update commentary on nolint directive * glorious/nits: rm init func and log results in main.go * Test to actually pull flag in * linter: fix * thrasher: nits * gk: nits 4 goflags goooooooooo! * gk: nits rn * make sonic default json implementation * screen 386 * linter: fix * Add commentary * glorious: nits Makefile not working * gk: nits * gk: nits whoops * whoopsirino * mention 32bit systems won't be sonic * gk: super-duper nit of extremes --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package currency
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
|
)
|
|
|
|
func TestCurrenciesUnmarshalJSON(t *testing.T) {
|
|
var unmarshalHere Currencies
|
|
expected := "btc,usd,ltc,bro,things"
|
|
encoded, err := json.Marshal(expected)
|
|
if err != nil {
|
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
|
}
|
|
|
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
|
if err != nil {
|
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
|
}
|
|
|
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
|
if err != nil {
|
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
|
}
|
|
|
|
if unmarshalHere.Join() != expected {
|
|
t.Errorf("Currencies UnmarshalJSON() error expected %s but received %s",
|
|
expected, unmarshalHere.Join())
|
|
}
|
|
}
|
|
|
|
func TestCurrenciesMarshalJSON(t *testing.T) {
|
|
quickStruct := struct {
|
|
C Currencies `json:"amazingCurrencies"`
|
|
}{
|
|
C: NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro", "things"}),
|
|
}
|
|
|
|
encoded, err := json.Marshal(quickStruct)
|
|
if err != nil {
|
|
t.Fatal("Currencies MarshalJSON() error", err)
|
|
}
|
|
|
|
expected := `{"amazingCurrencies":"btc,usd,ltc,bro,things"}`
|
|
if string(encoded) != expected {
|
|
t.Errorf("Currencies MarshalJSON() error expected %s but received %s",
|
|
expected, string(encoded))
|
|
}
|
|
}
|
|
|
|
func TestMatch(t *testing.T) {
|
|
matchString := []string{"btc", "usd", "ltc", "bro", "things"}
|
|
c := NewCurrenciesFromStringArray(matchString)
|
|
|
|
if !c.Match(NewCurrenciesFromStringArray(matchString)) {
|
|
t.Fatal("should match")
|
|
}
|
|
if c.Match(NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro"})) {
|
|
t.Fatal("should not match")
|
|
}
|
|
if c.Match(NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro", "garbo"})) {
|
|
t.Fatal("should not match")
|
|
}
|
|
}
|
|
|
|
func TestCurrenciesAdd(t *testing.T) {
|
|
c := Currencies{}
|
|
c = c.Add(BTC)
|
|
assert.Len(t, c, 1, "Should have one currency")
|
|
c = c.Add(ETH)
|
|
assert.Len(t, c, 2, "Should have two currencies")
|
|
c = c.Add(BTC)
|
|
assert.Len(t, c, 2, "Adding a duplicate should not change anything")
|
|
}
|