Skip to content

Commit

Permalink
Feature/complete coverage (#29)
Browse files Browse the repository at this point in the history
* Catch JSON Unmarshal error

* Catch empty NewLocale error

* Catch nested NewLocale error in NewFormatter

* fixed error message
  • Loading branch information
euanwm committed Nov 18, 2023
1 parent 4066507 commit 76125e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions amount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,14 @@ func TestAmount_UnmarshalJSON(t *testing.T) {
if unmarshalled.CurrencyCode() != "USD" {
t.Errorf("got %v, want USD", unmarshalled.CurrencyCode())
}

d = []byte(`{'break_please'}`)
amount := &currency.Amount{}
err = amount.UnmarshalJSON(d)
if err == nil {
t.Errorf("error expected")
}

}

func TestAmount_Value(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestGetSymbol(t *testing.T) {
{"USD", currency.NewLocale("en-AU"), "US$", true},
{"USD", currency.NewLocale("es"), "US$", true},
{"USD", currency.NewLocale("es-ES"), "US$", true},
{"USD", currency.NewLocale(""), "", true},
}

for _, tt := range tests {
Expand Down
9 changes: 9 additions & 0 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,12 @@ func TestFormatter_Parse(t *testing.T) {
})
}
}

func TestEmptyLocale(t *testing.T) {
locale := currency.NewLocale("")
formatter := currency.NewFormatter(locale)
got := formatter.Locale().String()
if got != "" {
t.Errorf("got %v, want empty locale", got)
}
}

0 comments on commit 76125e9

Please sign in to comment.