-
Notifications
You must be signed in to change notification settings - Fork 149
/
formatter_test.go
67 lines (60 loc) · 2.25 KB
/
formatter_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package money
import (
"testing"
)
func TestFormatter_Format(t *testing.T) {
tcs := []struct {
fraction int
decimal string
thousand string
grapheme string
template string
amount int64
expected string
}{
{2, ".", ",", "$", "1 $", 0, "0.00 $"},
{2, ".", ",", "$", "1 $", 1, "0.01 $"},
{2, ".", ",", "$", "1 $", 12, "0.12 $"},
{2, ".", ",", "$", "1 $", 123, "1.23 $"},
{2, ".", ",", "$", "1 $", 1234, "12.34 $"},
{2, ".", ",", "$", "1 $", 12345, "123.45 $"},
{2, ".", ",", "$", "1 $", 123456, "1,234.56 $"},
{2, ".", ",", "$", "1 $", 1234567, "12,345.67 $"},
{2, ".", ",", "$", "1 $", 12345678, "123,456.78 $"},
{2, ".", ",", "$", "1 $", 123456789, "1,234,567.89 $"},
{2, ".", ",", "$", "1 $", -1, "-0.01 $"},
{2, ".", ",", "$", "1 $", -12, "-0.12 $"},
{2, ".", ",", "$", "1 $", -123, "-1.23 $"},
{2, ".", ",", "$", "1 $", -1234, "-12.34 $"},
{2, ".", ",", "$", "1 $", -12345, "-123.45 $"},
{2, ".", ",", "$", "1 $", -123456, "-1,234.56 $"},
{2, ".", ",", "$", "1 $", -1234567, "-12,345.67 $"},
{2, ".", ",", "$", "1 $", -12345678, "-123,456.78 $"},
{2, ".", ",", "$", "1 $", -123456789, "-1,234,567.89 $"},
{3, ".", "", "$", "1 $", 1, "0.001 $"},
{3, ".", "", "$", "1 $", 12, "0.012 $"},
{3, ".", "", "$", "1 $", 123, "0.123 $"},
{3, ".", "", "$", "1 $", 1234, "1.234 $"},
{3, ".", "", "$", "1 $", 12345, "12.345 $"},
{3, ".", "", "$", "1 $", 123456, "123.456 $"},
{3, ".", "", "$", "1 $", 1234567, "1234.567 $"},
{3, ".", "", "$", "1 $", 12345678, "12345.678 $"},
{3, ".", "", "$", "1 $", 123456789, "123456.789 $"},
{2, ".", ",", "£", "$1", 1, "£0.01"},
{2, ".", ",", "£", "$1", 12, "£0.12"},
{2, ".", ",", "£", "$1", 123, "£1.23"},
{2, ".", ",", "£", "$1", 1234, "£12.34"},
{2, ".", ",", "£", "$1", 12345, "£123.45"},
{2, ".", ",", "£", "$1", 123456, "£1,234.56"},
{2, ".", ",", "£", "$1", 1234567, "£12,345.67"},
{2, ".", ",", "£", "$1", 12345678, "£123,456.78"},
{2, ".", ",", "£", "$1", 123456789, "£1,234,567.89"},
}
for _, tc := range tcs {
formatter := NewFormatter(tc.fraction, tc.decimal, tc.thousand, tc.grapheme, tc.template)
r := formatter.Format(tc.amount)
if r != tc.expected {
t.Errorf("Expected %d formatted to be %s got %s", tc.amount, tc.expected, r)
}
}
}