本文整理汇总了Golang中github.com/corestoreio/csfw/storage/money.Money.Scan方法的典型用法代码示例。如果您正苦于以下问题:Golang Money.Scan方法的具体用法?Golang Money.Scan怎么用?Golang Money.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/corestoreio/csfw/storage/money.Money
的用法示例。
在下文中一共展示了Money.Scan方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.Money
err := c.Scan(test.src)
c.FmtCur = testFmtCur
c.FmtNum = 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)
}
}
示例2: Benchmark_MoneyScan
// Benchmark_MoneyScan 3000000 504 ns/op 136 B/op 2 allocs/op => Go 1.4.2
// Benchmark_MoneyScan 5000000 386 ns/op 144 B/op 2 allocs/op => Go 1.5.0
func Benchmark_MoneyScan(b *testing.B) {
var d interface{}
d = []byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}
var want float64 = 705.993300
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
var c money.Money
c.Scan(d)
benchmarkMoneyScan = c.Getf()
if benchmarkMoneyScan != want {
b.Errorf("Have: %f\nWant: %f", benchmarkMoneyScan, want)
}
}
}