How to Write Example Functions (Testable Examples) in Go

Write a function starting with Example followed by the target name and include an Output comment to create a testable Go example.

Write a testable example function by defining a function with the Example prefix followed by the name of the function or type it demonstrates, and include a // Output: comment at the end to specify the expected stdout for the go test runner to verify.

// ExampleInt_SetInt64 demonstrates setting an integer value.
func ExampleInt_SetInt64() {
    z := &Int{}
    z.SetInt64(42)
    fmt.Println(z.Len())
    // Output: 6
}