Skip to content

Commit

Permalink
Merge pull request #24 from llonchj/fix-currency-money-New
Browse files Browse the repository at this point in the history
A new instance of Money has invalid Currency contents
  • Loading branch information
Rhymond authored May 30, 2017
2 parents 9df9f22 + f119e53 commit 52c0831
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion money.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Money struct {
func New(amount int64, code string) *Money {
return &Money{
amount: &Amount{val: amount},
currency: newCurrency(code),
currency: newCurrency(code).get(),
}
}

Expand Down
15 changes: 15 additions & 0 deletions money_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ func TestNew(t *testing.T) {
}
}

func TestCurrency(t *testing.T) {
code := "MOCK"
decimals := 5
AddCurrency(code, "M$", "1 $", ".", ",", decimals)
m := New(1, code)
c := m.Currency().Code
if c != code {
t.Errorf("Expected %d got %d", code, c)
}
f := m.Currency().Fraction
if f != decimals {
t.Errorf("Expected %d got %d", decimals, f)
}
}

func TestMoney_SameCurrency(t *testing.T) {
m := New(0, "EUR")
om := New(0, "USD")
Expand Down

0 comments on commit 52c0831

Please sign in to comment.