当前位置: 首页>>代码示例>>Golang>>正文


Golang ff.Everything类代码示例

本文整理汇总了Golang中github.com/pquerna/ffjson/tests/types/ff.Everything的典型用法代码示例。如果您正苦于以下问题:Golang Everything类的具体用法?Golang Everything怎么用?Golang Everything使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Everything类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestUnmarshalEmpty

func TestUnmarshalEmpty(t *testing.T) {
	record := ff.Everything{}
	err := record.UnmarshalJSON([]byte(`{}`))
	if err != nil {
		t.Fatalf("UnmarshalJSON: %v", err)
	}
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:7,代码来源:types_test.go

示例2: TestUnmarshalNullPointer

func TestUnmarshalNullPointer(t *testing.T) {
	record := ff.Everything{}
	err := record.UnmarshalJSON([]byte(`{"FooStruct": null,"Something":99}`))
	if err != nil {
		t.Fatalf("UnmarshalJSON: %v", err)
	}
	if record.FooStruct != nil {
		t.Fatalf("record.Something decoding problem, expected: nil got: %v", record.FooStruct)
	}
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:10,代码来源:types_test.go

示例3: TestUnmarshalFull

func TestUnmarshalFull(t *testing.T) {
	record := ff.Everything{}
	// TODO(pquerna): add unicode snowman
	// TODO(pquerna): handle Bar subtype
	err := record.UnmarshalJSON([]byte(everythingJson))
	if err != nil {
		t.Fatalf("UnmarshalJSON: %v", err)
	}

	expect := "snowman☃𐐷"
	if record.String != expect {
		t.Fatalf("record.String decoding problem, expected: %v got: %v", expect, record.String)
	}

	if record.Something != 99 {
		t.Fatalf("record.Something decoding problem, expected: 99 got: %v", record.Something)
	}
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:18,代码来源:types_test.go

示例4: TestRoundTrip

func TestRoundTrip(t *testing.T) {
	var record ff.Everything
	var recordTripped ff.Everything
	ff.NewEverything(&record)

	buf1, err := json.Marshal(&record)
	if err != nil {
		t.Fatalf("Marshal: %v", err)
	}

	recordTripped.MySweetInterface = &ff.Cats{}
	err = json.Unmarshal(buf1, &recordTripped)
	if err != nil {
		t.Fatalf("Unmarshal: %v", err)
	}

	good := reflect.DeepEqual(record.FooStruct, recordTripped.FooStruct)
	if !good {
		t.Fatalf("Expected: %v\n Got: %v", *record.FooStruct, *recordTripped.FooStruct)
	}

	record.FooStruct = nil
	recordTripped.FooStruct = nil

	good = reflect.DeepEqual(record, recordTripped)
	if !good {
		t.Fatalf("Expected: %v\n Got: %v", record, recordTripped)
	}

	if recordTripped.SuperBool != true {
		t.Fatal("Embeded struct didn't Unmarshal")
	}

	if recordTripped.Something != 99 {
		t.Fatal("Embeded nonexported-struct didn't Unmarshal")
	}
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:37,代码来源:types_test.go

示例5: TestUnmarshalToReusedObject

func TestUnmarshalToReusedObject(t *testing.T) {
	JSONParts := []string{
		`"Bool":true`,
		`"Int":1`,
		`"Int8": 2`,
		`"Int16": 3`,
		`"Int32": -4`,
		`"Int64": 57`,
		`"Uint": 100`,
		`"Uint8": 101`,
		`"Uint16": 102`,
		`"Uint32": 50`,
		`"Uint64": 103`,
		`"Uintptr": 104`,
		`"Float32": 3.14`,
		`"Float64": 3.15`,
		`"Array": [1,2,3]`,
		`"Map": {"bar": 2,"foo": 1}`,
		`"String": "snowman☃\uD801\uDC37"`,
		`"StringPointer": "pointed snowman☃\uD801\uDC37"`,
		`"Int64Pointer": 44`,
		`"FooStruct": {"Bar": 1}`,
		`"MapMap": {"a0": {"b0":"foo"}, "a1":{"a2":"bar"}}`,
		`"MapArraySlice": {"foo":[[1,2,3],[4,5,6],[7]], "bar": [[1,2,3,4],[5,6,7]]}`,
		`"Something": 99`,
	}

	JSONWhole := "{" + strings.Join(JSONParts, ",") + "}"
	var record ff.Everything
	if err := record.UnmarshalJSON([]byte(JSONWhole)); err != nil {
		t.Fatalf("UnmarshalJSON: %v", err)
	}

	for _, part := range JSONParts {
		reuseRecord := record
		if err := reuseRecord.UnmarshalJSON([]byte("{" + part + "}")); err != nil {
			t.Fatalf("UnmarshalJSON: %v", err)
		}
		var emptyRecord ff.Everything
		if err := emptyRecord.UnmarshalJSON([]byte("{" + part + "}")); err != nil {
			t.Fatalf("UnmarshalJSON: %v", err)
		}

		if !reflect.DeepEqual(reuseRecord, emptyRecord) {
			t.Errorf("%#v should be equal to %#v", reuseRecord, emptyRecord)
		}
	}
}
开发者ID:pquerna,项目名称:ffjson,代码行数:48,代码来源:types_test.go


注:本文中的github.com/pquerna/ffjson/tests/types/ff.Everything类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。