Browse Source

codec: test: move AnonInTestStrucIntf from values_test.go into values_flex_test.go

Some external libs (e.g. easyjson, ffjson) cannot initialize a pointer field
which is nil, making it impossible to run benchmarks against them.

So we just moved it into values_flex_test.go, so we still validate it for codec,
but can run with the highest common denominator for benchmarks.
Ugorji Nwoke 8 years ago
parent
commit
a437b1adc2
2 changed files with 26 additions and 26 deletions
  1. 26 0
      codec/values_flex_test.go
  2. 0 26
      codec/values_test.go

+ 26 - 0
codec/values_flex_test.go

@@ -5,6 +5,8 @@
 
 
 package codec
 package codec
 
 
+import "time"
+
 // This file contains values used by tests alone.
 // This file contains values used by tests alone.
 // This is where we may try out different things,
 // This is where we may try out different things,
 // that other engines may not support or may barf upon
 // that other engines may not support or may barf upon
@@ -55,7 +57,15 @@ type wrapInt64 int64
 type wrapUint8 uint8
 type wrapUint8 uint8
 type wrapBytes []uint8
 type wrapBytes []uint8
 
 
+type AnonInTestStrucIntf struct {
+	Islice []interface{}
+	Ms     map[string]interface{}
+	Nintf  interface{} //don't set this, so we can test for nil
+	T      time.Time
+}
+
 var testWRepeated512 wrapBytes
 var testWRepeated512 wrapBytes
+var testStrucTime = time.Date(2012, 2, 2, 2, 2, 2, 2000, time.UTC).UTC()
 
 
 func init() {
 func init() {
 	var testARepeated512 [512]byte
 	var testARepeated512 [512]byte
@@ -84,6 +94,11 @@ type TestStrucFlex struct {
 	Ui64array      [4]uint64
 	Ui64array      [4]uint64
 	Ui64slicearray []*[4]uint64
 	Ui64slicearray []*[4]uint64
 
 
+	// make this a ptr, so that it could be set or not.
+	// for comparison (e.g. with msgp), give it a struct tag (so it is not inlined),
+	// make this one omitempty (so it is excluded if nil).
+	*AnonInTestStrucIntf `json:",omitempty"`
+
 	//M map[interface{}]interface{}  `json:"-",bson:"-"`
 	//M map[interface{}]interface{}  `json:"-",bson:"-"`
 	Mtsptr     map[string]*TestStrucFlex
 	Mtsptr     map[string]*TestStrucFlex
 	Mts        map[string]TestStrucFlex
 	Mts        map[string]TestStrucFlex
@@ -140,6 +155,17 @@ func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool)
 
 
 	ts.Ui64slicearray = []*[4]uint64{&ts.Ui64array, &ts.Ui64array}
 	ts.Ui64slicearray = []*[4]uint64{&ts.Ui64array, &ts.Ui64array}
 
 
+	if useInterface {
+		ts.AnonInTestStrucIntf = &AnonInTestStrucIntf{
+			Islice: []interface{}{strRpt(n, "true"), true, strRpt(n, "no"), false, uint64(288), float64(0.4)},
+			Ms: map[string]interface{}{
+				strRpt(n, "true"):     strRpt(n, "true"),
+				strRpt(n, "int64(9)"): false,
+			},
+			T: testStrucTime,
+		}
+	}
+
 	populateTestStrucCommon(&ts.TestStrucCommon, n, bench, useInterface, useStringKeyOnly)
 	populateTestStrucCommon(&ts.TestStrucCommon, n, bench, useInterface, useStringKeyOnly)
 	if depth > 0 {
 	if depth > 0 {
 		depth--
 		depth--

+ 0 - 26
codec/values_test.go

@@ -18,7 +18,6 @@ package codec
 import (
 import (
 	"math"
 	"math"
 	"strings"
 	"strings"
-	"time"
 )
 )
 
 
 type wrapSliceUint64 []uint64
 type wrapSliceUint64 []uint64
@@ -56,13 +55,6 @@ type AnonInTestStruc struct {
 	AMSU16E     map[string]uint16
 	AMSU16E     map[string]uint16
 }
 }
 
 
-type AnonInTestStrucIntf struct {
-	Islice []interface{}
-	Ms     map[string]interface{}
-	Nintf  interface{} //don't set this, so we can test for nil
-	T      time.Time
-}
-
 type testSimpleFields struct {
 type testSimpleFields struct {
 	S string
 	S string
 
 
@@ -154,11 +146,6 @@ type TestStrucCommon struct {
 
 
 	NotAnon AnonInTestStruc
 	NotAnon AnonInTestStruc
 
 
-	// make this a ptr, so that it could be set or not.
-	// for comparison (e.g. with msgp), give it a struct tag (so it is not inlined),
-	// make this one omitempty (so it is excluded if nil).
-	*AnonInTestStrucIntf `json:",omitempty"`
-
 	// R          Raw // Testing Raw must be explicitly turned on, so use standalone test
 	// R          Raw // Testing Raw must be explicitly turned on, so use standalone test
 	// Rext RawExt // Testing RawExt is tricky, so use standalone test
 	// Rext RawExt // Testing RawExt is tricky, so use standalone test
 
 
@@ -178,8 +165,6 @@ type TestStruc struct {
 	Nteststruc *TestStruc
 	Nteststruc *TestStruc
 }
 }
 
 
-var testStrucTime = time.Date(2012, 2, 2, 2, 2, 2, 2000, time.UTC).UTC()
-
 func populateTestStrucCommon(ts *TestStrucCommon, n int, bench, useInterface, useStringKeyOnly bool) {
 func populateTestStrucCommon(ts *TestStrucCommon, n int, bench, useInterface, useStringKeyOnly bool) {
 	var i64a, i64b, i64c, i64d int64 = 64, 6464, 646464, 64646464
 	var i64a, i64b, i64c, i64d int64 = 64, 6464, 646464, 64646464
 
 
@@ -373,17 +358,6 @@ func populateTestStrucCommon(ts *TestStrucCommon, n int, bench, useInterface, us
 		ts.Simplef.Ui64 = ts.Ui64
 		ts.Simplef.Ui64 = ts.Ui64
 	}
 	}
 
 
-	if useInterface {
-		ts.AnonInTestStrucIntf = &AnonInTestStrucIntf{
-			Islice: []interface{}{strRpt(n, "true"), true, strRpt(n, "no"), false, uint64(288), float64(0.4)},
-			Ms: map[string]interface{}{
-				strRpt(n, "true"):     strRpt(n, "true"),
-				strRpt(n, "int64(9)"): false,
-			},
-			T: testStrucTime,
-		}
-	}
-
 	//For benchmarks, some things will not work.
 	//For benchmarks, some things will not work.
 	if !bench {
 	if !bench {
 		//json and bson require string keys in maps
 		//json and bson require string keys in maps