本文整理汇总了Golang中github.com/corestoreio/csfw/storage/money.Currency.Option方法的典型用法代码示例。如果您正苦于以下问题:Golang Currency.Option方法的具体用法?Golang Currency.Option怎么用?Golang Currency.Option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/corestoreio/csfw/storage/money.Currency
的用法示例。
在下文中一共展示了Currency.Option方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestScan
func TestScan(t *testing.T) {
tests := []struct {
src interface{}
want string
wantErr error
}{
{nil, `NaN`, nil},
{[]byte{0x39, 0x39, 0x39, 0x2e, 0x30, 0x30, 0x30, 0x30}, `999.0000`, nil},
{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
{[]byte{0x37, 0x30, 0x35, 0x2e, 0x19, 0x39, 0x33, 0x13}, `0.0000`, strconv.ErrSyntax},
{[]byte{0x37, 0x33}, `73.0000`, nil},
{[]byte{0x37, 0x38}, `78.0000`, nil},
{[]byte{0x37, 0x34}, `74.0000`, nil},
{[]byte{0x37, 0x37}, `77.0000`, nil},
{[]byte{0xa7, 0x3e}, `0.0000`, strconv.ErrSyntax},
{int(33), `0.0000`, errors.New("Unsupported Type int for value. Supported: []byte")},
}
var buf bytes.Buffer
for _, test := range tests {
var c money.Currency
err := c.Scan(test.src)
c.Option(
money.FormatCurrency(testFmtCur),
money.FormatNumber(testFmtNum),
)
if test.wantErr != nil {
assert.Error(t, err, "%v", test)
assert.Contains(t, err.Error(), test.wantErr.Error())
} else {
assert.NoError(t, err, "%v", test)
assert.EqualValues(t, test.want, string(c.Ftoa()), "%v", test)
if _, err := c.NumberWriter(&buf); err != nil {
t.Error(err)
}
buf.WriteString("; ")
}
}
want := `NaN; 999.000; 705.993; 705.993; 705.993; 705.993; 73.000; 78.000; 74.000; 77.000; `
have := buf.String()
if want != have {
t.Errorf("\nHave: %s\n\nWant: %s\n", have, want)
}
}