forked from Rhymond/go-money
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurrency_test.go
90 lines (76 loc) · 1.83 KB
/
currency_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package money
import (
"reflect"
"testing"
)
func TestCurrency_Get(t *testing.T) {
tcs := []struct {
code string
expected string
}{
{EUR, "EUR"},
{"EUR", "EUR"},
{"Eur", "EUR"},
}
for _, tc := range tcs {
c := newCurrency(tc.code).get()
if c.Code != tc.expected {
t.Errorf("Expected %s got %s", tc.expected, c.Code)
}
}
}
func TestCurrency_Get1(t *testing.T) {
code := "RANDOM"
c := newCurrency(code).get()
if c.Grapheme != code {
t.Errorf("Expected %s got %s", c.Grapheme, code)
}
}
func TestCurrency_Equals(t *testing.T) {
tcs := []struct {
code string
other string
}{
{EUR, "EUR"},
{"EUR", "EUR"},
{"Eur", "EUR"},
{"usd", "USD"},
}
for _, tc := range tcs {
c := newCurrency(tc.code).get()
oc := newCurrency(tc.other).get()
if !c.equals(oc) {
t.Errorf("Expected that %v is not equal %v", c, oc)
}
}
}
func TestCurrency_AddCurrency(t *testing.T) {
tcs := []struct {
code string
template string
}{
{"GOLD", "1$"},
}
for _, tc := range tcs {
AddCurrency(tc.code, "", tc.template, "", "", 0)
c := newCurrency(tc.code).get()
if c.Template != tc.template {
t.Errorf("Expected currency template %v got %v", tc.template, c.Template)
}
}
}
func TestCurrency_GetCurrency(t *testing.T) {
code := "KLINGONDOLLAR"
desired := Currency{Decimal: ".", Thousand: ",", Code: code, Fraction: 2, Grapheme: "$", Template: "$1"}
AddCurrency(desired.Code, desired.Grapheme, desired.Template, desired.Decimal, desired.Thousand, desired.Fraction)
currency := GetCurrency(code)
if !reflect.DeepEqual(currency, &desired) {
t.Errorf("Currencies do not match %+v got %+v", desired, currency)
}
}
func TestCurrency_GetNonExistingCurrency(t *testing.T) {
currency := GetCurrency("I*am*Not*a*Currency")
if currency != nil {
t.Errorf("Unexpected currency returned %+v", currency)
}
}