Skip to content

Commit

Permalink
docs: add more examples (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig authored May 6, 2023
1 parent 15725ab commit 94bcb7f
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 12 deletions.
59 changes: 53 additions & 6 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/shoenig/test/wait"
)

var t = new(myT)
Expand Down Expand Up @@ -467,14 +470,58 @@ func ExampleTrue() {
// Output:
}

// UUIDv4
func ExampleUUIDv4() {
UUIDv4(t, "60bf6bb2-dceb-c986-2d47-07ac5d14f247")
// Output:
}

// Unreachable
func ExampleUnreachable() {
if "foo" < "bar" {
Unreachable(t)
}
// Output:
}

// ValidJSON
func ExampleValidJSON() {
js := `{"key": ["v1", "v2"]}`
ValidJSON(t, js)
// Output:
}

// ValidJSONBytes
func ExampleValidJSONBytes() {
js := []byte(`{"key": ["v1", "v2"]}`)
ValidJSONBytes(t, js)
// Output:
}

func ExampleWait_initial_success() {
Wait(t, wait.InitialSuccess(
wait.BoolFunc(func() bool {
// will be retried until returns true
// or timeout is exceeded
return true
}),
wait.Timeout(1*time.Second),
wait.Gap(100*time.Millisecond),
))
// Output:
}

// Wait
func ExampleWait_continual_success() {
Wait(t, wait.ContinualSuccess(
wait.BoolFunc(func() bool {
// will be retried until timeout expires
// and will fail test if false is ever returned
return true
}),
wait.Timeout(1*time.Second),
wait.Gap(100*time.Millisecond),
))
// Output:
}

// Zero
func ExampleZero() {
Zero(t, 0)
Zero(t, 0.0)
// Output:
}
59 changes: 53 additions & 6 deletions must/examples_test.go

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

0 comments on commit 94bcb7f

Please sign in to comment.