slice

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainItem

func ContainItem[T any](m pepper.Matcher[T]) pepper.Matcher[[]T]

ContainItem checks if an array contains an item that meets a matcher's criteria.

Example
t := &SpyTB{}

anArray := []string{"HELLO", "WORLD"}
Expect(t, anArray).To(ContainItem(HaveAllCaps))

fmt.Println(t.Result())
Output:

Test passed
Example (Fail)
t := &SpyTB{}

anArray := []string{"hello", "world"}
Expect(t, anArray).To(ContainItem(HaveAllCaps))

fmt.Println(t.Result())
Output:

Test failed: [expected [hello world] to contain an item in all caps, but it did not]

func EveryItem

func EveryItem[T any](m pepper.Matcher[T]) pepper.Matcher[[]T]

EveryItem checks if every item in an array meets a matcher's criteria.

Example
t := &SpyTB{}

anArray := []string{"hello", "world"}
Expect(t, anArray).To(EveryItem(Containing("o")))

fmt.Println(t.Result())
Output:

Test passed
Example (Fail)
t := &SpyTB{}

anArray := []string{"hello", "world"}
Expect(t, anArray).To(EveryItem(Containing("h")))

fmt.Println(t.Result())
Output:

Test failed: [expected [hello world] to have every item contain "h"]

func HaveSize

func HaveSize[T any](matcher pepper.Matcher[int]) pepper.Matcher[[]T]

HaveSize checks if an array's size meets a matcher's criteria.

Example
t := &SpyTB{}

anArray := []string{"hello", "world"}
Expect(t, anArray).To(HaveSize[string](EqualTo(2)))

fmt.Println(t.Result())
Output:

Test passed
Example (Fail)
t := &SpyTB{}

anArray := []string{"hello", "world"}
Expect(t, anArray).To(HaveSize[string](EqualTo(3)))

fmt.Println(t.Result())
Output:

Test failed: [expected [hello world] to have a size be equal to 3, but it was 2]

func ShallowEquals added in v0.6.0

func ShallowEquals[T comparable](other []T) pepper.Matcher[[]T]

ShallowEquals checks if two slices are equal, only works with slices of comparable types.

Example
t := &SpyTB{}

anArray := []string{"hello", "world"}
Expect(t, anArray).To(ShallowEquals([]string{"hello", "world"}))

fmt.Println(t.Result())
Output:

Test passed
Example (Fail)
t := &SpyTB{}

anArray := []string{"hello", "world"}
Expect(t, anArray).To(ShallowEquals([]string{"goodbye", "world"}))

fmt.Println(t.Result())
Output:

Test failed: [expected [hello world] to be equal to [goodbye world]]

Types

This section is empty.

Jump to

Keyboard shortcuts

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