diff options
| author | 2024-06-20 17:06:20 +0000 | |
|---|---|---|
| committer | 2024-06-20 17:06:20 +0000 | |
| commit | 7b1ccbd65ad4e3dc240b20c0d730a28f5e32274f (patch) | |
| tree | afe11488718b998a04c961744bc28503b8612f6e /vendor/github.com/google/go-cmp/cmp/internal/value | |
| parent | [bugfix] rename `include_types[]` to `types[]` (#3023) (diff) | |
| download | gotosocial-7b1ccbd65ad4e3dc240b20c0d730a28f5e32274f.tar.xz | |
[feature] add worker task serialization logic (#2989)
* improved server shutdown with more precise shutdown of modules + deferring of ALL of it
* move delivery and workers into separate files
* add worker task model and Serialize() / Deserialize() methods for message types
* start adding message serialize / deserialize tests
* start adding test cases
* update body rewinding to rely on standard library mechanism of r.GetBody()
* remove request rewinding (http.Client{} should already handle this)
* standard library already handles rewinding
* improved code comment
* move the newPOST() function contents to prepare(), fits better with current API
* add Serialize() / Deserialize() implementations for Delivery{} type
* finish writing FromClientAPI sserialize / deserialize tests
* start adding FromFediAPI{} serialize / deserialize test cases
* fix FromFediAPI{} tests
* add tests for delivery message type
* fix repeat code
* missing license header
* use testrig status and accounts for marshal / unmarshaling tests
* add a specific test for checking account RSA keys are preserved
Diffstat (limited to 'vendor/github.com/google/go-cmp/cmp/internal/value')
3 files changed, 304 insertions, 0 deletions
| diff --git a/vendor/github.com/google/go-cmp/cmp/internal/value/name.go b/vendor/github.com/google/go-cmp/cmp/internal/value/name.go new file mode 100644 index 000000000..7b498bb2c --- /dev/null +++ b/vendor/github.com/google/go-cmp/cmp/internal/value/name.go @@ -0,0 +1,164 @@ +// Copyright 2020, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package value + +import ( +	"reflect" +	"strconv" +) + +var anyType = reflect.TypeOf((*interface{})(nil)).Elem() + +// TypeString is nearly identical to reflect.Type.String, +// but has an additional option to specify that full type names be used. +func TypeString(t reflect.Type, qualified bool) string { +	return string(appendTypeName(nil, t, qualified, false)) +} + +func appendTypeName(b []byte, t reflect.Type, qualified, elideFunc bool) []byte { +	// BUG: Go reflection provides no way to disambiguate two named types +	// of the same name and within the same package, +	// but declared within the namespace of different functions. + +	// Use the "any" alias instead of "interface{}" for better readability. +	if t == anyType { +		return append(b, "any"...) +	} + +	// Named type. +	if t.Name() != "" { +		if qualified && t.PkgPath() != "" { +			b = append(b, '"') +			b = append(b, t.PkgPath()...) +			b = append(b, '"') +			b = append(b, '.') +			b = append(b, t.Name()...) +		} else { +			b = append(b, t.String()...) +		} +		return b +	} + +	// Unnamed type. +	switch k := t.Kind(); k { +	case reflect.Bool, reflect.String, reflect.UnsafePointer, +		reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, +		reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, +		reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128: +		b = append(b, k.String()...) +	case reflect.Chan: +		if t.ChanDir() == reflect.RecvDir { +			b = append(b, "<-"...) +		} +		b = append(b, "chan"...) +		if t.ChanDir() == reflect.SendDir { +			b = append(b, "<-"...) +		} +		b = append(b, ' ') +		b = appendTypeName(b, t.Elem(), qualified, false) +	case reflect.Func: +		if !elideFunc { +			b = append(b, "func"...) +		} +		b = append(b, '(') +		for i := 0; i < t.NumIn(); i++ { +			if i > 0 { +				b = append(b, ", "...) +			} +			if i == t.NumIn()-1 && t.IsVariadic() { +				b = append(b, "..."...) +				b = appendTypeName(b, t.In(i).Elem(), qualified, false) +			} else { +				b = appendTypeName(b, t.In(i), qualified, false) +			} +		} +		b = append(b, ')') +		switch t.NumOut() { +		case 0: +			// Do nothing +		case 1: +			b = append(b, ' ') +			b = appendTypeName(b, t.Out(0), qualified, false) +		default: +			b = append(b, " ("...) +			for i := 0; i < t.NumOut(); i++ { +				if i > 0 { +					b = append(b, ", "...) +				} +				b = appendTypeName(b, t.Out(i), qualified, false) +			} +			b = append(b, ')') +		} +	case reflect.Struct: +		b = append(b, "struct{ "...) +		for i := 0; i < t.NumField(); i++ { +			if i > 0 { +				b = append(b, "; "...) +			} +			sf := t.Field(i) +			if !sf.Anonymous { +				if qualified && sf.PkgPath != "" { +					b = append(b, '"') +					b = append(b, sf.PkgPath...) +					b = append(b, '"') +					b = append(b, '.') +				} +				b = append(b, sf.Name...) +				b = append(b, ' ') +			} +			b = appendTypeName(b, sf.Type, qualified, false) +			if sf.Tag != "" { +				b = append(b, ' ') +				b = strconv.AppendQuote(b, string(sf.Tag)) +			} +		} +		if b[len(b)-1] == ' ' { +			b = b[:len(b)-1] +		} else { +			b = append(b, ' ') +		} +		b = append(b, '}') +	case reflect.Slice, reflect.Array: +		b = append(b, '[') +		if k == reflect.Array { +			b = strconv.AppendUint(b, uint64(t.Len()), 10) +		} +		b = append(b, ']') +		b = appendTypeName(b, t.Elem(), qualified, false) +	case reflect.Map: +		b = append(b, "map["...) +		b = appendTypeName(b, t.Key(), qualified, false) +		b = append(b, ']') +		b = appendTypeName(b, t.Elem(), qualified, false) +	case reflect.Ptr: +		b = append(b, '*') +		b = appendTypeName(b, t.Elem(), qualified, false) +	case reflect.Interface: +		b = append(b, "interface{ "...) +		for i := 0; i < t.NumMethod(); i++ { +			if i > 0 { +				b = append(b, "; "...) +			} +			m := t.Method(i) +			if qualified && m.PkgPath != "" { +				b = append(b, '"') +				b = append(b, m.PkgPath...) +				b = append(b, '"') +				b = append(b, '.') +			} +			b = append(b, m.Name...) +			b = appendTypeName(b, m.Type, qualified, true) +		} +		if b[len(b)-1] == ' ' { +			b = b[:len(b)-1] +		} else { +			b = append(b, ' ') +		} +		b = append(b, '}') +	default: +		panic("invalid kind: " + k.String()) +	} +	return b +} diff --git a/vendor/github.com/google/go-cmp/cmp/internal/value/pointer.go b/vendor/github.com/google/go-cmp/cmp/internal/value/pointer.go new file mode 100644 index 000000000..e5dfff69a --- /dev/null +++ b/vendor/github.com/google/go-cmp/cmp/internal/value/pointer.go @@ -0,0 +1,34 @@ +// Copyright 2018, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package value + +import ( +	"reflect" +	"unsafe" +) + +// Pointer is an opaque typed pointer and is guaranteed to be comparable. +type Pointer struct { +	p unsafe.Pointer +	t reflect.Type +} + +// PointerOf returns a Pointer from v, which must be a +// reflect.Ptr, reflect.Slice, or reflect.Map. +func PointerOf(v reflect.Value) Pointer { +	// The proper representation of a pointer is unsafe.Pointer, +	// which is necessary if the GC ever uses a moving collector. +	return Pointer{unsafe.Pointer(v.Pointer()), v.Type()} +} + +// IsNil reports whether the pointer is nil. +func (p Pointer) IsNil() bool { +	return p.p == nil +} + +// Uintptr returns the pointer as a uintptr. +func (p Pointer) Uintptr() uintptr { +	return uintptr(p.p) +} diff --git a/vendor/github.com/google/go-cmp/cmp/internal/value/sort.go b/vendor/github.com/google/go-cmp/cmp/internal/value/sort.go new file mode 100644 index 000000000..98533b036 --- /dev/null +++ b/vendor/github.com/google/go-cmp/cmp/internal/value/sort.go @@ -0,0 +1,106 @@ +// Copyright 2017, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package value + +import ( +	"fmt" +	"math" +	"reflect" +	"sort" +) + +// SortKeys sorts a list of map keys, deduplicating keys if necessary. +// The type of each value must be comparable. +func SortKeys(vs []reflect.Value) []reflect.Value { +	if len(vs) == 0 { +		return vs +	} + +	// Sort the map keys. +	sort.SliceStable(vs, func(i, j int) bool { return isLess(vs[i], vs[j]) }) + +	// Deduplicate keys (fails for NaNs). +	vs2 := vs[:1] +	for _, v := range vs[1:] { +		if isLess(vs2[len(vs2)-1], v) { +			vs2 = append(vs2, v) +		} +	} +	return vs2 +} + +// isLess is a generic function for sorting arbitrary map keys. +// The inputs must be of the same type and must be comparable. +func isLess(x, y reflect.Value) bool { +	switch x.Type().Kind() { +	case reflect.Bool: +		return !x.Bool() && y.Bool() +	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: +		return x.Int() < y.Int() +	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: +		return x.Uint() < y.Uint() +	case reflect.Float32, reflect.Float64: +		// NOTE: This does not sort -0 as less than +0 +		// since Go maps treat -0 and +0 as equal keys. +		fx, fy := x.Float(), y.Float() +		return fx < fy || math.IsNaN(fx) && !math.IsNaN(fy) +	case reflect.Complex64, reflect.Complex128: +		cx, cy := x.Complex(), y.Complex() +		rx, ix, ry, iy := real(cx), imag(cx), real(cy), imag(cy) +		if rx == ry || (math.IsNaN(rx) && math.IsNaN(ry)) { +			return ix < iy || math.IsNaN(ix) && !math.IsNaN(iy) +		} +		return rx < ry || math.IsNaN(rx) && !math.IsNaN(ry) +	case reflect.Ptr, reflect.UnsafePointer, reflect.Chan: +		return x.Pointer() < y.Pointer() +	case reflect.String: +		return x.String() < y.String() +	case reflect.Array: +		for i := 0; i < x.Len(); i++ { +			if isLess(x.Index(i), y.Index(i)) { +				return true +			} +			if isLess(y.Index(i), x.Index(i)) { +				return false +			} +		} +		return false +	case reflect.Struct: +		for i := 0; i < x.NumField(); i++ { +			if isLess(x.Field(i), y.Field(i)) { +				return true +			} +			if isLess(y.Field(i), x.Field(i)) { +				return false +			} +		} +		return false +	case reflect.Interface: +		vx, vy := x.Elem(), y.Elem() +		if !vx.IsValid() || !vy.IsValid() { +			return !vx.IsValid() && vy.IsValid() +		} +		tx, ty := vx.Type(), vy.Type() +		if tx == ty { +			return isLess(x.Elem(), y.Elem()) +		} +		if tx.Kind() != ty.Kind() { +			return vx.Kind() < vy.Kind() +		} +		if tx.String() != ty.String() { +			return tx.String() < ty.String() +		} +		if tx.PkgPath() != ty.PkgPath() { +			return tx.PkgPath() < ty.PkgPath() +		} +		// This can happen in rare situations, so we fallback to just comparing +		// the unique pointer for a reflect.Type. This guarantees deterministic +		// ordering within a program, but it is obviously not stable. +		return reflect.ValueOf(vx.Type()).Pointer() < reflect.ValueOf(vy.Type()).Pointer() +	default: +		// Must be Func, Map, or Slice; which are not comparable. +		panic(fmt.Sprintf("%T is not comparable", x.Type())) +	} +} | 
