forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
currencies_test.go
64 lines (54 loc) · 1.63 KB
/
currencies_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package currency
import (
"encoding/json"
"testing"
)
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")
}
}