...

Package format

import "github.com/onsi/gomega/format"
Overview
Index

Overview ▾

Variables

CharactersAroundMismatchToInclude (default 5) specifies how many contextual characters should be printed before and after the first diff location in a truncated string assertion error message.

var CharactersAroundMismatchToInclude uint = 5

The default indentation string emitted by the format package

var Indent = "    "

Use MaxDepth to set the maximum recursion depth when printing deeply nested objects

var MaxDepth = uint(10)

MaxLength of the string representation of an object. If MaxLength is set to 0, the Object will not be truncated.

var MaxLength = 4000

Print the content of context objects. By default it will be suppressed.

Set PrintContextObjects = true to enable printing of the context internals.

var PrintContextObjects = false

TruncateThreshold (default 50) specifies the maximum length string to print in string comparison assertion error messages.

var TruncateThreshold uint = 50

TruncatedDiff choose if we should display a truncated pretty diff or not

var TruncatedDiff = true

By default, all objects (even those that implement fmt.Stringer and fmt.GoStringer) are recursively inspected to generate output.

Set UseStringerRepresentation = true to use GoString (for fmt.GoStringers) or String (for fmt.Stringer) instead.

Note that GoString and String don't always have all the information you need to understand why a test failed!

var UseStringerRepresentation = false

func IndentString

func IndentString(s string, indentation uint) string

IndentString takes a string and indents each line by the specified amount.

func Message

func Message(actual interface{}, message string, expected ...interface{}) string

Generates a formatted matcher success/failure message of the form:

Expected
	<pretty printed actual>
<message>
	<pretty printed expected>

If expected is omitted, then the message looks like:

Expected
	<pretty printed actual>
<message>

func MessageWithDiff

func MessageWithDiff(actual, message, expected string) string

func Object

func Object(object interface{}, indentation uint) string

Pretty prints the passed in object at the passed in indentation level.

Object recurses into deeply nested objects emitting pretty-printed representations of their components.

Modify format.MaxDepth to control how deep the recursion is allowed to go Set format.UseStringerRepresentation to true to return object.GoString() or object.String() when available instead of recursing into the object.

Set PrintContextObjects to true to print the content of objects implementing context.Context

func UnregisterCustomFormatter

func UnregisterCustomFormatter(key CustomFormatterKey)

UnregisterCustomFormatter unregisters a previously registered CustomFormatter. You should pass in the key returned by RegisterCustomFormatter

type CustomFormatter

CustomFormatters can be registered with Gomega via RegisterCustomFormatter() Any value to be rendered by Gomega is passed to each registered CustomFormatters. The CustomFormatter signals that it will handle formatting the value by returning (formatted-string, true) If the CustomFormatter does not want to handle the object it should return ("", false)

Strings returned by CustomFormatters are not truncated

type CustomFormatter func(value interface{}) (string, bool)

type CustomFormatterKey

type CustomFormatterKey uint

func RegisterCustomFormatter

func RegisterCustomFormatter(customFormatter CustomFormatter) CustomFormatterKey

RegisterCustomFormatter registers a CustomFormatter and returns a CustomFormatterKey

You can call UnregisterCustomFormatter with the returned key to unregister the associated CustomFormatter

type GomegaStringer

GomegaStringer allows for custom formating of objects for gomega.

type GomegaStringer interface {
    // GomegaString will be used to custom format an object.
    // It does not follow UseStringerRepresentation value and will always be called regardless.
    // It also ignores the MaxLength value.
    GomegaString() string
}