Skip to content

Commit

Permalink
Merge pull request #23 from jeffandersen/master
Browse files Browse the repository at this point in the history
Add Currency method to Money to allow access to Currency information
  • Loading branch information
Rhymond authored Apr 25, 2017
2 parents a544e62 + 53f94dd commit 9df9f22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions money.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions money_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ func TestMoney_Add(t *testing.T) {
}
}


}

func TestMoney_Add2(t *testing.T) {
Expand Down Expand Up @@ -468,7 +467,6 @@ func TestMoney_Allocate2(t *testing.T) {
}
}


func TestMoney_Chain(t *testing.T) {
m := New(10, "EUR")
om := New(5, "EUR")
Expand Down Expand Up @@ -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())
}
}
}

0 comments on commit 9df9f22

Please sign in to comment.