aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/tdewolff/parse/strconv/price_test.go
blob: 3b3fccf6042aec63a2af5ba930164d4ac8f50db7 (plain)
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
package strconv // import "github.com/tdewolff/parse/strconv"

import (
	"testing"

	"github.com/tdewolff/test"
)

func TestAppendPrice(t *testing.T) {
	priceTests := []struct {
		price    int64
		dec      bool
		expected string
	}{
		{0, false, "0"},
		{0, true, "0.00"},
		{100, true, "1.00"},
		{-100, true, "1.00"},
		{100000, false, "1,000"},
		{100000, true, "1,000.00"},
		{123456789012, true, "1,234,567,890.12"},
		{9223372036854775807, true, "92,233,720,368,547,758.07"},
		{-9223372036854775808, true, "92,233,720,368,547,758.08"},
	}
	for _, tt := range priceTests {
		price := AppendPrice([]byte{}, tt.price, tt.dec, ',', '.')
		test.String(t, string(price), tt.expected, "for", tt.price)
	}
}