From 53f94dd8974a5b1316b67f3dbeae5de42ef55c3e Mon Sep 17 00:00:00 2001 From: Jeff Andersen Date: Tue, 25 Apr 2017 10:49:43 -0300 Subject: [PATCH] Add Currency method to Money to allow access to Currency information --- money.go | 5 +++++ money_test.go | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/money.go b/money.go index 16886fd..36230c9 100644 --- a/money.go +++ b/money.go @@ -24,6 +24,11 @@ func New(amount int64, code string) *Money { } } +// Currency returns the currency used by Money +func (m *Money) Currency() *Currency { + return m.currency +} + // Amount returns a copy of the internal monetary value as an int64 func (m *Money) Amount() int64 { return m.amount.val diff --git a/money_test.go b/money_test.go index 3b1408b..02fe644 100644 --- a/money_test.go +++ b/money_test.go @@ -278,7 +278,6 @@ func TestMoney_Add(t *testing.T) { } } - } func TestMoney_Add2(t *testing.T) { @@ -468,7 +467,6 @@ func TestMoney_Allocate2(t *testing.T) { } } - func TestMoney_Chain(t *testing.T) { m := New(10, "EUR") om := New(5, "EUR") @@ -590,10 +588,18 @@ func TestMoney_Comparison(t *testing.T) { } } +func TestMoney_Currency(t *testing.T) { + pound := New(100, "GBP") + + if pound.Currency().Code != "GBP" { + t.Errorf("Expected %s got %s", "GBP", pound.Currency().Code) + } +} + func TestMoney_Amount(t *testing.T) { pound := New(100, "GBP") if pound.Amount() != 100 { t.Errorf("Expected %d got %d", 100, pound.Amount()) } -} \ No newline at end of file +}