Skip to content

Commit

Permalink
docs: add more examples (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig authored May 3, 2023
1 parent dd77737 commit f9e3762
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 12 deletions.
66 changes: 60 additions & 6 deletions examples_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//go:build unix

package test

import (
"fmt"
"os"
"strings"
)

Expand Down Expand Up @@ -45,17 +48,50 @@ func (c *myContainer[T]) Empty() bool {
return len(c.items) == 0
}

type score int

func (s score) Less(other score) bool {
return s < other
}

func ExampleAscending() {
nums := []int{1, 3, 4, 4, 9}
Ascending(t, nums)
// Output:
}

// AscendingCmp
func ExampleAscendingCmp() {
labels := []string{"Fun", "great", "Happy", "joyous"}
AscendingCmp(t, labels, func(a, b string) int {
A := strings.ToLower(a)
B := strings.ToLower(b)
switch {
case A == B:
return 0
case A < B:
return -1
default:
return 1
}
})
// Output:
}

// AscendingFunc
func ExampleAscendingFunc() {
labels := []string{"Fun", "great", "Happy", "joyous"}
AscendingFunc(t, labels, func(a, b string) bool {
A := strings.ToLower(a)
B := strings.ToLower(b)
return A < B
})
// Output:
}

// AscendingLess
func ExampleAscendingLess() {
nums := []score{4, 6, 7, 9}
AscendingLess(t, nums)
// Output:
}

func ExampleBetween() {
lower, upper := 3, 9
Expand Down Expand Up @@ -109,15 +145,33 @@ func ExampleDescendingFunc() {
// Output:
}

// DescendingLess
func ExampleDescendingLess() {
nums := []score{9, 6, 3, 1, 0}
DescendingLess(t, nums)
// Output:
}

// DirExists
func ExampleDirExists() {
DirExists(t, "/tmp")
// Output:
}

// DirExistsFS
func ExampleDirExistsFS() {
DirExistsFS(t, os.DirFS("/"), "tmp")
// Output:
}

// DirNotExists
func ExampleDirNotExists() {
DirNotExists(t, "/does/not/exist")
// Output:
}

// DirNotExistsFS
func ExampleDirNotExistsFS() {
DirNotExistsFS(t, os.DirFS("/"), "does/not/exist")
// Output:
}

func ExampleEmpty() {
// container implements .Empty method
Expand Down
66 changes: 60 additions & 6 deletions must/examples_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions must/must.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ func DirNotExistsFS(t T, system fs.FS, directory string, settings ...Setting) {
// DirNotExists asserts directory does not exist on the OS filesystem.
func DirNotExists(t T, directory string, settings ...Setting) {
t.Helper()
directory = strings.TrimPrefix(directory, "/")
invoke(t, assertions.DirNotExistsFS(os.DirFS(brokenfs.Root), directory), settings...)
}

Expand Down

0 comments on commit f9e3762

Please sign in to comment.