예제 #1
0
func TestNumberFmtNumber2(t *testing.T) {
	// only to test the default format
	tests := []struct {
		opts    []i18n.NumberOptions
		sign    int
		i       int64
		prec    int
		frac    int64
		want    string
		wantErr error
	}{
		{
			[]i18n.NumberOptions{
				i18n.SetNumberFormat(""),
				i18n.SetNumberSymbols(testDefCurSym),
			},
			-1, -1234, 3, 6, "-1,234.006", nil, // euros with default Symbols
		},
		{
			[]i18n.NumberOptions{
				i18n.SetNumberFormat(""),
				i18n.SetNumberSymbols(testDefCurSym),
			},
			-1, -1234, 4, 6, "-1,234.001", nil, // euros with default Symbols
		},
	}

	var buf bytes.Buffer
	for _, test := range tests {
		haveNumber := i18n.NewNumber(test.opts...)

		_, err := haveNumber.FmtNumber(&buf, test.sign, test.i, test.prec, test.frac)
		have := buf.String()
		if test.wantErr != nil {
			assert.Error(t, err)
			assert.EqualError(t, err, test.wantErr.Error())
		} else {
			assert.NoError(t, err)

			assert.EqualValues(t, test.want, have, "%v", test)
		}
		buf.Reset()
	}
}
예제 #2
0
파일: money_test.go 프로젝트: levcom/csfw
	PlusSign:               '+',
	MinusSign:              '-',
	Exponential:            'E',
	SuperscriptingExponent: '×',
	PerMille:               '‰',
	Infinity:               '∞',
	Nan:                    []byte(`NaN`),
}

var testFmtCur = i18n.NewCurrency(
	i18n.SetCurrencyFormat("¤ #,##0.00"),
	i18n.SetCurrencySymbols(testDefaultSymbols),
)
var testFmtNum = i18n.NewNumber(
	i18n.SetNumberFormat("###0.###"),
	i18n.SetNumberSymbols(testDefaultSymbols),
)

func TestString(t *testing.T) {
	tests := []struct {
		prec int
		have int64
		want string
	}{
		{0, 13, "$ 13.00"},
		{10, 13, "$ 1.30"},
		{100, 13, "$ 0.13"},
		{1000, 13, "$ 0.01"},
		{100, -13, "$ -0.13"},
		{0, -45628734653, "$ -45,628,734,653.00"},
		{10, -45628734653, "$ -4,562,873,465.30"},