structuraldiff

package
v0.0.0-...-650f6e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package structuraldiff provides best-effort prettyprinting and diffing of pretty-printed values.

The output of any method in this package is not remotely stable. Use at your own risk.

As a quick word of caution, both DebugDump and DebugEqual are intentionally abstraction-breaking and will NOT ignore unexported fields. Other packages like go-cmp will ignore unexported fields and will make you pass in an option to prove that you own the struct in question and can look at its fields.

We don't do that. You can always see everything.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugDump

func DebugDump(val any) string

DebugDump is an extremely abstraction-breaking function that will print a Go Value.

It prints zero values and unexported field, but does NOT ignore user-defined methods for pretty-printing. It SHOULD ignore user-defined methods for pretty-printing, but this causes issues with infinite recursion when printing protos.

Types

type Result

type Result struct {
	// contains filtered or unexported fields
}

A Result is either a list of diffs

func DebugCompare

func DebugCompare[T any](left T, right T) *Result

DebugCompare compares two values of the same type and produces a structural diff between them.

If we can't detect a difference between the two structures, return an apologetic message but NOT a nil result. That way we can compare the Result to nil to see if there were any problems.

func (*Result) String

func (result *Result) String() string

String prints a result as a single string with no coloration.

Sometimes you want colors, like when printing to a terminal, but by default you don't. Regardless, stringifying with colors should be opt-in and should always be on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL