-
Notifications
You must be signed in to change notification settings - Fork 4
/
money_test.go
37 lines (32 loc) · 1.61 KB
/
money_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
package utils
import (
"testing"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
)
func Test_FormatToIndonesianMoney(t *testing.T) {
t.Run("Success", func(t *testing.T) {
price := decimal.NewFromFloat(10000000.88)
result := FormatToIndonesianMoney(price)
assert.Equal(t, result, "Rp10.000.001")
})
}
func TestFormatMoney(t *testing.T) {
assert.Equal(t, "Rp10.000.000", FormatMoney(decimal.NewFromFloat(10000000), "IDR"))
assert.Equal(t, "Rp10.000.001", FormatMoney(decimal.NewFromFloat(10000000.88), "IDR"))
assert.Equal(t, "$1.49", FormatMoney(decimal.NewFromFloat(1.49), "USD"))
assert.Equal(t, "$1.49", FormatMoney(decimal.NewFromFloat(1.4889), "USD"))
assert.Equal(t, "¥149", FormatMoney(decimal.NewFromFloat(149), "JPY"))
assert.Equal(t, "¥149", FormatMoney(decimal.NewFromFloat(148.89), "JPY"))
assert.Equal(t, "€1.49", FormatMoney(decimal.NewFromFloat(1.49), "EUR"))
assert.Equal(t, "€1.49", FormatMoney(decimal.NewFromFloat(1.4889), "EUR"))
assert.Equal(t, "£1.49", FormatMoney(decimal.NewFromFloat(1.49), "GBP"))
assert.Equal(t, "£1.49", FormatMoney(decimal.NewFromFloat(1.4889), "GBP"))
assert.Equal(t, "A$1.49", FormatMoney(decimal.NewFromFloat(1.49), "AUD"))
assert.Equal(t, "A$1.49", FormatMoney(decimal.NewFromFloat(1.4889), "AUD"))
assert.Equal(t, "CA$1.49", FormatMoney(decimal.NewFromFloat(1.49), "CAD"))
assert.Equal(t, "CA$1.49", FormatMoney(decimal.NewFromFloat(1.4889), "CAD"))
// handle unknown currency code
assert.Equal(t, "ASU1.49", FormatMoney(decimal.NewFromFloat(1.4889), "ASU"))
assert.Equal(t, "ZZZ1.49", FormatMoney(decimal.NewFromFloat(1.4889), "ZZZ"))
}