typed

package
v0.0.0-...-626596f Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package typed is a strictly typed wrapper around cmp.Diff.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff[T any](want T, got T, opts ...cmp.Option) (ret string)

Diff is the same as DiffSafe except that both failures and actual diff are returned in `ret` without any way to distinguish them.

func DiffSafe

func DiffSafe[T any](want T, got T, opts ...cmp.Option) (ret string, ok bool)

DiffSafe is just like cmp.Diff but it forces got and want to have the same type and includes protocmp.Transform().

This will result in more informative compile-time errors. protocmp.Transform() is necessary for any protocol buffer comparison, and it correctly does nothing if the arguments that we pass in are hereditarily non-protobufs. So, for developer convenience, let's just always add it.

Unlike a raw `cmp.Diff`, this will not panic but will instead return any discovered error as a string value with ok == false.

if you want to extend the defaults, take a look at: - "go.chromium.org/luci/common/testing/registry"

func Got

func Got[T any](got T) *diffBuilder[T]

Got supports the got-before-want style, it can be used as:

if diff := Got(1).Want(2).Options(...).Diff(); diff != "" {
  ...
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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