當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Currency.FtoaAppend方法代碼示例

本文整理匯總了Golang中github.com/corestoreio/csfw/storage/money.Currency.FtoaAppend方法的典型用法代碼示例。如果您正苦於以下問題:Golang Currency.FtoaAppend方法的具體用法?Golang Currency.FtoaAppend怎麽用?Golang Currency.FtoaAppend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/corestoreio/csfw/storage/money.Currency的用法示例。


在下文中一共展示了Currency.FtoaAppend方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
			}

		}
	}
}
開發者ID:hafeez3000,項目名稱:csfw,代碼行數:59,代碼來源:encoding_test.go


注:本文中的github.com/corestoreio/csfw/storage/money.Currency.FtoaAppend方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。