Skip to content

Commit f9e3762

Browse files
authored
docs: add more examples (#126)
1 parent dd77737 commit f9e3762

4 files changed

Lines changed: 122 additions & 12 deletions

File tree

examples_test.go

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
//go:build unix
2+
13
package test
24

35
import (
46
"fmt"
7+
"os"
58
"strings"
69
)
710

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

51+
type score int
52+
53+
func (s score) Less(other score) bool {
54+
return s < other
55+
}
56+
4857
func ExampleAscending() {
4958
nums := []int{1, 3, 4, 4, 9}
5059
Ascending(t, nums)
5160
// Output:
5261
}
5362

54-
// AscendingCmp
63+
func ExampleAscendingCmp() {
64+
labels := []string{"Fun", "great", "Happy", "joyous"}
65+
AscendingCmp(t, labels, func(a, b string) int {
66+
A := strings.ToLower(a)
67+
B := strings.ToLower(b)
68+
switch {
69+
case A == B:
70+
return 0
71+
case A < B:
72+
return -1
73+
default:
74+
return 1
75+
}
76+
})
77+
// Output:
78+
}
5579

56-
// AscendingFunc
80+
func ExampleAscendingFunc() {
81+
labels := []string{"Fun", "great", "Happy", "joyous"}
82+
AscendingFunc(t, labels, func(a, b string) bool {
83+
A := strings.ToLower(a)
84+
B := strings.ToLower(b)
85+
return A < B
86+
})
87+
// Output:
88+
}
5789

58-
// AscendingLess
90+
func ExampleAscendingLess() {
91+
nums := []score{4, 6, 7, 9}
92+
AscendingLess(t, nums)
93+
// Output:
94+
}
5995

6096
func ExampleBetween() {
6197
lower, upper := 3, 9
@@ -109,15 +145,33 @@ func ExampleDescendingFunc() {
109145
// Output:
110146
}
111147

112-
// DescendingLess
148+
func ExampleDescendingLess() {
149+
nums := []score{9, 6, 3, 1, 0}
150+
DescendingLess(t, nums)
151+
// Output:
152+
}
113153

114-
// DirExists
154+
func ExampleDirExists() {
155+
DirExists(t, "/tmp")
156+
// Output:
157+
}
115158

116-
// DirExistsFS
159+
func ExampleDirExistsFS() {
160+
DirExistsFS(t, os.DirFS("/"), "tmp")
161+
// Output:
162+
}
117163

118164
// DirNotExists
165+
func ExampleDirNotExists() {
166+
DirNotExists(t, "/does/not/exist")
167+
// Output:
168+
}
119169

120170
// DirNotExistsFS
171+
func ExampleDirNotExistsFS() {
172+
DirNotExistsFS(t, os.DirFS("/"), "does/not/exist")
173+
// Output:
174+
}
121175

122176
func ExampleEmpty() {
123177
// container implements .Empty method

must/examples_test.go

Lines changed: 60 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

must/must.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ func DirNotExistsFS(t T, system fs.FS, directory string, settings ...Setting) {
554554
// DirNotExists asserts directory does not exist on the OS filesystem.
555555
func DirNotExists(t T, directory string, settings ...Setting) {
556556
t.Helper()
557+
directory = strings.TrimPrefix(directory, "/")
557558
invoke(t, assertions.DirNotExistsFS(os.DirFS(brokenfs.Root), directory), settings...)
558559
}
559560

0 commit comments

Comments
 (0)