Dep helper (#2151)

* Add dep task to update go dependencies

* Update go dependencies
This commit is contained in:
Manuel Alejandro de Brito Fontes 2018-09-29 19:47:07 -03:00 committed by Miek Gieben
parent 8f8b81f56b
commit 0e8977761d
764 changed files with 172 additions and 267451 deletions

View file

@ -1,230 +0,0 @@
// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
package codec
import (
"bufio"
"bytes"
"encoding/hex"
"math"
"os"
"regexp"
"strings"
"testing"
)
func TestCborIndefiniteLength(t *testing.T) {
oldMapType := testCborH.MapType
defer func() {
testCborH.MapType = oldMapType
}()
testCborH.MapType = testMapStrIntfTyp
// var (
// M1 map[string][]byte
// M2 map[uint64]bool
// L1 []interface{}
// S1 []string
// B1 []byte
// )
var v, vv interface{}
// define it (v), encode it using indefinite lengths, decode it (vv), compare v to vv
v = map[string]interface{}{
"one-byte-key": []byte{1, 2, 3, 4, 5, 6},
"two-string-key": "two-value",
"three-list-key": []interface{}{true, false, uint64(1), int64(-1)},
}
var buf bytes.Buffer
// buf.Reset()
e := NewEncoder(&buf, testCborH)
buf.WriteByte(cborBdIndefiniteMap)
//----
buf.WriteByte(cborBdIndefiniteString)
e.MustEncode("one-")
e.MustEncode("byte-")
e.MustEncode("key")
buf.WriteByte(cborBdBreak)
buf.WriteByte(cborBdIndefiniteBytes)
e.MustEncode([]byte{1, 2, 3})
e.MustEncode([]byte{4, 5, 6})
buf.WriteByte(cborBdBreak)
//----
buf.WriteByte(cborBdIndefiniteString)
e.MustEncode("two-")
e.MustEncode("string-")
e.MustEncode("key")
buf.WriteByte(cborBdBreak)
buf.WriteByte(cborBdIndefiniteString)
e.MustEncode([]byte("two-")) // encode as bytes, to check robustness of code
e.MustEncode([]byte("value"))
buf.WriteByte(cborBdBreak)
//----
buf.WriteByte(cborBdIndefiniteString)
e.MustEncode("three-")
e.MustEncode("list-")
e.MustEncode("key")
buf.WriteByte(cborBdBreak)
buf.WriteByte(cborBdIndefiniteArray)
e.MustEncode(true)
e.MustEncode(false)
e.MustEncode(uint64(1))
e.MustEncode(int64(-1))
buf.WriteByte(cborBdBreak)
buf.WriteByte(cborBdBreak) // close map
NewDecoderBytes(buf.Bytes(), testCborH).MustDecode(&vv)
if err := deepEqual(v, vv); err != nil {
logT(t, "-------- Before and After marshal do not match: Error: %v", err)
logT(t, " ....... GOLDEN: (%T) %#v", v, v)
logT(t, " ....... DECODED: (%T) %#v", vv, vv)
failT(t)
}
}
type testCborGolden struct {
Base64 string `codec:"cbor"`
Hex string `codec:"hex"`
Roundtrip bool `codec:"roundtrip"`
Decoded interface{} `codec:"decoded"`
Diagnostic string `codec:"diagnostic"`
Skip bool `codec:"skip"`
}
// Some tests are skipped because they include numbers outside the range of int64/uint64
func TestCborGoldens(t *testing.T) {
oldMapType := testCborH.MapType
defer func() {
testCborH.MapType = oldMapType
}()
testCborH.MapType = testMapStrIntfTyp
// decode test-cbor-goldens.json into a list of []*testCborGolden
// for each one,
// - decode hex into []byte bs
// - decode bs into interface{} v
// - compare both using deepequal
// - for any miss, record it
var gs []*testCborGolden
f, err := os.Open("test-cbor-goldens.json")
if err != nil {
logT(t, "error opening test-cbor-goldens.json: %v", err)
failT(t)
}
defer f.Close()
jh := new(JsonHandle)
jh.MapType = testMapStrIntfTyp
// d := NewDecoder(f, jh)
d := NewDecoder(bufio.NewReader(f), jh)
// err = d.Decode(&gs)
d.MustDecode(&gs)
if err != nil {
logT(t, "error json decoding test-cbor-goldens.json: %v", err)
failT(t)
}
tagregex := regexp.MustCompile(`[\d]+\(.+?\)`)
hexregex := regexp.MustCompile(`h'([0-9a-fA-F]*)'`)
for i, g := range gs {
// fmt.Printf("%v, skip: %v, isTag: %v, %s\n", i, g.Skip, tagregex.MatchString(g.Diagnostic), g.Diagnostic)
// skip tags or simple or those with prefix, as we can't verify them.
if g.Skip || strings.HasPrefix(g.Diagnostic, "simple(") || tagregex.MatchString(g.Diagnostic) {
// fmt.Printf("%v: skipped\n", i)
logT(t, "[%v] skipping because skip=true OR unsupported simple value or Tag Value", i)
continue
}
// println("++++++++++++", i, "g.Diagnostic", g.Diagnostic)
if hexregex.MatchString(g.Diagnostic) {
// println(i, "g.Diagnostic matched hex")
if s2 := g.Diagnostic[2 : len(g.Diagnostic)-1]; s2 == "" {
g.Decoded = zeroByteSlice
} else if bs2, err2 := hex.DecodeString(s2); err2 == nil {
g.Decoded = bs2
}
// fmt.Printf("%v: hex: %v\n", i, g.Decoded)
}
bs, err := hex.DecodeString(g.Hex)
if err != nil {
logT(t, "[%v] error hex decoding %s [%v]: %v", i, g.Hex, err)
failT(t)
}
var v interface{}
NewDecoderBytes(bs, testCborH).MustDecode(&v)
if _, ok := v.(RawExt); ok {
continue
}
// check the diagnostics to compare
switch g.Diagnostic {
case "Infinity":
b := math.IsInf(v.(float64), 1)
testCborError(t, i, math.Inf(1), v, nil, &b)
case "-Infinity":
b := math.IsInf(v.(float64), -1)
testCborError(t, i, math.Inf(-1), v, nil, &b)
case "NaN":
// println(i, "checking NaN")
b := math.IsNaN(v.(float64))
testCborError(t, i, math.NaN(), v, nil, &b)
case "undefined":
b := v == nil
testCborError(t, i, nil, v, nil, &b)
default:
v0 := g.Decoded
// testCborCoerceJsonNumber(reflect.ValueOf(&v0))
testCborError(t, i, v0, v, deepEqual(v0, v), nil)
}
}
}
func testCborError(t *testing.T, i int, v0, v1 interface{}, err error, equal *bool) {
if err == nil && equal == nil {
// fmt.Printf("%v testCborError passed (err and equal nil)\n", i)
return
}
if err != nil {
logT(t, "[%v] deepEqual error: %v", i, err)
logT(t, " ....... GOLDEN: (%T) %#v", v0, v0)
logT(t, " ....... DECODED: (%T) %#v", v1, v1)
failT(t)
}
if equal != nil && !*equal {
logT(t, "[%v] values not equal", i)
logT(t, " ....... GOLDEN: (%T) %#v", v0, v0)
logT(t, " ....... DECODED: (%T) %#v", v1, v1)
failT(t)
}
// fmt.Printf("%v testCborError passed (checks passed)\n", i)
}
func TestCborHalfFloat(t *testing.T) {
m := map[uint16]float64{
// using examples from
// https://en.wikipedia.org/wiki/Half-precision_floating-point_format
0x3c00: 1,
0x3c01: 1 + math.Pow(2, -10),
0xc000: -2,
0x7bff: 65504,
0x0400: math.Pow(2, -14),
0x03ff: math.Pow(2, -14) - math.Pow(2, -24),
0x0001: math.Pow(2, -24),
0x0000: 0,
0x8000: -0.0,
}
var ba [3]byte
ba[0] = cborBdFloat16
var res float64
for k, v := range m {
res = 0
bigen.PutUint16(ba[1:], k)
testUnmarshalErr(&res, ba[:3], testCborH, t, "-")
if res == v {
logT(t, "equal floats: from %x %b, %v", k, k, v)
} else {
failT(t, "unequal floats: from %x %b, %v != %v", k, k, res, v)
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,54 +0,0 @@
// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
package codec
// All non-std package dependencies related to testing live in this file,
// so porting to different environment is easy (just update functions).
import (
"errors"
"reflect"
)
// --- these functions are used by both benchmarks and tests
func deepEqual(v1, v2 interface{}) (err error) {
if !reflect.DeepEqual(v1, v2) {
err = errors.New("Not Match")
}
return
}
func approxDataSize(rv reflect.Value) (sum int) {
switch rk := rv.Kind(); rk {
case reflect.Invalid:
case reflect.Ptr, reflect.Interface:
sum += int(rv.Type().Size())
sum += approxDataSize(rv.Elem())
case reflect.Slice:
sum += int(rv.Type().Size())
for j := 0; j < rv.Len(); j++ {
sum += approxDataSize(rv.Index(j))
}
case reflect.String:
sum += int(rv.Type().Size())
sum += rv.Len()
case reflect.Map:
sum += int(rv.Type().Size())
for _, mk := range rv.MapKeys() {
sum += approxDataSize(mk)
sum += approxDataSize(rv.MapIndex(mk))
}
case reflect.Struct:
//struct size already includes the full data size.
//sum += int(rv.Type().Size())
for j := 0; j < rv.NumField(); j++ {
sum += approxDataSize(rv.Field(j))
}
default:
//pure value types
sum += int(rv.Type().Size())
}
return
}

File diff suppressed because it is too large Load diff

View file

@ -1,658 +0,0 @@
// +build !notfastpath
// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
// Code generated from mammoth2-test.go.tmpl - DO NOT EDIT.
package codec
// Increase codecoverage by covering all the codecgen paths, in fast-path and gen-helper.go....
//
// Add:
// - test file for creating a mammoth generated file as _mammoth_generated.go
// - generate a second mammoth files in a different file: mammoth2_generated_test.go
// - mammoth-test.go.tmpl will do this
// - run codecgen on it, into mammoth2_codecgen_generated_test.go (no build tags)
// - as part of TestMammoth, run it also
// - this will cover all the codecgen, gen-helper, etc in one full run
// - check in mammoth* files into github also
// - then
//
// Now, add some types:
// - some that implement BinaryMarshal, TextMarshal, JSONMarshal, and one that implements none of it
// - create a wrapper type that includes TestMammoth2, with it in slices, and maps, and the custom types
// - this wrapper object is what we work encode/decode (so that the codecgen methods are called)
// import "encoding/binary"
import "fmt"
type TestMammoth2 struct {
FIntf interface{}
FptrIntf *interface{}
FString string
FptrString *string
FFloat32 float32
FptrFloat32 *float32
FFloat64 float64
FptrFloat64 *float64
FUint uint
FptrUint *uint
FUint8 uint8
FptrUint8 *uint8
FUint16 uint16
FptrUint16 *uint16
FUint32 uint32
FptrUint32 *uint32
FUint64 uint64
FptrUint64 *uint64
FUintptr uintptr
FptrUintptr *uintptr
FInt int
FptrInt *int
FInt8 int8
FptrInt8 *int8
FInt16 int16
FptrInt16 *int16
FInt32 int32
FptrInt32 *int32
FInt64 int64
FptrInt64 *int64
FBool bool
FptrBool *bool
FSliceIntf []interface{}
FptrSliceIntf *[]interface{}
FSliceString []string
FptrSliceString *[]string
FSliceFloat32 []float32
FptrSliceFloat32 *[]float32
FSliceFloat64 []float64
FptrSliceFloat64 *[]float64
FSliceUint []uint
FptrSliceUint *[]uint
FSliceUint8 []uint8
FptrSliceUint8 *[]uint8
FSliceUint16 []uint16
FptrSliceUint16 *[]uint16
FSliceUint32 []uint32
FptrSliceUint32 *[]uint32
FSliceUint64 []uint64
FptrSliceUint64 *[]uint64
FSliceUintptr []uintptr
FptrSliceUintptr *[]uintptr
FSliceInt []int
FptrSliceInt *[]int
FSliceInt8 []int8
FptrSliceInt8 *[]int8
FSliceInt16 []int16
FptrSliceInt16 *[]int16
FSliceInt32 []int32
FptrSliceInt32 *[]int32
FSliceInt64 []int64
FptrSliceInt64 *[]int64
FSliceBool []bool
FptrSliceBool *[]bool
FMapIntfIntf map[interface{}]interface{}
FptrMapIntfIntf *map[interface{}]interface{}
FMapIntfString map[interface{}]string
FptrMapIntfString *map[interface{}]string
FMapIntfUint map[interface{}]uint
FptrMapIntfUint *map[interface{}]uint
FMapIntfUint8 map[interface{}]uint8
FptrMapIntfUint8 *map[interface{}]uint8
FMapIntfUint16 map[interface{}]uint16
FptrMapIntfUint16 *map[interface{}]uint16
FMapIntfUint32 map[interface{}]uint32
FptrMapIntfUint32 *map[interface{}]uint32
FMapIntfUint64 map[interface{}]uint64
FptrMapIntfUint64 *map[interface{}]uint64
FMapIntfUintptr map[interface{}]uintptr
FptrMapIntfUintptr *map[interface{}]uintptr
FMapIntfInt map[interface{}]int
FptrMapIntfInt *map[interface{}]int
FMapIntfInt8 map[interface{}]int8
FptrMapIntfInt8 *map[interface{}]int8
FMapIntfInt16 map[interface{}]int16
FptrMapIntfInt16 *map[interface{}]int16
FMapIntfInt32 map[interface{}]int32
FptrMapIntfInt32 *map[interface{}]int32
FMapIntfInt64 map[interface{}]int64
FptrMapIntfInt64 *map[interface{}]int64
FMapIntfFloat32 map[interface{}]float32
FptrMapIntfFloat32 *map[interface{}]float32
FMapIntfFloat64 map[interface{}]float64
FptrMapIntfFloat64 *map[interface{}]float64
FMapIntfBool map[interface{}]bool
FptrMapIntfBool *map[interface{}]bool
FMapStringIntf map[string]interface{}
FptrMapStringIntf *map[string]interface{}
FMapStringString map[string]string
FptrMapStringString *map[string]string
FMapStringUint map[string]uint
FptrMapStringUint *map[string]uint
FMapStringUint8 map[string]uint8
FptrMapStringUint8 *map[string]uint8
FMapStringUint16 map[string]uint16
FptrMapStringUint16 *map[string]uint16
FMapStringUint32 map[string]uint32
FptrMapStringUint32 *map[string]uint32
FMapStringUint64 map[string]uint64
FptrMapStringUint64 *map[string]uint64
FMapStringUintptr map[string]uintptr
FptrMapStringUintptr *map[string]uintptr
FMapStringInt map[string]int
FptrMapStringInt *map[string]int
FMapStringInt8 map[string]int8
FptrMapStringInt8 *map[string]int8
FMapStringInt16 map[string]int16
FptrMapStringInt16 *map[string]int16
FMapStringInt32 map[string]int32
FptrMapStringInt32 *map[string]int32
FMapStringInt64 map[string]int64
FptrMapStringInt64 *map[string]int64
FMapStringFloat32 map[string]float32
FptrMapStringFloat32 *map[string]float32
FMapStringFloat64 map[string]float64
FptrMapStringFloat64 *map[string]float64
FMapStringBool map[string]bool
FptrMapStringBool *map[string]bool
FMapFloat32Intf map[float32]interface{}
FptrMapFloat32Intf *map[float32]interface{}
FMapFloat32String map[float32]string
FptrMapFloat32String *map[float32]string
FMapFloat32Uint map[float32]uint
FptrMapFloat32Uint *map[float32]uint
FMapFloat32Uint8 map[float32]uint8
FptrMapFloat32Uint8 *map[float32]uint8
FMapFloat32Uint16 map[float32]uint16
FptrMapFloat32Uint16 *map[float32]uint16
FMapFloat32Uint32 map[float32]uint32
FptrMapFloat32Uint32 *map[float32]uint32
FMapFloat32Uint64 map[float32]uint64
FptrMapFloat32Uint64 *map[float32]uint64
FMapFloat32Uintptr map[float32]uintptr
FptrMapFloat32Uintptr *map[float32]uintptr
FMapFloat32Int map[float32]int
FptrMapFloat32Int *map[float32]int
FMapFloat32Int8 map[float32]int8
FptrMapFloat32Int8 *map[float32]int8
FMapFloat32Int16 map[float32]int16
FptrMapFloat32Int16 *map[float32]int16
FMapFloat32Int32 map[float32]int32
FptrMapFloat32Int32 *map[float32]int32
FMapFloat32Int64 map[float32]int64
FptrMapFloat32Int64 *map[float32]int64
FMapFloat32Float32 map[float32]float32
FptrMapFloat32Float32 *map[float32]float32
FMapFloat32Float64 map[float32]float64
FptrMapFloat32Float64 *map[float32]float64
FMapFloat32Bool map[float32]bool
FptrMapFloat32Bool *map[float32]bool
FMapFloat64Intf map[float64]interface{}
FptrMapFloat64Intf *map[float64]interface{}
FMapFloat64String map[float64]string
FptrMapFloat64String *map[float64]string
FMapFloat64Uint map[float64]uint
FptrMapFloat64Uint *map[float64]uint
FMapFloat64Uint8 map[float64]uint8
FptrMapFloat64Uint8 *map[float64]uint8
FMapFloat64Uint16 map[float64]uint16
FptrMapFloat64Uint16 *map[float64]uint16
FMapFloat64Uint32 map[float64]uint32
FptrMapFloat64Uint32 *map[float64]uint32
FMapFloat64Uint64 map[float64]uint64
FptrMapFloat64Uint64 *map[float64]uint64
FMapFloat64Uintptr map[float64]uintptr
FptrMapFloat64Uintptr *map[float64]uintptr
FMapFloat64Int map[float64]int
FptrMapFloat64Int *map[float64]int
FMapFloat64Int8 map[float64]int8
FptrMapFloat64Int8 *map[float64]int8
FMapFloat64Int16 map[float64]int16
FptrMapFloat64Int16 *map[float64]int16
FMapFloat64Int32 map[float64]int32
FptrMapFloat64Int32 *map[float64]int32
FMapFloat64Int64 map[float64]int64
FptrMapFloat64Int64 *map[float64]int64
FMapFloat64Float32 map[float64]float32
FptrMapFloat64Float32 *map[float64]float32
FMapFloat64Float64 map[float64]float64
FptrMapFloat64Float64 *map[float64]float64
FMapFloat64Bool map[float64]bool
FptrMapFloat64Bool *map[float64]bool
FMapUintIntf map[uint]interface{}
FptrMapUintIntf *map[uint]interface{}
FMapUintString map[uint]string
FptrMapUintString *map[uint]string
FMapUintUint map[uint]uint
FptrMapUintUint *map[uint]uint
FMapUintUint8 map[uint]uint8
FptrMapUintUint8 *map[uint]uint8
FMapUintUint16 map[uint]uint16
FptrMapUintUint16 *map[uint]uint16
FMapUintUint32 map[uint]uint32
FptrMapUintUint32 *map[uint]uint32
FMapUintUint64 map[uint]uint64
FptrMapUintUint64 *map[uint]uint64
FMapUintUintptr map[uint]uintptr
FptrMapUintUintptr *map[uint]uintptr
FMapUintInt map[uint]int
FptrMapUintInt *map[uint]int
FMapUintInt8 map[uint]int8
FptrMapUintInt8 *map[uint]int8
FMapUintInt16 map[uint]int16
FptrMapUintInt16 *map[uint]int16
FMapUintInt32 map[uint]int32
FptrMapUintInt32 *map[uint]int32
FMapUintInt64 map[uint]int64
FptrMapUintInt64 *map[uint]int64
FMapUintFloat32 map[uint]float32
FptrMapUintFloat32 *map[uint]float32
FMapUintFloat64 map[uint]float64
FptrMapUintFloat64 *map[uint]float64
FMapUintBool map[uint]bool
FptrMapUintBool *map[uint]bool
FMapUint8Intf map[uint8]interface{}
FptrMapUint8Intf *map[uint8]interface{}
FMapUint8String map[uint8]string
FptrMapUint8String *map[uint8]string
FMapUint8Uint map[uint8]uint
FptrMapUint8Uint *map[uint8]uint
FMapUint8Uint8 map[uint8]uint8
FptrMapUint8Uint8 *map[uint8]uint8
FMapUint8Uint16 map[uint8]uint16
FptrMapUint8Uint16 *map[uint8]uint16
FMapUint8Uint32 map[uint8]uint32
FptrMapUint8Uint32 *map[uint8]uint32
FMapUint8Uint64 map[uint8]uint64
FptrMapUint8Uint64 *map[uint8]uint64
FMapUint8Uintptr map[uint8]uintptr
FptrMapUint8Uintptr *map[uint8]uintptr
FMapUint8Int map[uint8]int
FptrMapUint8Int *map[uint8]int
FMapUint8Int8 map[uint8]int8
FptrMapUint8Int8 *map[uint8]int8
FMapUint8Int16 map[uint8]int16
FptrMapUint8Int16 *map[uint8]int16
FMapUint8Int32 map[uint8]int32
FptrMapUint8Int32 *map[uint8]int32
FMapUint8Int64 map[uint8]int64
FptrMapUint8Int64 *map[uint8]int64
FMapUint8Float32 map[uint8]float32
FptrMapUint8Float32 *map[uint8]float32
FMapUint8Float64 map[uint8]float64
FptrMapUint8Float64 *map[uint8]float64
FMapUint8Bool map[uint8]bool
FptrMapUint8Bool *map[uint8]bool
FMapUint16Intf map[uint16]interface{}
FptrMapUint16Intf *map[uint16]interface{}
FMapUint16String map[uint16]string
FptrMapUint16String *map[uint16]string
FMapUint16Uint map[uint16]uint
FptrMapUint16Uint *map[uint16]uint
FMapUint16Uint8 map[uint16]uint8
FptrMapUint16Uint8 *map[uint16]uint8
FMapUint16Uint16 map[uint16]uint16
FptrMapUint16Uint16 *map[uint16]uint16
FMapUint16Uint32 map[uint16]uint32
FptrMapUint16Uint32 *map[uint16]uint32
FMapUint16Uint64 map[uint16]uint64
FptrMapUint16Uint64 *map[uint16]uint64
FMapUint16Uintptr map[uint16]uintptr
FptrMapUint16Uintptr *map[uint16]uintptr
FMapUint16Int map[uint16]int
FptrMapUint16Int *map[uint16]int
FMapUint16Int8 map[uint16]int8
FptrMapUint16Int8 *map[uint16]int8
FMapUint16Int16 map[uint16]int16
FptrMapUint16Int16 *map[uint16]int16
FMapUint16Int32 map[uint16]int32
FptrMapUint16Int32 *map[uint16]int32
FMapUint16Int64 map[uint16]int64
FptrMapUint16Int64 *map[uint16]int64
FMapUint16Float32 map[uint16]float32
FptrMapUint16Float32 *map[uint16]float32
FMapUint16Float64 map[uint16]float64
FptrMapUint16Float64 *map[uint16]float64
FMapUint16Bool map[uint16]bool
FptrMapUint16Bool *map[uint16]bool
FMapUint32Intf map[uint32]interface{}
FptrMapUint32Intf *map[uint32]interface{}
FMapUint32String map[uint32]string
FptrMapUint32String *map[uint32]string
FMapUint32Uint map[uint32]uint
FptrMapUint32Uint *map[uint32]uint
FMapUint32Uint8 map[uint32]uint8
FptrMapUint32Uint8 *map[uint32]uint8
FMapUint32Uint16 map[uint32]uint16
FptrMapUint32Uint16 *map[uint32]uint16
FMapUint32Uint32 map[uint32]uint32
FptrMapUint32Uint32 *map[uint32]uint32
FMapUint32Uint64 map[uint32]uint64
FptrMapUint32Uint64 *map[uint32]uint64
FMapUint32Uintptr map[uint32]uintptr
FptrMapUint32Uintptr *map[uint32]uintptr
FMapUint32Int map[uint32]int
FptrMapUint32Int *map[uint32]int
FMapUint32Int8 map[uint32]int8
FptrMapUint32Int8 *map[uint32]int8
FMapUint32Int16 map[uint32]int16
FptrMapUint32Int16 *map[uint32]int16
FMapUint32Int32 map[uint32]int32
FptrMapUint32Int32 *map[uint32]int32
FMapUint32Int64 map[uint32]int64
FptrMapUint32Int64 *map[uint32]int64
FMapUint32Float32 map[uint32]float32
FptrMapUint32Float32 *map[uint32]float32
FMapUint32Float64 map[uint32]float64
FptrMapUint32Float64 *map[uint32]float64
FMapUint32Bool map[uint32]bool
FptrMapUint32Bool *map[uint32]bool
FMapUint64Intf map[uint64]interface{}
FptrMapUint64Intf *map[uint64]interface{}
FMapUint64String map[uint64]string
FptrMapUint64String *map[uint64]string
FMapUint64Uint map[uint64]uint
FptrMapUint64Uint *map[uint64]uint
FMapUint64Uint8 map[uint64]uint8
FptrMapUint64Uint8 *map[uint64]uint8
FMapUint64Uint16 map[uint64]uint16
FptrMapUint64Uint16 *map[uint64]uint16
FMapUint64Uint32 map[uint64]uint32
FptrMapUint64Uint32 *map[uint64]uint32
FMapUint64Uint64 map[uint64]uint64
FptrMapUint64Uint64 *map[uint64]uint64
FMapUint64Uintptr map[uint64]uintptr
FptrMapUint64Uintptr *map[uint64]uintptr
FMapUint64Int map[uint64]int
FptrMapUint64Int *map[uint64]int
FMapUint64Int8 map[uint64]int8
FptrMapUint64Int8 *map[uint64]int8
FMapUint64Int16 map[uint64]int16
FptrMapUint64Int16 *map[uint64]int16
FMapUint64Int32 map[uint64]int32
FptrMapUint64Int32 *map[uint64]int32
FMapUint64Int64 map[uint64]int64
FptrMapUint64Int64 *map[uint64]int64
FMapUint64Float32 map[uint64]float32
FptrMapUint64Float32 *map[uint64]float32
FMapUint64Float64 map[uint64]float64
FptrMapUint64Float64 *map[uint64]float64
FMapUint64Bool map[uint64]bool
FptrMapUint64Bool *map[uint64]bool
FMapUintptrIntf map[uintptr]interface{}
FptrMapUintptrIntf *map[uintptr]interface{}
FMapUintptrString map[uintptr]string
FptrMapUintptrString *map[uintptr]string
FMapUintptrUint map[uintptr]uint
FptrMapUintptrUint *map[uintptr]uint
FMapUintptrUint8 map[uintptr]uint8
FptrMapUintptrUint8 *map[uintptr]uint8
FMapUintptrUint16 map[uintptr]uint16
FptrMapUintptrUint16 *map[uintptr]uint16
FMapUintptrUint32 map[uintptr]uint32
FptrMapUintptrUint32 *map[uintptr]uint32
FMapUintptrUint64 map[uintptr]uint64
FptrMapUintptrUint64 *map[uintptr]uint64
FMapUintptrUintptr map[uintptr]uintptr
FptrMapUintptrUintptr *map[uintptr]uintptr
FMapUintptrInt map[uintptr]int
FptrMapUintptrInt *map[uintptr]int
FMapUintptrInt8 map[uintptr]int8
FptrMapUintptrInt8 *map[uintptr]int8
FMapUintptrInt16 map[uintptr]int16
FptrMapUintptrInt16 *map[uintptr]int16
FMapUintptrInt32 map[uintptr]int32
FptrMapUintptrInt32 *map[uintptr]int32
FMapUintptrInt64 map[uintptr]int64
FptrMapUintptrInt64 *map[uintptr]int64
FMapUintptrFloat32 map[uintptr]float32
FptrMapUintptrFloat32 *map[uintptr]float32
FMapUintptrFloat64 map[uintptr]float64
FptrMapUintptrFloat64 *map[uintptr]float64
FMapUintptrBool map[uintptr]bool
FptrMapUintptrBool *map[uintptr]bool
FMapIntIntf map[int]interface{}
FptrMapIntIntf *map[int]interface{}
FMapIntString map[int]string
FptrMapIntString *map[int]string
FMapIntUint map[int]uint
FptrMapIntUint *map[int]uint
FMapIntUint8 map[int]uint8
FptrMapIntUint8 *map[int]uint8
FMapIntUint16 map[int]uint16
FptrMapIntUint16 *map[int]uint16
FMapIntUint32 map[int]uint32
FptrMapIntUint32 *map[int]uint32
FMapIntUint64 map[int]uint64
FptrMapIntUint64 *map[int]uint64
FMapIntUintptr map[int]uintptr
FptrMapIntUintptr *map[int]uintptr
FMapIntInt map[int]int
FptrMapIntInt *map[int]int
FMapIntInt8 map[int]int8
FptrMapIntInt8 *map[int]int8
FMapIntInt16 map[int]int16
FptrMapIntInt16 *map[int]int16
FMapIntInt32 map[int]int32
FptrMapIntInt32 *map[int]int32
FMapIntInt64 map[int]int64
FptrMapIntInt64 *map[int]int64
FMapIntFloat32 map[int]float32
FptrMapIntFloat32 *map[int]float32
FMapIntFloat64 map[int]float64
FptrMapIntFloat64 *map[int]float64
FMapIntBool map[int]bool
FptrMapIntBool *map[int]bool
FMapInt8Intf map[int8]interface{}
FptrMapInt8Intf *map[int8]interface{}
FMapInt8String map[int8]string
FptrMapInt8String *map[int8]string
FMapInt8Uint map[int8]uint
FptrMapInt8Uint *map[int8]uint
FMapInt8Uint8 map[int8]uint8
FptrMapInt8Uint8 *map[int8]uint8
FMapInt8Uint16 map[int8]uint16
FptrMapInt8Uint16 *map[int8]uint16
FMapInt8Uint32 map[int8]uint32
FptrMapInt8Uint32 *map[int8]uint32
FMapInt8Uint64 map[int8]uint64
FptrMapInt8Uint64 *map[int8]uint64
FMapInt8Uintptr map[int8]uintptr
FptrMapInt8Uintptr *map[int8]uintptr
FMapInt8Int map[int8]int
FptrMapInt8Int *map[int8]int
FMapInt8Int8 map[int8]int8
FptrMapInt8Int8 *map[int8]int8
FMapInt8Int16 map[int8]int16
FptrMapInt8Int16 *map[int8]int16
FMapInt8Int32 map[int8]int32
FptrMapInt8Int32 *map[int8]int32
FMapInt8Int64 map[int8]int64
FptrMapInt8Int64 *map[int8]int64
FMapInt8Float32 map[int8]float32
FptrMapInt8Float32 *map[int8]float32
FMapInt8Float64 map[int8]float64
FptrMapInt8Float64 *map[int8]float64
FMapInt8Bool map[int8]bool
FptrMapInt8Bool *map[int8]bool
FMapInt16Intf map[int16]interface{}
FptrMapInt16Intf *map[int16]interface{}
FMapInt16String map[int16]string
FptrMapInt16String *map[int16]string
FMapInt16Uint map[int16]uint
FptrMapInt16Uint *map[int16]uint
FMapInt16Uint8 map[int16]uint8
FptrMapInt16Uint8 *map[int16]uint8
FMapInt16Uint16 map[int16]uint16
FptrMapInt16Uint16 *map[int16]uint16
FMapInt16Uint32 map[int16]uint32
FptrMapInt16Uint32 *map[int16]uint32
FMapInt16Uint64 map[int16]uint64
FptrMapInt16Uint64 *map[int16]uint64
FMapInt16Uintptr map[int16]uintptr
FptrMapInt16Uintptr *map[int16]uintptr
FMapInt16Int map[int16]int
FptrMapInt16Int *map[int16]int
FMapInt16Int8 map[int16]int8
FptrMapInt16Int8 *map[int16]int8
FMapInt16Int16 map[int16]int16
FptrMapInt16Int16 *map[int16]int16
FMapInt16Int32 map[int16]int32
FptrMapInt16Int32 *map[int16]int32
FMapInt16Int64 map[int16]int64
FptrMapInt16Int64 *map[int16]int64
FMapInt16Float32 map[int16]float32
FptrMapInt16Float32 *map[int16]float32
FMapInt16Float64 map[int16]float64
FptrMapInt16Float64 *map[int16]float64
FMapInt16Bool map[int16]bool
FptrMapInt16Bool *map[int16]bool
FMapInt32Intf map[int32]interface{}
FptrMapInt32Intf *map[int32]interface{}
FMapInt32String map[int32]string
FptrMapInt32String *map[int32]string
FMapInt32Uint map[int32]uint
FptrMapInt32Uint *map[int32]uint
FMapInt32Uint8 map[int32]uint8
FptrMapInt32Uint8 *map[int32]uint8
FMapInt32Uint16 map[int32]uint16
FptrMapInt32Uint16 *map[int32]uint16
FMapInt32Uint32 map[int32]uint32
FptrMapInt32Uint32 *map[int32]uint32
FMapInt32Uint64 map[int32]uint64
FptrMapInt32Uint64 *map[int32]uint64
FMapInt32Uintptr map[int32]uintptr
FptrMapInt32Uintptr *map[int32]uintptr
FMapInt32Int map[int32]int
FptrMapInt32Int *map[int32]int
FMapInt32Int8 map[int32]int8
FptrMapInt32Int8 *map[int32]int8
FMapInt32Int16 map[int32]int16
FptrMapInt32Int16 *map[int32]int16
FMapInt32Int32 map[int32]int32
FptrMapInt32Int32 *map[int32]int32
FMapInt32Int64 map[int32]int64
FptrMapInt32Int64 *map[int32]int64
FMapInt32Float32 map[int32]float32
FptrMapInt32Float32 *map[int32]float32
FMapInt32Float64 map[int32]float64
FptrMapInt32Float64 *map[int32]float64
FMapInt32Bool map[int32]bool
FptrMapInt32Bool *map[int32]bool
FMapInt64Intf map[int64]interface{}
FptrMapInt64Intf *map[int64]interface{}
FMapInt64String map[int64]string
FptrMapInt64String *map[int64]string
FMapInt64Uint map[int64]uint
FptrMapInt64Uint *map[int64]uint
FMapInt64Uint8 map[int64]uint8
FptrMapInt64Uint8 *map[int64]uint8
FMapInt64Uint16 map[int64]uint16
FptrMapInt64Uint16 *map[int64]uint16
FMapInt64Uint32 map[int64]uint32
FptrMapInt64Uint32 *map[int64]uint32
FMapInt64Uint64 map[int64]uint64
FptrMapInt64Uint64 *map[int64]uint64
FMapInt64Uintptr map[int64]uintptr
FptrMapInt64Uintptr *map[int64]uintptr
FMapInt64Int map[int64]int
FptrMapInt64Int *map[int64]int
FMapInt64Int8 map[int64]int8
FptrMapInt64Int8 *map[int64]int8
FMapInt64Int16 map[int64]int16
FptrMapInt64Int16 *map[int64]int16
FMapInt64Int32 map[int64]int32
FptrMapInt64Int32 *map[int64]int32
FMapInt64Int64 map[int64]int64
FptrMapInt64Int64 *map[int64]int64
FMapInt64Float32 map[int64]float32
FptrMapInt64Float32 *map[int64]float32
FMapInt64Float64 map[int64]float64
FptrMapInt64Float64 *map[int64]float64
FMapInt64Bool map[int64]bool
FptrMapInt64Bool *map[int64]bool
FMapBoolIntf map[bool]interface{}
FptrMapBoolIntf *map[bool]interface{}
FMapBoolString map[bool]string
FptrMapBoolString *map[bool]string
FMapBoolUint map[bool]uint
FptrMapBoolUint *map[bool]uint
FMapBoolUint8 map[bool]uint8
FptrMapBoolUint8 *map[bool]uint8
FMapBoolUint16 map[bool]uint16
FptrMapBoolUint16 *map[bool]uint16
FMapBoolUint32 map[bool]uint32
FptrMapBoolUint32 *map[bool]uint32
FMapBoolUint64 map[bool]uint64
FptrMapBoolUint64 *map[bool]uint64
FMapBoolUintptr map[bool]uintptr
FptrMapBoolUintptr *map[bool]uintptr
FMapBoolInt map[bool]int
FptrMapBoolInt *map[bool]int
FMapBoolInt8 map[bool]int8
FptrMapBoolInt8 *map[bool]int8
FMapBoolInt16 map[bool]int16
FptrMapBoolInt16 *map[bool]int16
FMapBoolInt32 map[bool]int32
FptrMapBoolInt32 *map[bool]int32
FMapBoolInt64 map[bool]int64
FptrMapBoolInt64 *map[bool]int64
FMapBoolFloat32 map[bool]float32
FptrMapBoolFloat32 *map[bool]float32
FMapBoolFloat64 map[bool]float64
FptrMapBoolFloat64 *map[bool]float64
FMapBoolBool map[bool]bool
FptrMapBoolBool *map[bool]bool
}
// -----------
type testMammoth2Binary uint64
func (x testMammoth2Binary) MarshalBinary() (data []byte, err error) {
data = make([]byte, 8)
bigen.PutUint64(data, uint64(x))
return
}
func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) {
*x = testMammoth2Binary(bigen.Uint64(data))
return
}
type testMammoth2Text uint64
func (x testMammoth2Text) MarshalText() (data []byte, err error) {
data = []byte(fmt.Sprintf("%b", uint64(x)))
return
}
func (x *testMammoth2Text) UnmarshalText(data []byte) (err error) {
_, err = fmt.Sscanf(string(data), "%b", (*uint64)(x))
return
}
type testMammoth2Json uint64
func (x testMammoth2Json) MarshalJSON() (data []byte, err error) {
data = []byte(fmt.Sprintf("%v", uint64(x)))
return
}
func (x *testMammoth2Json) UnmarshalJSON(data []byte) (err error) {
_, err = fmt.Sscanf(string(data), "%v", (*uint64)(x))
return
}
type testMammoth2Basic [4]uint64
type TestMammoth2Wrapper struct {
V TestMammoth2
T testMammoth2Text
B testMammoth2Binary
J testMammoth2Json
C testMammoth2Basic
M map[testMammoth2Basic]TestMammoth2
L []TestMammoth2
A [4]int64
}

File diff suppressed because it is too large Load diff

View file

@ -1,30 +0,0 @@
// +build x
// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
package codec
// These tests are used to verify msgpack and cbor implementations against their python libraries.
// If you have the library installed, you can enable the tests back by running: go test -tags=x .
// Look at test.py for how to setup your environment.
import (
"testing"
)
func TestMsgpackPythonGenStreams(t *testing.T) {
doTestPythonGenStreams(t, "msgpack", testMsgpackH)
}
func TestCborPythonGenStreams(t *testing.T) {
doTestPythonGenStreams(t, "cbor", testCborH)
}
func TestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) {
doTestMsgpackRpcSpecGoClientToPythonSvc(t)
}
func TestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) {
doTestMsgpackRpcSpecPythonClientToGoSvc(t)
}

View file

@ -1,304 +0,0 @@
// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
package codec
// This file sets up the variables used, including testInitFns.
// Each file should add initialization that should be performed
// after flags are parsed.
//
// init is a multi-step process:
// - setup vars (handled by init functions in each file)
// - parse flags
// - setup derived vars (handled by pre-init registered functions - registered in init function)
// - post init (handled by post-init registered functions - registered in init function)
// This way, no one has to manage carefully control the initialization
// using file names, etc.
//
// Tests which require external dependencies need the -tag=x parameter.
// They should be run as:
// go test -tags=x -run=. <other parameters ...>
// Benchmarks should also take this parameter, to include the sereal, xdr, etc.
// To run against codecgen, etc, make sure you pass extra parameters.
// Example usage:
// go test "-tags=x codecgen" -bench=. <other parameters ...>
//
// To fully test everything:
// go test -tags=x -benchtime=100ms -tv -bg -bi -brw -bu -v -run=. -bench=.
// Handling flags
// codec_test.go will define a set of global flags for testing, including:
// - Use Reset
// - Use IO reader/writer (vs direct bytes)
// - Set Canonical
// - Set InternStrings
// - Use Symbols
//
// This way, we can test them all by running same set of tests with a different
// set of flags.
//
// Following this, all the benchmarks will utilize flags set by codec_test.go
// and will not redefine these "global" flags.
import (
"bytes"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"sync"
"testing"
)
// DO NOT REMOVE - replacement line for go-codec-bench import declaration tag //
type testHED struct {
H Handle
E *Encoder
D *Decoder
}
type ioReaderWrapper struct {
r io.Reader
}
func (x ioReaderWrapper) Read(p []byte) (n int, err error) {
return x.r.Read(p)
}
type ioWriterWrapper struct {
w io.Writer
}
func (x ioWriterWrapper) Write(p []byte) (n int, err error) {
return x.w.Write(p)
}
var (
// testNoopH = NoopHandle(8)
testMsgpackH = &MsgpackHandle{}
testBincH = &BincHandle{}
testSimpleH = &SimpleHandle{}
testCborH = &CborHandle{}
testJsonH = &JsonHandle{}
testHandles []Handle
testPreInitFns []func()
testPostInitFns []func()
testOnce sync.Once
testHEDs []testHED
)
// flag variables used by tests (and bench)
var (
testDepth int
testVerbose bool
testInitDebug bool
testStructToArray bool
testCanonical bool
testUseReset bool
testSkipIntf bool
testInternStr bool
testUseMust bool
testCheckCircRef bool
testUseIoEncDec int
testUseIoWrapper bool
testMaxInitLen int
testNumRepeatString int
testRpcBufsize int
)
// variables that are not flags, but which can configure the handles
var (
testEncodeOptions EncodeOptions
testDecodeOptions DecodeOptions
)
// flag variables used by bench
var (
benchDoInitBench bool
benchVerify bool
benchUnscientificRes bool = false
benchMapStringKeyOnly bool
//depth of 0 maps to ~400bytes json-encoded string, 1 maps to ~1400 bytes, etc
//For depth>1, we likely trigger stack growth for encoders, making benchmarking unreliable.
benchDepth int
benchInitDebug bool
)
func init() {
log.SetOutput(ioutil.Discard) // don't allow things log to standard out/err
testHEDs = make([]testHED, 0, 32)
testHandles = append(testHandles,
// testNoopH,
testMsgpackH, testBincH, testSimpleH,
testCborH, testJsonH)
testInitFlags()
benchInitFlags()
}
func testInitFlags() {
// delete(testDecOpts.ExtFuncs, timeTyp)
flag.IntVar(&testDepth, "tsd", 0, "Test Struc Depth")
flag.BoolVar(&testVerbose, "tv", false, "Test Verbose (no longer used - here for compatibility)")
flag.BoolVar(&testInitDebug, "tg", false, "Test Init Debug")
flag.IntVar(&testUseIoEncDec, "ti", -1, "Use IO Reader/Writer for Marshal/Unmarshal ie >= 0")
flag.BoolVar(&testUseIoWrapper, "tiw", false, "Wrap the IO Reader/Writer with a base pass-through reader/writer")
flag.BoolVar(&testStructToArray, "ts", false, "Set StructToArray option")
flag.BoolVar(&testCanonical, "tc", false, "Set Canonical option")
flag.BoolVar(&testInternStr, "te", false, "Set InternStr option")
flag.BoolVar(&testSkipIntf, "tf", false, "Skip Interfaces")
flag.BoolVar(&testUseReset, "tr", false, "Use Reset")
flag.IntVar(&testNumRepeatString, "trs", 8, "Create string variables by repeating a string N times")
flag.IntVar(&testMaxInitLen, "tx", 0, "Max Init Len")
flag.BoolVar(&testUseMust, "tm", true, "Use Must(En|De)code")
flag.BoolVar(&testCheckCircRef, "tl", false, "Use Check Circular Ref")
}
func benchInitFlags() {
flag.BoolVar(&benchMapStringKeyOnly, "bs", false, "Bench use maps with string keys only")
flag.BoolVar(&benchInitDebug, "bg", false, "Bench Debug")
flag.IntVar(&benchDepth, "bd", 1, "Bench Depth")
flag.BoolVar(&benchDoInitBench, "bi", false, "Run Bench Init")
flag.BoolVar(&benchVerify, "bv", false, "Verify Decoded Value during Benchmark")
flag.BoolVar(&benchUnscientificRes, "bu", false, "Show Unscientific Results during Benchmark")
}
func testHEDGet(h Handle) *testHED {
for i := range testHEDs {
v := &testHEDs[i]
if v.H == h {
return v
}
}
testHEDs = append(testHEDs, testHED{h, NewEncoder(nil, h), NewDecoder(nil, h)})
return &testHEDs[len(testHEDs)-1]
}
func testReinit() {
testOnce = sync.Once{}
testHEDs = nil
}
func testInitAll() {
// only parse it once.
if !flag.Parsed() {
flag.Parse()
}
for _, f := range testPreInitFns {
f()
}
for _, f := range testPostInitFns {
f()
}
}
func sTestCodecEncode(ts interface{}, bsIn []byte, fn func([]byte) *bytes.Buffer,
h Handle, bh *BasicHandle) (bs []byte, err error) {
// bs = make([]byte, 0, approxSize)
var e *Encoder
var buf *bytes.Buffer
if testUseReset {
e = testHEDGet(h).E
} else {
e = NewEncoder(nil, h)
}
var oldWriteBufferSize int
if testUseIoEncDec >= 0 {
buf = fn(bsIn)
// set the encode options for using a buffer
oldWriteBufferSize = bh.WriterBufferSize
bh.WriterBufferSize = testUseIoEncDec
if testUseIoWrapper {
e.Reset(ioWriterWrapper{buf})
} else {
e.Reset(buf)
}
} else {
bs = bsIn
e.ResetBytes(&bs)
}
if testUseMust {
e.MustEncode(ts)
} else {
err = e.Encode(ts)
}
if testUseIoEncDec >= 0 {
bs = buf.Bytes()
bh.WriterBufferSize = oldWriteBufferSize
}
return
}
func sTestCodecDecode(bs []byte, ts interface{}, h Handle, bh *BasicHandle) (err error) {
var d *Decoder
// var buf *bytes.Reader
if testUseReset {
d = testHEDGet(h).D
} else {
d = NewDecoder(nil, h)
}
var oldReadBufferSize int
if testUseIoEncDec >= 0 {
buf := bytes.NewReader(bs)
oldReadBufferSize = bh.ReaderBufferSize
bh.ReaderBufferSize = testUseIoEncDec
if testUseIoWrapper {
d.Reset(ioReaderWrapper{buf})
} else {
d.Reset(buf)
}
} else {
d.ResetBytes(bs)
}
if testUseMust {
d.MustDecode(ts)
} else {
err = d.Decode(ts)
}
if testUseIoEncDec >= 0 {
bh.ReaderBufferSize = oldReadBufferSize
}
return
}
// --- functions below are used by both benchmarks and tests
func logT(x interface{}, format string, args ...interface{}) {
if t, ok := x.(*testing.T); ok && t != nil {
t.Logf(format, args...)
} else if b, ok := x.(*testing.B); ok && b != nil {
b.Logf(format, args...)
} else { // if testing.Verbose() { // if testVerbose {
if len(format) == 0 || format[len(format)-1] != '\n' {
format = format + "\n"
}
fmt.Printf(format, args...)
}
}
// --- functions below are used only by benchmarks alone
func fnBenchmarkByteBuf(bsIn []byte) (buf *bytes.Buffer) {
// var buf bytes.Buffer
// buf.Grow(approxSize)
buf = bytes.NewBuffer(bsIn)
buf.Truncate(0)
return
}
// func benchFnCodecEncode(ts interface{}, bsIn []byte, h Handle) (bs []byte, err error) {
// return testCodecEncode(ts, bsIn, fnBenchmarkByteBuf, h)
// }
// func benchFnCodecDecode(bs []byte, ts interface{}, h Handle) (err error) {
// return testCodecDecode(bs, ts, h)
// }

View file

@ -1,208 +0,0 @@
/* // +build testing */
// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
package codec
import (
"strings"
"time"
)
const teststrucflexChanCap = 64
// This file contains values used by tests alone.
// This is where we may try out different things,
// that other engines may not support or may barf upon
// e.g. custom extensions for wrapped types, maps with non-string keys, etc.
// Some unused types just stored here
type Bbool bool
type Sstring string
type Sstructsmall struct {
A int
}
type Sstructbig struct {
A int
B bool
c string
// Sval Sstruct
Ssmallptr *Sstructsmall
Ssmall *Sstructsmall
Sptr *Sstructbig
}
type SstructbigMapBySlice struct {
_struct struct{} `codec:",toarray"`
A int
B bool
c string
// Sval Sstruct
Ssmallptr *Sstructsmall
Ssmall *Sstructsmall
Sptr *Sstructbig
}
// small struct for testing that codecgen works for unexported types
type tLowerFirstLetter struct {
I int
u uint64
S string
b []byte
}
// Some used types
type wrapInt64 int64
type wrapUint8 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
Tptr *time.Time
}
var testWRepeated512 wrapBytes
var testStrucTime = time.Date(2012, 2, 2, 2, 2, 2, 2000, time.UTC).UTC()
func init() {
var testARepeated512 [512]byte
for i := range testARepeated512 {
testARepeated512[i] = 'A'
}
testWRepeated512 = wrapBytes(testARepeated512[:])
}
type TestStrucFlex struct {
_struct struct{} `codec:",omitempty"` //set omitempty for every field
TestStrucCommon
Chstr chan string
Mis map[int]string
Mbu64 map[bool]struct{}
Miwu64s map[int]wrapUint64Slice
Mfwss map[float64]wrapStringSlice
Mf32wss map[float32]wrapStringSlice
Mui2wss map[uint64]wrapStringSlice
Msu2wss map[stringUint64T]wrapStringSlice
Ci64 wrapInt64
Swrapbytes []wrapBytes
Swrapuint8 []wrapUint8
ArrStrUi64T [4]stringUint64T
Ui64array [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:"-"`
Mtsptr map[string]*TestStrucFlex
Mts map[string]TestStrucFlex
Its []*TestStrucFlex
Nteststruc *TestStrucFlex
}
func emptyTestStrucFlex() *TestStrucFlex {
var ts TestStrucFlex
// we initialize and start draining the chan, so that we can decode into it without it blocking due to no consumer
ts.Chstr = make(chan string, teststrucflexChanCap)
go func() {
for range ts.Chstr {
}
}() // drain it
return &ts
}
func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStrucFlex) {
ts = &TestStrucFlex{
Chstr: make(chan string, teststrucflexChanCap),
Miwu64s: map[int]wrapUint64Slice{
5: []wrapUint64{1, 2, 3, 4, 5},
3: []wrapUint64{1, 2, 3},
},
Mf32wss: map[float32]wrapStringSlice{
5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
3.0: []wrapString{"1.0", "2.0", "3.0"},
},
Mui2wss: map[uint64]wrapStringSlice{
5: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
3: []wrapString{"1.0", "2.0", "3.0"},
},
Mfwss: map[float64]wrapStringSlice{
5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
3.0: []wrapString{"1.0", "2.0", "3.0"},
},
Mis: map[int]string{
1: "one",
22: "twenty two",
-44: "minus forty four",
},
Mbu64: map[bool]struct{}{false: {}, true: {}},
Ci64: -22,
Swrapbytes: []wrapBytes{ // lengths of 1, 2, 4, 8, 16, 32, 64, 128, 256,
testWRepeated512[:1],
testWRepeated512[:2],
testWRepeated512[:4],
testWRepeated512[:8],
testWRepeated512[:16],
testWRepeated512[:32],
testWRepeated512[:64],
testWRepeated512[:128],
testWRepeated512[:256],
testWRepeated512[:512],
},
Swrapuint8: []wrapUint8{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
},
Ui64array: [4]uint64{4, 16, 64, 256},
ArrStrUi64T: [4]stringUint64T{{"4", 4}, {"3", 3}, {"2", 2}, {"1", 1}},
}
numChanSend := cap(ts.Chstr) / 4 // 8
for i := 0; i < numChanSend; i++ {
ts.Chstr <- strings.Repeat("A", i+1)
}
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)
if depth > 0 {
depth--
if ts.Mtsptr == nil {
ts.Mtsptr = make(map[string]*TestStrucFlex)
}
if ts.Mts == nil {
ts.Mts = make(map[string]TestStrucFlex)
}
ts.Mtsptr["0"] = newTestStrucFlex(depth, n, bench, useInterface, useStringKeyOnly)
ts.Mts["0"] = *(ts.Mtsptr["0"])
ts.Its = append(ts.Its, ts.Mtsptr["0"])
}
return
}

View file

@ -1,400 +0,0 @@
/* // +build testing */
// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
package codec
// This file contains values used by tests and benchmarks.
// The benchmarks will test performance against other libraries
// (encoding/json, json-iterator, bson, gob, etc).
// Consequently, we only use values that will parse well in all engines,
// and only leverage features that work across multiple libraries for a truer comparison.
// For example,
// - JSON/BSON do not like maps with keys that are not strings,
// so we only use maps with string keys here.
// - _struct options are not honored by other libraries,
// so we don't use them in this file.
import (
"math"
"strings"
)
// func init() {
// rt := reflect.TypeOf((*TestStruc)(nil)).Elem()
// defTypeInfos.get(rt2id(rt), rt)
// }
type wrapSliceUint64 []uint64
type wrapSliceString []string
type wrapUint64 uint64
type wrapString string
type wrapUint64Slice []wrapUint64
type wrapStringSlice []wrapString
type stringUint64T struct {
S string
U uint64
}
type AnonInTestStruc struct {
AS string
AI64 int64
AI16 int16
AUi64 uint64
ASslice []string
AI64slice []int64
AUi64slice []uint64
AF64slice []float64
AF32slice []float32
// AMI32U32 map[int32]uint32
// AMU32F64 map[uint32]float64 // json/bson do not like it
AMSU16 map[string]uint16
// use these to test 0-len or nil slices/maps/arrays
AI64arr0 [0]int64
A164slice0 []int64
AUi64sliceN []uint64
AMSU16N map[string]uint16
AMSU16E map[string]uint16
}
// testSimpleFields is a sub-set of TestStrucCommon
type testSimpleFields struct {
S string
I64 int64
I8 int8
Ui64 uint64
Ui8 uint8
F64 float64
F32 float32
B bool
Sslice []string
I16slice []int16
Ui64slice []uint64
Ui8slice []uint8
Bslice []bool
Iptrslice []*int64
WrapSliceInt64 wrapSliceUint64
WrapSliceString wrapSliceString
Msi64 map[string]int64
}
type TestStrucCommon struct {
S string
I64 int64
I32 int32
I16 int16
I8 int8
I64n int64
I32n int32
I16n int16
I8n int8
Ui64 uint64
Ui32 uint32
Ui16 uint16
Ui8 uint8
F64 float64
F32 float32
B bool
By uint8 // byte: msgp doesn't like byte
Sslice []string
I64slice []int64
I16slice []int16
Ui64slice []uint64
Ui8slice []uint8
Bslice []bool
Byslice []byte
Iptrslice []*int64
WrapSliceInt64 wrapSliceUint64
WrapSliceString wrapSliceString
Msi64 map[string]int64
Simplef testSimpleFields
SstrUi64T []stringUint64T
AnonInTestStruc
NotAnon AnonInTestStruc
// 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
}
type TestStruc struct {
// _struct struct{} `json:",omitempty"` //set omitempty for every field
TestStrucCommon
Mtsptr map[string]*TestStruc
Mts map[string]TestStruc
Its []*TestStruc
Nteststruc *TestStruc
}
func populateTestStrucCommon(ts *TestStrucCommon, n int, bench, useInterface, useStringKeyOnly bool) {
var i64a, i64b, i64c, i64d int64 = 64, 6464, 646464, 64646464
// if bench, do not use uint64 values > math.MaxInt64, as bson, etc cannot decode them
var a = AnonInTestStruc{
// There's more leeway in altering this.
AS: strRpt(n, "A-String"),
AI64: -64646464,
AI16: 1616,
AUi64: 64646464,
// (U+1D11E)G-clef character may be represented in json as "\uD834\uDD1E".
// single reverse solidus character may be represented in json as "\u005C".
// include these in ASslice below.
ASslice: []string{
strRpt(n, "Aone"),
strRpt(n, "Atwo"),
strRpt(n, "Athree"),
strRpt(n, "Afour.reverse_solidus.\u005c"),
strRpt(n, "Afive.Gclef.\U0001d11E\"ugorji\"done.")},
AI64slice: []int64{
0, 1, -1, -22, 333, -4444, 55555, -666666,
// msgpack ones
-48, -32, -24, -8, 32, 127, 192, 255,
// standard ones
0, -1, 1,
math.MaxInt8, math.MaxInt8 + 4, math.MaxInt8 - 4,
math.MaxInt16, math.MaxInt16 + 4, math.MaxInt16 - 4,
math.MaxInt32, math.MaxInt32 + 4, math.MaxInt32 - 4,
math.MaxInt64, math.MaxInt64 - 4,
math.MinInt8, math.MinInt8 + 4, math.MinInt8 - 4,
math.MinInt16, math.MinInt16 + 4, math.MinInt16 - 4,
math.MinInt32, math.MinInt32 + 4, math.MinInt32 - 4,
math.MinInt64, math.MinInt64 + 4,
},
AUi64slice: []uint64{
0, 1, 22, 333, 4444, 55555, 666666,
// standard ones
math.MaxUint8, math.MaxUint8 + 4, math.MaxUint8 - 4,
math.MaxUint16, math.MaxUint16 + 4, math.MaxUint16 - 4,
math.MaxUint32, math.MaxUint32 + 4, math.MaxUint32 - 4,
},
AMSU16: map[string]uint16{strRpt(n, "1"): 1, strRpt(n, "22"): 2, strRpt(n, "333"): 3, strRpt(n, "4444"): 4},
// Note: +/- inf, NaN, and other non-representable numbers should not be explicitly tested here
AF64slice: []float64{
11.11e-11, -11.11e+11,
2.222E+12, -2.222E-12,
-555.55E-5, 555.55E+5,
666.66E-6, -666.66E+6,
7777.7777E-7, -7777.7777E-7,
-8888.8888E+8, 8888.8888E+8,
-99999.9999E+9, 99999.9999E+9,
// these below are hairy enough to need strconv.ParseFloat
33.33E-33, -33.33E+33,
44.44e+44, -44.44e-44,
// standard ones
0, -1, 1,
// math.Inf(1), math.Inf(-1),
math.Pi, math.Phi, math.E,
math.MaxFloat64, math.SmallestNonzeroFloat64,
},
AF32slice: []float32{
11.11e-11, -11.11e+11,
2.222E+12, -2.222E-12,
-555.55E-5, 555.55E+5,
666.66E-6, -666.66E+6,
7777.7777E-7, -7777.7777E-7,
-8888.8888E+8, 8888.8888E+8,
-99999.9999E+9, 99999.9999E+9,
// these below are hairy enough to need strconv.ParseFloat
33.33E-33, -33.33E+33,
// standard ones
0, -1, 1,
// math.Float32frombits(0x7FF00000), math.Float32frombits(0xFFF00000), //+inf and -inf
math.MaxFloat32, math.SmallestNonzeroFloat32,
},
A164slice0: []int64{},
AUi64sliceN: nil,
AMSU16N: nil,
AMSU16E: map[string]uint16{},
}
if !bench {
a.AUi64slice = append(a.AUi64slice, math.MaxUint64, math.MaxUint64-4)
}
*ts = TestStrucCommon{
S: strRpt(n, `some really really cool names that are nigerian and american like "ugorji melody nwoke" - get it? `),
// set the numbers close to the limits
I8: math.MaxInt8 * 2 / 3, // 8,
I8n: math.MinInt8 * 2 / 3, // 8,
I16: math.MaxInt16 * 2 / 3, // 16,
I16n: math.MinInt16 * 2 / 3, // 16,
I32: math.MaxInt32 * 2 / 3, // 32,
I32n: math.MinInt32 * 2 / 3, // 32,
I64: math.MaxInt64 * 2 / 3, // 64,
I64n: math.MinInt64 * 2 / 3, // 64,
Ui64: math.MaxUint64 * 2 / 3, // 64
Ui32: math.MaxUint32 * 2 / 3, // 32
Ui16: math.MaxUint16 * 2 / 3, // 16
Ui8: math.MaxUint8 * 2 / 3, // 8
F32: 3.402823e+38, // max representable float32 without losing precision
F64: 3.40281991833838838338e+53,
B: true,
By: 5,
Sslice: []string{strRpt(n, "one"), strRpt(n, "two"), strRpt(n, "three")},
I64slice: []int64{1111, 2222, 3333},
I16slice: []int16{44, 55, 66},
Ui64slice: []uint64{12121212, 34343434, 56565656},
Ui8slice: []uint8{210, 211, 212},
Bslice: []bool{true, false, true, false},
Byslice: []byte{13, 14, 15},
Msi64: map[string]int64{
strRpt(n, "one"): 1,
strRpt(n, "two"): 2,
strRpt(n, "\"three\""): 3,
},
WrapSliceInt64: []uint64{4, 16, 64, 256},
WrapSliceString: []string{strRpt(n, "4"), strRpt(n, "16"), strRpt(n, "64"), strRpt(n, "256")},
// 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.
// Msu2wss: map[stringUint64T]wrapStringSlice{
// {"5", 5}: []wrapString{"1", "2", "3", "4", "5"},
// {"3", 3}: []wrapString{"1", "2", "3"},
// },
// 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? `),
// set the numbers close to the limits
I8: math.MaxInt8 * 2 / 3, // 8,
I64: math.MaxInt64 * 2 / 3, // 64,
Ui64: math.MaxUint64 * 2 / 3, // 64
Ui8: math.MaxUint8 * 2 / 3, // 8
F32: 3.402823e+38, // max representable float32 without losing precision
F64: 3.40281991833838838338e+53,
B: true,
Sslice: []string{strRpt(n, "one"), strRpt(n, "two"), strRpt(n, "three")},
I16slice: []int16{44, 55, 66},
Ui64slice: []uint64{12121212, 34343434, 56565656},
Ui8slice: []uint8{210, 211, 212},
Bslice: []bool{true, false, true, false},
Msi64: map[string]int64{
strRpt(n, "one"): 1,
strRpt(n, "two"): 2,
strRpt(n, "\"three\""): 3,
},
WrapSliceInt64: []uint64{4, 16, 64, 256},
WrapSliceString: []string{strRpt(n, "4"), strRpt(n, "16"), strRpt(n, "64"), strRpt(n, "256")},
},
SstrUi64T: []stringUint64T{{"1", 1}, {"2", 2}, {"3", 3}, {"4", 4}},
AnonInTestStruc: a,
NotAnon: a,
}
if bench {
ts.Ui64 = math.MaxInt64 * 2 / 3
ts.Simplef.Ui64 = ts.Ui64
}
//For benchmarks, some things will not work.
if !bench {
//json and bson require string keys in maps
//ts.M = map[interface{}]interface{}{
// true: "true",
// int8(9): false,
//}
//gob cannot encode nil in element in array (encodeArray: nil element)
ts.Iptrslice = []*int64{nil, &i64a, nil, &i64b, nil, &i64c, nil, &i64d, nil}
// ts.Iptrslice = nil
}
if !useStringKeyOnly {
// ts.AnonInTestStruc.AMU32F64 = map[uint32]float64{1: 1, 2: 2, 3: 3} // Json/Bson barf
}
}
func newTestStruc(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStruc) {
ts = &TestStruc{}
populateTestStrucCommon(&ts.TestStrucCommon, n, bench, useInterface, useStringKeyOnly)
if depth > 0 {
depth--
if ts.Mtsptr == nil {
ts.Mtsptr = make(map[string]*TestStruc)
}
if ts.Mts == nil {
ts.Mts = make(map[string]TestStruc)
}
ts.Mtsptr[strRpt(n, "0")] = newTestStruc(depth, n, bench, useInterface, useStringKeyOnly)
ts.Mts[strRpt(n, "0")] = *(ts.Mtsptr[strRpt(n, "0")])
ts.Its = append(ts.Its, ts.Mtsptr[strRpt(n, "0")])
}
return
}
var testStrRptMap = make(map[int]map[string]string)
func strRpt(n int, s string) string {
if false {
// fmt.Printf(">>>> calling strings.Repeat on n: %d, key: %s\n", n, s)
return strings.Repeat(s, n)
}
m1, ok := testStrRptMap[n]
if !ok {
// fmt.Printf(">>>> making new map for n: %v\n", n)
m1 = make(map[string]string)
testStrRptMap[n] = m1
}
v1, ok := m1[s]
if !ok {
// fmt.Printf(">>>> creating new entry for key: %s\n", s)
v1 = strings.Repeat(s, n)
m1[s] = v1
}
return v1
}
// func wstrRpt(n int, s string) wrapBytes {
// return wrapBytes(bytes.Repeat([]byte(s), n))
// }

