Documentation
¶
Index ¶
- Constants
- Variables
- func Abs[T constraints.Integer](a T) T
- func AddCarriageReturnAfterNewlines(s string) string
- func AssertNoGoroutineLeak(t *testing.T, startCount int)
- func AssertNoMemoryLeak(t *testing.T, startStats *runtime.MemStats, maxAllocDelta uint64, ...)
- func BytesAsString(b []byte) string
- func Catch(fn func()) (result error)
- func CombineErrors(errs ...error) error
- func CombineErrorsWithPrefixMessage(prefixMsg string, errs ...error) error
- func ConvertPanicValueToError(v any) error
- func ConvertStringSlice[A ~string, B ~string](s []A) []B
- func CountDigits(n int64) int
- func CountPrevBackslashes[T constraints.Integer](s []T, i int32) int32
- func DefaultIfZero[T constraints.Integer](v, defaultValue T) T
- func EmptySliceIfNil[T any](slice []T) []T
- func EqualMaps[K comparable, V any](m1 map[K]V, m2 map[K]V, eql func(v1, v2 V) bool) bool
- func FilterMapSlice[T any, U any](s []T, mapper func(e T) (U, bool)) []U
- func FilterSlice[T any](s []T, filter func(e T) bool) []T
- func FilterSliceByType[T any, V any](s []T, filter V) []V
- func FindClosest[T any](search ClosestSearch[T]) (sourceIndex int, minDistance int)
- func FindClosestString(ctx context.Context, candidates []string, v string, maxDifferences int) (string, int, bool)
- func FindDoubleLineSequence(bytes []byte) (index int, length int)
- func FindLongestCommonPrefix(strs []string) string
- func GetByteSize[T any]() uintptr
- func HexDigitToByte(c byte) byte
- func If[T any](cond bool, a, b T) T
- func Implements[T any](v any) bool
- func IndentLines(s string, indent string) string
- func InefficientlyWaitUntilFalse(b *atomic.Bool, timeout time.Duration) bool
- func InefficientlyWaitUntilTrue(b *atomic.Bool, timeout time.Duration) bool
- func IsContextDone(ctx context.Context) bool
- func IsHexDigit(c byte) bool
- func IsWholeInt64[F ~float64](f F) bool
- func MapSlice[T any, U any](s []T, mapper func(e T) U) []U
- func MapSliceIndexed[T any, U any](s []T, mapper func(e T, i int) U) []U
- func MarshalIndentJsonNoHTMLEspace(v any, prefix, indent string) ([]byte, error)
- func MarshalJsonNoHTMLEspace(v any) ([]byte, error)
- func Max[T constraints.Ordered](a, b T) T
- func Min[T constraints.Ordered](a T, b T) T
- func MinMaxPossibleRuneCount(byteCount int) (int, int)
- func MoveCursorNextLine(writer io.Writer, n int)
- func Must[T any](a T, err error) T
- func Must2[T any, U any](a T, b U, err error) (T, U)
- func MustGet[T any](a T, found bool) T
- func MustWriteMany[W io.Writer](w W, slices ...[]byte)
- func New[T any](v T) *T
- func PanicIfErr(err error)
- func PanicIfErrAmong(errs ...error)
- func PercentDecode(s string, allowNotEncoded bool) (string, error)
- func PercentEncode(s string) string
- func PrintSmallLineSeparator(w io.Writer)
- func RandFloat(low, high float64, seed uint64) float64
- func Recover() any
- func RemoveIndexOfSlice[T any](s []T, index int) []T
- func Repeat[T any](n int, fn func(index int) T) []T
- func RepeatValue[T any](n int, v T) []T
- func Ret[V any](v V) func() V
- func Ret0[A, B any](a A, b B) A
- func Ret1[A, B any](a A, b B) B
- func ReversedSlice[T any](s []T) []T
- func SameKeys[K comparable, V any](m1 map[K]V, m2 map[K]V) bool
- func SamePointer(a, b interface{}) bool
- func ShrinkSliceIfWastedCapacity[E any](slice []E, minShrinkableStackLength int, stackShrinkDivider int) []E
- func SliceContains[T constraints.Ordered](slice []T, v T) bool
- func Some[T any](s []T, predicate func(e T) bool) bool
- func StringAsBytes[T ~string](s T) []byte
- func StripANSISequences(str string) string
- func WriteMany[W io.Writer](w W, slices ...[]byte) error
- type AssertNoMemoryLeakOptions
- type ClosestSearch
- type FixedBufferWriter
- type FnReader
- type FnReaderWriter
- type FnReaderWriterCloser
- type FnWriter
- type TestWriter
Constants ¶
const (
SMALL_LINE_SEP = "------------------------------"
)
const UPPER_HEX_DIGITS = "0123456789ABCDEF"
Variables ¶
var ANSI_ESCAPE_SEQUENCE_REGEX = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))")
var (
ErrInvalidPercentEncodedString = errors.New("invalid percent encoded string")
)
var ErrOutOfSpace = errors.New("out of space")
var (
MATCHALL_REGEX = regexp.MustCompile(".*")
)
Functions ¶
func Abs ¶
func Abs[T constraints.Integer](a T) T
func AssertNoGoroutineLeak ¶
AssertNoGoroutineLeak checks
func AssertNoMemoryLeak ¶
func AssertNoMemoryLeak(t *testing.T, startStats *runtime.MemStats, maxAllocDelta uint64, opts ...AssertNoMemoryLeakOptions)
AssertNoMemoryLeak checks that at most maxAllocDelta bytes have been allocated since the passed memory stats have been collected. This function should be called at the end of a long test suite or test case.
func BytesAsString ¶
func CombineErrors ¶
CombineErrors combines errors into a single error with a multiline message.
func CombineErrorsWithPrefixMessage ¶
CombineErrorsWithPrefixMessage combines errors into a single error with a multiline message.
func ConvertStringSlice ¶
func CountDigits ¶
func CountPrevBackslashes ¶
func CountPrevBackslashes[T constraints.Integer](s []T, i int32) int32
func DefaultIfZero ¶
func DefaultIfZero[T constraints.Integer](v, defaultValue T) T
func EmptySliceIfNil ¶
func EmptySliceIfNil[T any](slice []T) []T
func EqualMaps ¶
func EqualMaps[K comparable, V any](m1 map[K]V, m2 map[K]V, eql func(v1, v2 V) bool) bool
func FilterMapSlice ¶
func FilterSlice ¶
func FilterSliceByType ¶
func FindClosest ¶
func FindClosest[T any](search ClosestSearch[T]) (sourceIndex int, minDistance int)
func FindClosestString ¶
func FindDoubleLineSequence ¶
FindDoubleLineSequence returns the index of a double line sequence (see further), and the sequence's length in bytes. If no double lines sequence is present, the index will be negative. A double line sequence is one of the following sequences: \r\r, \n\n, \r\n\n, \n\r\n, \r\n\r\n
func FindLongestCommonPrefix ¶
func GetByteSize ¶
func HexDigitToByte ¶
func Implements ¶
func IndentLines ¶
func InefficientlyWaitUntilFalse ¶
InefficientlyWaitUntilFalse checks every ~millisecond if *b is false, it returns true if *b is false or returns false on timeout.
func InefficientlyWaitUntilTrue ¶
InefficientlyWaitUntilTrue checks every ~millisecond if *b is true, it returns true if *b is true or returns false on timeout.
func IsContextDone ¶
func IsHexDigit ¶
func IsWholeInt64 ¶
func MapSliceIndexed ¶
func MarshalJsonNoHTMLEspace ¶
func Max ¶
func Max[T constraints.Ordered](a, b T) T
func Min ¶
func Min[T constraints.Ordered](a T, b T) T
func MinMaxPossibleRuneCount ¶
func MoveCursorNextLine ¶
func MustWriteMany ¶
func PanicIfErr ¶
func PanicIfErr(err error)
func PanicIfErrAmong ¶
func PanicIfErrAmong(errs ...error)
func PercentEncode ¶
func PrintSmallLineSeparator ¶
func Recover ¶
func Recover() any
Recover only calls recover. From recover()'s doc:
If recover is called outside the deferred function it will not stop a panicking sequence.
func RemoveIndexOfSlice ¶
func RepeatValue ¶
func ReversedSlice ¶
func ReversedSlice[T any](s []T) []T
func SameKeys ¶
func SameKeys[K comparable, V any](m1 map[K]V, m2 map[K]V) bool
func SamePointer ¶
func SamePointer(a, b interface{}) bool
func SliceContains ¶
func SliceContains[T constraints.Ordered](slice []T, v T) bool
func StringAsBytes ¶
func StripANSISequences ¶
Types ¶
type AssertNoMemoryLeakOptions ¶
type AssertNoMemoryLeakOptions struct { // duration of sleep before collection of memory stats, // defaults to defaultPreSleepDuration. PreSleepDurationMillis uint8 // if true AssertNoMemoryLeak checks that the number of goroutines has not increased. CheckGoroutines bool // number of goroutines at the beginning, GoroutineCount int MaxGoroutineCountDelta uint8 }
type ClosestSearch ¶
type FixedBufferWriter ¶
type FixedBufferWriter []byte
FixedBufferWriter writes data in the wrapper byte slice, it never allocates a new slice. ErrOutOfSpace is returned if there not enough space.
type FnReaderWriter ¶
type FnReaderWriterCloser ¶
type FnReaderWriterCloser struct { WriteFn func(p []byte) (n int, err error) ReadFn func(p []byte) (n int, err error) CloseFn func() error }
func (FnReaderWriterCloser) Close ¶
func (w FnReaderWriterCloser) Close() error