本文整理汇总了Golang中github.com/corestoreio/csfw/storage/money.Currency.UnmarshalJSON方法的典型用法代码示例。如果您正苦于以下问题:Golang Currency.UnmarshalJSON方法的具体用法?Golang Currency.UnmarshalJSON怎么用?Golang Currency.UnmarshalJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/corestoreio/csfw/storage/money.Currency
的用法示例。
在下文中一共展示了Currency.UnmarshalJSON方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestJSONUnMarshalSingle
func TestJSONUnMarshalSingle(t *testing.T) {
tests := []struct {
haveEnc money.JSONMarshaller
jsonData []byte
want string
wantErr error
}{
{money.JSONNumber, []byte{0xf1, 0x32, 0xd8, 0x8a, 0x12, 0x8a, 0x74, 0x2a, 0x5, 0x5d, 0x18, 0x39, 0xf9, 0xd7, 0x99, 0x8b}, `NaN`, nil},
{money.JSONNumber, []byte(`1999.0000`), `1999.0000`, nil},
{money.JSONNumber, []byte(`-0.01`), `-0.0100`, nil},
{money.JSONNumber, []byte(`null`), `NaN`, nil},
{money.JSONNumber, []byte(`1234.56789`), `1234.5679`, nil},
{money.JSONNumber, []byte(`-1234.56789`), `-1234.5679`, nil},
{money.JSONNumber, []byte(`2999x.0156`), `2999.0156`, nil},
{money.JSONNumber, []byte(`""`), `NaN`, nil},
{money.JSONLocale, []byte(`$ 999.00 `), `999.0000`, nil},
{money.JSONLocale, []byte(`EUR 999.00`), `999.0000`, nil},
{money.JSONLocale, []byte(`EUR 99x9.0'0`), `999.0000`, nil},
{money.JSONLocale, []byte("EUR \x00 99x9.0'0"), `999.0000`, nil},
{money.JSONLocale, []byte(`2 345 678,45 €`), `2345678.4500`, nil},
{money.JSONLocale, []byte(`2 345 367,834456 €`), `2345367.8345`, nil},
{money.JSONLocale, []byte(`null`), `NaN`, nil},
{money.JSONLocale, []byte(`1.705,99 €`), `1705.9900`, nil},
{money.JSONLocale, []byte(`705,99 €`), `705.9900`, nil},
{money.JSONLocale, []byte(`$ 5,123,705.94`), `5123705.9400`, nil},
{money.JSONLocale, []byte(`$ -6,705.99`), `-6705.9900`, nil},
{money.JSONLocale, []byte(`$ 705.99`), `705.9900`, nil},
{money.JSONLocale, []byte(`$ 70789`), `70789.0000`, nil},
{money.JSONExtended, []byte(`[999.0000,"$","$ 999.00"]`), `999.0000`, nil},
{money.JSONExtended, []byte(`[999.0000,null,null]`), `999.0000`, nil},
{money.JSONExtended, []byte(`[1,999.00236,null,null]`), `1.0000`, nil},
{money.JSONExtended, []byte(`[1999.00236,null,null]`), `1999.0024`, nil},
{money.JSONExtended, []byte(`null`), `NaN`, nil},
{money.JSONExtended, []byte(`[null,"$",null]`), `NaN`, nil},
{money.JSONExtended, []byte(`[null,null,null]`), `NaN`, nil},
{money.JSONExtended, []byte(`[ ]`), `NaN`, money.ErrDecodeMissingColon},
}
for _, test := range tests {
var c money.Currency
err := c.UnmarshalJSON(test.jsonData)
if test.wantErr != nil {
assert.Error(t, err)
assert.EqualError(t, err, test.wantErr.Error())
} else {
var buf []byte
assert.NoError(t, err)
buf = c.FtoaAppend(buf)
have := string(buf)
if test.want != have {
t.Errorf("\nHave: %s\n\nWant: %s\n", have, test.want)
}
}
}
}
示例2: benchmark_JSONUnMarshalSingle
func benchmark_JSONUnMarshalSingle(b *testing.B, data []byte, want int64) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
var c money.Currency
if err := c.UnmarshalJSON(data); err != nil {
b.Error(err)
}
benchmark_JSONUnMarshalSingleValue = c.Raw()
if benchmark_JSONUnMarshalSingleValue != want {
b.Errorf("Have: %d\nWant: %d", benchmark_JSONUnMarshalSingleValue, want)
}
}
}