View file

@ -1,488 +0,0 @@
// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.
// +build alltests
// +build go1.7
package codec
// Run this using:
// go test -tags=alltests -run=Suite -coverprofile=cov.out
// go tool cover -html=cov.out
//
// Because build tags are a build time parameter, we will have to test out the
// different tags separately.
// Tags: x codecgen safe appengine notfastpath
//
// These tags should be added to alltests, e.g.
// go test '-tags=alltests x codecgen' -run=Suite -coverprofile=cov.out
//
// To run all tests before submitting code, run:
// a=( "" "safe" "codecgen" "notfastpath" "codecgen notfastpath" "codecgen safe" "safe notfastpath" )
// for i in "${a[@]}"; do echo ">>>> TAGS: $i"; go test "-tags=alltests $i" -run=Suite; done
//
// This only works on go1.7 and above. This is when subtests and suites were supported.
import "testing"
// func TestMain(m *testing.M) {
// println("calling TestMain")
// // set some parameters
// exitcode := m.Run()
// os.Exit(exitcode)
// }
func testGroupResetFlags() {
testUseMust = false
testCanonical = false
testUseMust = false
testInternStr = false
testUseIoEncDec = -1
testStructToArray = false
testCheckCircRef = false
testUseReset = false
testMaxInitLen = 0
testUseIoWrapper = false
testNumRepeatString = 8
testEncodeOptions.RecursiveEmptyCheck = false
testDecodeOptions.MapValueReset = false
testUseIoEncDec = -1
testDepth = 0
}
func testSuite(t *testing.T, f func(t *testing.T)) {
// find . -name "*_test.go" | xargs grep -e 'flag.' | cut -d '&' -f 2 | cut -d ',' -f 1 | grep -e '^test'
// Disregard the following: testInitDebug, testSkipIntf, testJsonIndent (Need a test for it)
testReinit() // so flag.Parse() is called first, and never called again
testDecodeOptions = DecodeOptions{}
testEncodeOptions = EncodeOptions{}
testGroupResetFlags()
testReinit()
t.Run("optionsFalse", f)
testCanonical = true
testUseMust = true
testInternStr = true
testUseIoEncDec = 0
testStructToArray = true
testCheckCircRef = true
testUseReset = true
testDecodeOptions.MapValueReset = true
testEncodeOptions.RecursiveEmptyCheck = true
testReinit()
t.Run("optionsTrue", f)
testDepth = 6
testReinit()
t.Run("optionsTrue-deepstruct", f)
testDepth = 0
// testEncodeOptions.AsSymbols = AsSymbolAll
testUseIoWrapper = true
testReinit()
t.Run("optionsTrue-ioWrapper", f)
testUseIoEncDec = -1
// make buffer small enough so that we have to re-fill multiple times.
testSkipRPCTests = true
testUseIoEncDec = 128
// testDecodeOptions.ReaderBufferSize = 128
// testEncodeOptions.WriterBufferSize = 128
testReinit()
t.Run("optionsTrue-bufio", f)
// testDecodeOptions.ReaderBufferSize = 0
// testEncodeOptions.WriterBufferSize = 0
testUseIoEncDec = -1
testSkipRPCTests = false
testNumRepeatString = 32
testReinit()
t.Run("optionsTrue-largestrings", f)
// The following here MUST be tested individually, as they create
// side effects i.e. the decoded value is different.
// testDecodeOptions.MapValueReset = true // ok - no side effects
// testDecodeOptions.InterfaceReset = true // error??? because we do deepEquals to verify
// testDecodeOptions.ErrorIfNoField = true // error, as expected, as fields not there
// testDecodeOptions.ErrorIfNoArrayExpand = true // no error, but no error case either
// testDecodeOptions.PreferArrayOverSlice = true // error??? because slice != array.
// .... however, update deepEqual to take this option
// testReinit()
// t.Run("optionsTrue-resetOptions", f)
testGroupResetFlags()
}
/*
find . -name "codec_test.go" | xargs grep -e '^func Test' | \
cut -d '(' -f 1 | cut -d ' ' -f 2 | \
while read f; do echo "t.Run(\"$f\", $f)"; done
*/
func testCodecGroup(t *testing.T) {
// println("running testcodecsuite")
// <setup code>
t.Run("TestBincCodecsTable", TestBincCodecsTable)
t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
t.Run("TestBincMammoth", TestBincMammoth)
t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
t.Run("TestSimpleMammoth", TestSimpleMammoth)
t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer)
t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf)
t.Run("TestMsgpackMammoth", TestMsgpackMammoth)
t.Run("TestCborCodecsTable", TestCborCodecsTable)
t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
t.Run("TestCborCodecChan", TestCborCodecChan)
t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
t.Run("TestCborMammoth", TestCborMammoth)
t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer)
t.Run("TestJsonCodecChan", TestJsonCodecChan)
t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf)
t.Run("TestJsonMammoth", TestJsonMammoth)
t.Run("TestJsonRaw", TestJsonRaw)
t.Run("TestBincRaw", TestBincRaw)
t.Run("TestMsgpackRaw", TestMsgpackRaw)
t.Run("TestSimpleRaw", TestSimpleRaw)
t.Run("TestCborRaw", TestCborRaw)
t.Run("TestAllEncCircularRef", TestAllEncCircularRef)
t.Run("TestAllAnonCycle", TestAllAnonCycle)
t.Run("TestBincRpcGo", TestBincRpcGo)
t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
t.Run("TestCborRpcGo", TestCborRpcGo)
t.Run("TestJsonRpcGo", TestJsonRpcGo)
t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
t.Run("TestJsonLargeInteger", TestJsonLargeInteger)
t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext)
t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent)
t.Run("TestJsonSwallowAndZero", TestJsonSwallowAndZero)
t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero)
t.Run("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero)
t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero)
t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero)
t.Run("TestJsonRawExt", TestJsonRawExt)
t.Run("TestCborRawExt", TestCborRawExt)
t.Run("TestMsgpackRawExt", TestMsgpackRawExt)
t.Run("TestBincRawExt", TestBincRawExt)
t.Run("TestSimpleRawExt", TestSimpleRawExt)
t.Run("TestJsonMapStructKey", TestJsonMapStructKey)
t.Run("TestCborMapStructKey", TestCborMapStructKey)
t.Run("TestMsgpackMapStructKey", TestMsgpackMapStructKey)
t.Run("TestBincMapStructKey", TestBincMapStructKey)
t.Run("TestSimpleMapStructKey", TestSimpleMapStructKey)
t.Run("TestJsonDecodeNilMapValue", TestJsonDecodeNilMapValue)
t.Run("TestCborDecodeNilMapValue", TestCborDecodeNilMapValue)
t.Run("TestMsgpackDecodeNilMapValue", TestMsgpackDecodeNilMapValue)
t.Run("TestBincDecodeNilMapValue", TestBincDecodeNilMapValue)
t.Run("TestSimpleDecodeNilMapValue", TestSimpleDecodeNilMapValue)
t.Run("TestJsonEmbeddedFieldPrecedence", TestJsonEmbeddedFieldPrecedence)
t.Run("TestCborEmbeddedFieldPrecedence", TestCborEmbeddedFieldPrecedence)
t.Run("TestMsgpackEmbeddedFieldPrecedence", TestMsgpackEmbeddedFieldPrecedence)
t.Run("TestBincEmbeddedFieldPrecedence", TestBincEmbeddedFieldPrecedence)
t.Run("TestSimpleEmbeddedFieldPrecedence", TestSimpleEmbeddedFieldPrecedence)
t.Run("TestJsonLargeContainerLen", TestJsonLargeContainerLen)
t.Run("TestCborLargeContainerLen", TestCborLargeContainerLen)
t.Run("TestMsgpackLargeContainerLen", TestMsgpackLargeContainerLen)
t.Run("TestBincLargeContainerLen", TestBincLargeContainerLen)
t.Run("TestSimpleLargeContainerLen", TestSimpleLargeContainerLen)
t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
t.Run("TestCborMammothMapsAndSlices", TestCborMammothMapsAndSlices)
t.Run("TestMsgpackMammothMapsAndSlices", TestMsgpackMammothMapsAndSlices)
t.Run("TestBincMammothMapsAndSlices", TestBincMammothMapsAndSlices)
t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
t.Run("TestJsonTime", TestJsonTime)
t.Run("TestCborTime", TestCborTime)
t.Run("TestMsgpackTime", TestMsgpackTime)
t.Run("TestBincTime", TestBincTime)
t.Run("TestSimpleTime", TestSimpleTime)
t.Run("TestJsonUintToInt", TestJsonUintToInt)
t.Run("TestCborUintToInt", TestCborUintToInt)
t.Run("TestMsgpackUintToInt", TestMsgpackUintToInt)
t.Run("TestBincUintToInt", TestBincUintToInt)
t.Run("TestSimpleUintToInt", TestSimpleUintToInt)
t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType)
t.Run("TestCborDifferentMapOrSliceType", TestCborDifferentMapOrSliceType)
t.Run("TestMsgpackDifferentMapOrSliceType", TestMsgpackDifferentMapOrSliceType)
t.Run("TestBincDifferentMapOrSliceType", TestBincDifferentMapOrSliceType)
t.Run("TestSimpleDifferentMapOrSliceType", TestSimpleDifferentMapOrSliceType)
t.Run("TestJsonScalars", TestJsonScalars)
t.Run("TestCborScalars", TestCborScalars)
t.Run("TestMsgpackScalars", TestMsgpackScalars)
t.Run("TestBincScalars", TestBincScalars)
t.Run("TestSimpleScalars", TestSimpleScalars)
t.Run("TestJsonOmitempty", TestJsonOmitempty)
t.Run("TestCborOmitempty", TestCborOmitempty)
t.Run("TestMsgpackOmitempty", TestMsgpackOmitempty)
t.Run("TestBincOmitempty", TestBincOmitempty)
t.Run("TestSimpleOmitempty", TestSimpleOmitempty)
t.Run("TestJsonIntfMapping", TestJsonIntfMapping)
t.Run("TestCborIntfMapping", TestCborIntfMapping)
t.Run("TestMsgpackIntfMapping", TestMsgpackIntfMapping)
t.Run("TestBincIntfMapping", TestBincIntfMapping)
t.Run("TestSimpleIntfMapping", TestSimpleIntfMapping)
t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
t.Run("TestCborHalfFloat", TestCborHalfFloat)
// <tear-down code>
}
func testJsonGroup(t *testing.T) {
t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer)
t.Run("TestJsonCodecChan", TestJsonCodecChan)
t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf)
t.Run("TestJsonMammoth", TestJsonMammoth)
t.Run("TestJsonRaw", TestJsonRaw)
t.Run("TestJsonRpcGo", TestJsonRpcGo)
t.Run("TestJsonLargeInteger", TestJsonLargeInteger)
t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext)
t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent)
t.Run("TestJsonSwallowAndZero", TestJsonSwallowAndZero)
t.Run("TestJsonRawExt", TestJsonRawExt)
t.Run("TestJsonMapStructKey", TestJsonMapStructKey)
t.Run("TestJsonDecodeNilMapValue", TestJsonDecodeNilMapValue)
t.Run("TestJsonEmbeddedFieldPrecedence", TestJsonEmbeddedFieldPrecedence)
t.Run("TestJsonLargeContainerLen", TestJsonLargeContainerLen)
t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
t.Run("TestJsonTime", TestJsonTime)
t.Run("TestJsonUintToInt", TestJsonUintToInt)
t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType)
t.Run("TestJsonScalars", TestJsonScalars)
t.Run("TestJsonOmitempty", TestJsonOmitempty)
t.Run("TestJsonIntfMapping", TestJsonIntfMapping)
}
func testBincGroup(t *testing.T) {
t.Run("TestBincCodecsTable", TestBincCodecsTable)
t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
t.Run("TestBincMammoth", TestBincMammoth)
t.Run("TestBincRaw", TestBincRaw)
t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero)
t.Run("TestBincRawExt", TestBincRawExt)
t.Run("TestBincMapStructKey", TestBincMapStructKey)
t.Run("TestBincDecodeNilMapValue", TestBincDecodeNilMapValue)
t.Run("TestBincEmbeddedFieldPrecedence", TestBincEmbeddedFieldPrecedence)
t.Run("TestBincLargeContainerLen", TestBincLargeContainerLen)
t.Run("TestBincMammothMapsAndSlices", TestBincMammothMapsAndSlices)
t.Run("TestBincTime", TestBincTime)
t.Run("TestBincUintToInt", TestBincUintToInt)
t.Run("TestBincDifferentMapOrSliceType", TestBincDifferentMapOrSliceType)
t.Run("TestBincScalars", TestBincScalars)
t.Run("TestBincOmitempty", TestBincOmitempty)
t.Run("TestBincIntfMapping", TestBincIntfMapping)
}
func testCborGroup(t *testing.T) {
t.Run("TestCborCodecsTable", TestCborCodecsTable)
t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
t.Run("TestCborCodecChan", TestCborCodecChan)
t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
t.Run("TestCborMammoth", TestCborMammoth)
t.Run("TestCborRaw", TestCborRaw)
t.Run("TestCborRpcGo", TestCborRpcGo)
t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero)
t.Run("TestCborRawExt", TestCborRawExt)
t.Run("TestCborMapStructKey", TestCborMapStructKey)
t.Run("TestCborDecodeNilMapValue", TestCborDecodeNilMapValue)
t.Run("TestCborEmbeddedFieldPrecedence", TestCborEmbeddedFieldPrecedence)
t.Run("TestCborLargeContainerLen", TestCborLargeContainerLen)
t.Run("TestCborMammothMapsAndSlices", TestCborMammothMapsAndSlices)
t.Run("TestCborTime", TestCborTime)
t.Run("TestCborUintToInt", TestCborUintToInt)
t.Run("TestCborDifferentMapOrSliceType", TestCborDifferentMapOrSliceType)
t.Run("TestCborScalars", TestCborScalars)
t.Run("TestCborOmitempty", TestCborOmitempty)
t.Run("TestCborIntfMapping", TestCborIntfMapping)
t.Run("TestCborHalfFloat", TestCborHalfFloat)
}
func testMsgpackGroup(t *testing.T) {
t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer)
t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf)
t.Run("TestMsgpackMammoth", TestMsgpackMammoth)
t.Run("TestMsgpackRaw", TestMsgpackRaw)
t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
t.Run("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero)
t.Run("TestMsgpackRawExt", TestMsgpackRawExt)
t.Run("TestMsgpackMapStructKey", TestMsgpackMapStructKey)
t.Run("TestMsgpackDecodeNilMapValue", TestMsgpackDecodeNilMapValue)
t.Run("TestMsgpackEmbeddedFieldPrecedence", TestMsgpackEmbeddedFieldPrecedence)
t.Run("TestMsgpackLargeContainerLen", TestMsgpackLargeContainerLen)
t.Run("TestMsgpackMammothMapsAndSlices", TestMsgpackMammothMapsAndSlices)
t.Run("TestMsgpackTime", TestMsgpackTime)
t.Run("TestMsgpackUintToInt", TestMsgpackUintToInt)
t.Run("TestMsgpackDifferentMapOrSliceType", TestMsgpackDifferentMapOrSliceType)
t.Run("TestMsgpackScalars", TestMsgpackScalars)
t.Run("TestMsgpackOmitempty", TestMsgpackOmitempty)
t.Run("TestMsgpackIntfMapping", TestMsgpackIntfMapping)
}
func testSimpleGroup(t *testing.T) {
t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
t.Run("TestSimpleMammoth", TestSimpleMammoth)
t.Run("TestSimpleRaw", TestSimpleRaw)
t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero)
t.Run("TestSimpleRawExt", TestSimpleRawExt)
t.Run("TestSimpleMapStructKey", TestSimpleMapStructKey)
t.Run("TestSimpleDecodeNilMapValue", TestSimpleDecodeNilMapValue)
t.Run("TestSimpleEmbeddedFieldPrecedence", TestSimpleEmbeddedFieldPrecedence)
t.Run("TestSimpleLargeContainerLen", TestSimpleLargeContainerLen)
t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
t.Run("TestSimpleTime", TestSimpleTime)
t.Run("TestSimpleUintToInt", TestSimpleUintToInt)
t.Run("TestSimpleDifferentMapOrSliceType", TestSimpleDifferentMapOrSliceType)
t.Run("TestSimpleScalars", TestSimpleScalars)
t.Run("TestSimpleOmitempty", TestSimpleOmitempty)
t.Run("TestSimpleIntfMapping", TestSimpleIntfMapping)
}
func testSimpleMammothGroup(t *testing.T) {
t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
}
func testRpcGroup(t *testing.T) {
t.Run("TestBincRpcGo", TestBincRpcGo)
t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
t.Run("TestCborRpcGo", TestCborRpcGo)
t.Run("TestJsonRpcGo", TestJsonRpcGo)
t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
}
func TestCodecSuite(t *testing.T) {
testSuite(t, testCodecGroup)
testGroupResetFlags()
oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString :=
testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString
testMaxInitLen = 10
testJsonH.Indent = 8
testJsonH.HTMLCharsAsIs = true
testJsonH.MapKeyAsString = true
// testJsonH.PreferFloat = true
testReinit()
t.Run("json-spaces-htmlcharsasis-initLen10", testJsonGroup)
testMaxInitLen = 10
testJsonH.Indent = -1
testJsonH.HTMLCharsAsIs = false
testJsonH.MapKeyAsString = true
// testJsonH.PreferFloat = false
testReinit()
t.Run("json-tabs-initLen10", testJsonGroup)
testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString =
oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString
oldIndefLen := testCborH.IndefiniteLength
testCborH.IndefiniteLength = true
testReinit()
t.Run("cbor-indefinitelength", testCborGroup)
testCborH.IndefiniteLength = oldIndefLen
oldTimeRFC3339 := testCborH.TimeRFC3339
testCborH.TimeRFC3339 = !testCborH.TimeRFC3339
testReinit()
t.Run("cbor-rfc3339", testCborGroup)
testCborH.TimeRFC3339 = oldTimeRFC3339
oldSymbols := testBincH.AsSymbols
testBincH.AsSymbols = 2 // AsSymbolNone
testReinit()
t.Run("binc-no-symbols", testBincGroup)
testBincH.AsSymbols = 1 // AsSymbolAll
testReinit()
t.Run("binc-all-symbols", testBincGroup)
testBincH.AsSymbols = oldSymbols
oldWriteExt := testMsgpackH.WriteExt
oldNoFixedNum := testMsgpackH.NoFixedNum
testMsgpackH.WriteExt = !testMsgpackH.WriteExt
testReinit()
t.Run("msgpack-inverse-writeext", testMsgpackGroup)
testMsgpackH.WriteExt = oldWriteExt
testMsgpackH.NoFixedNum = !testMsgpackH.NoFixedNum
testReinit()
t.Run("msgpack-fixednum", testMsgpackGroup)
testMsgpackH.NoFixedNum = oldNoFixedNum
oldEncZeroValuesAsNil := testSimpleH.EncZeroValuesAsNil
testSimpleH.EncZeroValuesAsNil = !testSimpleH.EncZeroValuesAsNil
testUseMust = true
testReinit()
t.Run("simple-enczeroasnil", testSimpleMammothGroup) // testSimpleGroup
testSimpleH.EncZeroValuesAsNil = oldEncZeroValuesAsNil
oldRpcBufsize := testRpcBufsize
testRpcBufsize = 0
t.Run("rpc-buf-0", testRpcGroup)
testRpcBufsize = 0
t.Run("rpc-buf-00", testRpcGroup)
testRpcBufsize = 0
t.Run("rpc-buf-000", testRpcGroup)
testRpcBufsize = 16
t.Run("rpc-buf-16", testRpcGroup)
testRpcBufsize = 2048
t.Run("rpc-buf-2048", testRpcGroup)
testRpcBufsize = oldRpcBufsize
testGroupResetFlags()
}
// func TestCodecSuite(t *testing.T) {
// testReinit() // so flag.Parse() is called first, and never called again
// testDecodeOptions, testEncodeOptions = DecodeOptions{}, EncodeOptions{}
// testGroupResetFlags()
// testReinit()
// t.Run("optionsFalse", func(t *testing.T) {
// t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
// })
// }