matchers

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

README

GoDoc

A set of custom gomega matchers to test generated go code.

Example of included new matchers:

myCode := `
	package main

	import "fmt"

	func main() {
		fmt.Println("Hello, 世界")
	}
`

Expect(myCode).To(BeValidGoCode())
Expect(myCode).To(DeclarePackage("main"))
Expect(myCode).To(ImportPackage("fmt"))
Expect(myCode).To(ContainCode(`fmt.Println("Hello, 世界")`))
Expect("2006-01-02T15:04").To(EqualTime(time.Now()))

These matchers are actively used in the goldi test suit.

Documentation

Overview

Example
myCode := `
		package main

		import "fmt"

		func main() {
			fmt.Println("Hello, 世界")
		}
	`

Expect(myCode).To(BeValidGoCode())
Expect(myCode).To(DeclarePackage("main"))
Expect(myCode).To(ImportPackage("fmt"))
Expect(myCode).To(ContainCode(`fmt.Println("Hello, 世界")`))
Expect("2006-01-02T15:04").To(EqualTime(time.Now()))
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeValidGoCode

func BeValidGoCode() types.GomegaMatcher

BeValidGoCode succeeds if actual can be converted or read into to byte[] and contains valid go code.

func ContainCode

func ContainCode(expected string) types.GomegaMatcher

ContainCode succeeds if actual can be converted or read into to byte[], is valid go code and contains the given go code. Indentation is ignored and the syntax of the given go code is not checked.

func DeclarePackage

func DeclarePackage(packageName string) types.GomegaMatcher

DeclarePackage succeeds if actual can be converted or read into to byte[], is valid go code and declares the given package name.

func Dump

func Dump(output *bytes.Buffer)

func EqualTime

func EqualTime(expected interface{}) types.GomegaMatcher

EqualTime succeeds if actual is a time.Time or a RFC3339 formatted string and equals expected. expected can either be a time.Time or a string in RFC3339.

func ImportPackage

func ImportPackage(expected string) types.GomegaMatcher

ImportPackage succeeds if actual can be converted or read into to byte[], is valid go code and contains an import statement for the given package

func RegisterExtendedTestingT

func RegisterExtendedTestingT(t types.GomegaTestingT)

RegisterExtendedTestingT is like gomega.RegisterTestingT but it also omits any gomega frames from the printed stacktrace.

Types

This section is empty.

Jump to

Keyboard shortcuts

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