Sfoglia il codice sorgente

codec: test: move types and fields into values_test.go

- move the custom types wrapBytes, wrapUint8, etc into the top-level
  so it is tested against codecgen, etc.
Ugorji Nwoke 8 anni fa
parent
commit
b6896933d9
2 ha cambiato i file con 36 aggiunte e 5 eliminazioni
  1. 0 5
      codec/values_flex_test.go
  2. 36 0
      codec/values_test.go

+ 0 - 5
codec/values_flex_test.go

@@ -7,14 +7,10 @@ package codec
 
 // This file contains values used by tests and benchmarks.
 
-type testInt64 int64
-
 type TestStrucFlex struct {
 	_struct struct{} `codec:",omitempty"` //set omitempty for every field
 	testStrucCommon
 
-	Ci64 testInt64 // added here, so we can execute the extension paths
-
 	Mis     map[int]string
 	Mbu64   map[bool]struct{}
 	Miwu64s map[int]wrapUint64Slice
@@ -32,7 +28,6 @@ type TestStrucFlex struct {
 
 func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStrucFlex) {
 	ts = &TestStrucFlex{
-		Ci64: -22,
 		Miwu64s: map[int]wrapUint64Slice{
 			5: []wrapUint64{1, 2, 3, 4, 5},
 			3: []wrapUint64{1, 2, 3},

+ 36 - 0
codec/values_test.go

@@ -10,6 +10,7 @@ package codec
 // so we only use maps with string keys here.
 
 import (
+	"bytes"
 	"math"
 	"strings"
 	"time"
@@ -17,10 +18,14 @@ import (
 
 type wrapSliceUint64 []uint64
 type wrapSliceString []string
+type wrapUint8 uint8
+type wrapInt64 int64
 type wrapUint64 uint64
 type wrapString string
 type wrapUint64Slice []wrapUint64
 type wrapStringSlice []wrapString
+type wrapBytes []uint8
+type wrapBytesSlice []wrapBytes
 
 type stringUint64T struct {
 	S string
@@ -157,6 +162,13 @@ type testStrucCommon struct {
 	// make this one omitempty (so it is excluded if nil).
 	*AnonInTestStrucIntf `codec:",omitempty"`
 
+	Ci64       wrapInt64
+	Swrapbytes []wrapBytes
+	Swrapuint8 []wrapUint8
+
+	// R          Raw // Testing Raw must be explicitly turned on, so use standalone test
+	// Rext RawExt // Testing RawExt is tricky, so use standalone test
+
 	Nmap   map[string]bool //don't set this, so we can test for nil
 	Nslice []byte          //don't set this, so we can test for nil
 	Nint64 *int64          //don't set this, so we can test for nil
@@ -343,6 +355,25 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 		WrapSliceInt64:  []uint64{4, 16, 64, 256},
 		WrapSliceString: []string{strRpt(n, "4"), strRpt(n, "16"), strRpt(n, "64"), strRpt(n, "256")},
 
+		Ci64: -22,
+		Swrapbytes: []wrapBytes{ // lengths of 1, 2, 4, 8, 16, 32, 64, 128, 256,
+			wstrRpt(1, "A"),
+			wstrRpt(2, "A"),
+			wstrRpt(4, "A"),
+			wstrRpt(8, "A"),
+			wstrRpt(16, "A"),
+			wstrRpt(32, "A"),
+			wstrRpt(64, "A"),
+			wstrRpt(128, "A"),
+			wstrRpt(256, "A"),
+			wstrRpt(512, "A"),
+		},
+		Swrapuint8: []wrapUint8{
+			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+		},
+		// R: Raw([]byte("goodbye")),
+		// Rext: RawExt{ 120, []byte("hello"), }, // TODO: don't set this - it's hard to test
+
 		// DecodeNaked bombs here, because the stringUint64T is decoded as a map,
 		// and a map cannot be the key type of a map.
 		// Thus, don't initialize this here.
@@ -352,6 +383,7 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 		// },
 
 		// make Simplef same as top-level
+		// TODO: should this have slightly different values???
 		Simplef: testSimpleFields{
 			S: strRpt(n, `some really really cool names that are nigerian and american like "ugorji melody nwoke" - get it? `),
 
@@ -450,3 +482,7 @@ func newTestStruc(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts
 func strRpt(n int, s string) string {
 	return strings.Repeat(s, n)
 }
+
+func wstrRpt(n int, s string) wrapBytes {
+	return wrapBytes(bytes.Repeat([]byte(s), n))
+}