예제 #1
0
func BenchmarkUnmarshalmap(b *testing.B) {
	to := testpkg.SimpleStruct{}
	m := map[string]interface{}{
		"SimpleField":   "hello",
		"field2":        "second field",
		"field3":        "third field",
		"SimpleSkipped": "skipped",
		"Ignored":       "ignore",
		"-":             "ignore",
		"SimpleOmitEmptyNoName": "noname",
	}
	for i := 0; i < b.N; i++ {
		to.UnmarshalMap(m)
	}
}
예제 #2
0
func TestSimpleStruct(t *testing.T) {
	var s testpkg.SimpleStruct
	expected := testpkg.SimpleStruct{
		SimpleField:             "hello",
		SimpleJSONTagged:        "second field",
		SimpleJSONTaggedOmitted: "third field",
		SimpleOmitEmptyNoName:   "noname",
	}
	m := map[string]interface{}{
		"SimpleField":   "hello",
		"field2":        "second field",
		"field3":        "third field",
		"SimpleSkipped": "skipped",
		"Ignored":       "ignore",
		"-":             "ignore",
		"SimpleOmitEmptyNoName": "noname",
	}

	err := s.UnmarshalMap(m)
	assert.NoError(t, err)
	assert.Equal(t, expected, s)

	equalJSONs(t, expected, m)
}