1 // Copyright 2016 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 var testUUID = Must(Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479"))
15 func TestJSON(t *testing.T) {
20 s1 := S{ID1: testUUID}
21 data, err := json.Marshal(&s1)
26 if err := json.Unmarshal(data, &s2); err != nil {
29 if !reflect.DeepEqual(&s1, &s2) {
30 t.Errorf("got %#v, want %#v", s2, s1)
34 func BenchmarkUUID_MarshalJSON(b *testing.B) {
36 UUID UUID `json:"uuid"`
39 x.UUID, err = Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
43 for i := 0; i < b.N; i++ {
44 js, err := json.Marshal(x)
46 b.Fatalf("marshal json: %#v (%v)", js, err)
51 func BenchmarkUUID_UnmarshalJSON(b *testing.B) {
52 js := []byte(`{"uuid":"f47ac10b-58cc-0372-8567-0e02b2c3d479"}`)
54 UUID UUID `json:"uuid"`
56 for i := 0; i < b.N; i++ {
57 err := json.Unmarshal(js, &x)
59 b.Fatalf("marshal json: %#v (%v)", js, err)