Skip to content

Commit 3bd6a9b

Browse files
authored
doc: update (#49)
* added more examples and advanced usage guidance * reformatted go code in markdown * fixed broken links, misspellings * added presentation of the approach to testing Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 2ff9e7c commit 3bd6a9b

16 files changed

Lines changed: 1821 additions & 687 deletions

File tree

.claude/CLAUDE.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ go test ./codegen/internal/... # Scanner and generator tests
121121
go test ./internal/assertions -run TestEqual
122122

123123
# Run with coverage
124-
go test -cover ./internal/assertions # Should be 90%+
125-
go test -cover ./assert # Should be ~100%
126-
go test -cover ./require # Should be ~100%
124+
go test -cover ./internal/assertions # Should be 90%+
125+
go test -cover ./assert # Should be ~100%
126+
go test -cover ./require # Should be ~100%
127127
go test -cover ./codegen/internal/scanner/... # Scanner tests
128128

129129
# Run tests with verbose output
@@ -160,6 +160,11 @@ cd hack/doc-site/hugo
160160

161161
**Example - Adding a new assertion:**
162162
```go
163+
import (
164+
"fmt"
165+
"strings"
166+
)
167+
163168
// In internal/assertions/string.go
164169

165170
// StartsWith asserts that the string starts with the given prefix.
@@ -168,16 +173,16 @@ cd hack/doc-site/hugo
168173
//
169174
// Examples:
170175
//
171-
// success: "hello world", "hello"
172-
// failure: "hello world", "bye"
176+
// success: "hello world", "hello"
177+
// failure: "hello world", "bye"
173178
func StartsWith(t T, str, prefix string, msgAndArgs ...any) bool {
174-
if h, ok := t.(H); ok {
175-
h.Helper()
176-
}
177-
if !strings.HasPrefix(str, prefix) {
178-
return Fail(t, fmt.Sprintf("Expected %q to start with %q", str, prefix), msgAndArgs...)
179-
}
180-
return true
179+
if h, ok := t.(H); ok {
180+
h.Helper()
181+
}
182+
if !strings.HasPrefix(str, prefix) {
183+
return Fail(t, fmt.Sprintf("Expected %q to start with %q", str, prefix), msgAndArgs...)
184+
}
185+
return true
181186
}
182187
```
183188

@@ -233,10 +238,10 @@ The generator reads "Examples:" sections from doc comments:
233238
//
234239
// Examples:
235240
//
236-
// success: 123, 123
237-
// failure: 123, 456
241+
// success: 123, 123
242+
// failure: 123, 456
238243
func Equal(t T, expected, actual any, msgAndArgs ...any) bool {
239-
// implementation
244+
// implementation
240245
}
241246
```
242247

@@ -297,10 +302,11 @@ To assign a function to a domain, add a domain tag in its doc comment:
297302
// domain: equality
298303
//
299304
// Examples:
300-
// success: 123, 123
301-
// failure: 123, 456
305+
//
306+
// success: 123, 123
307+
// failure: 123, 456
302308
func Equal(t T, expected, actual any, msgAndArgs ...any) bool {
303-
// implementation
309+
// implementation
304310
}
305311
```
306312

@@ -396,6 +402,12 @@ This layered approach ensures:
396402
**This repository uses a signature testing pattern** based on Go 1.23's `iter.Seq` for all table-driven tests:
397403

398404
```go
405+
import (
406+
"iter"
407+
"slices"
408+
"testing"
409+
)
410+
399411
// Define test case struct
400412
type parseTestExamplesCase struct {
401413
name string

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ go get github.com/go-openapi/testify/v2
8181
`testify` simplifies your test assertions like so.
8282

8383
```go
84-
import (
84+
import (
8585
"testing"
8686
)
8787
...
@@ -101,7 +101,7 @@ go get github.com/go-openapi/testify/v2
101101
Becomes:
102102

103103
```go
104-
import (
104+
import (
105105
"testing"
106106
"github.com/go-openapi/testify/v2/require"
107107
)
@@ -190,8 +190,8 @@ Maintainers can cut a new release by either:
190190
[doc-examples]: https://go-openapi.github.io/testify/usage/examples
191191
[doc-generics]: https://go-openapi.github.io/testify/usage/generics
192192
[example-with-generics-url]: https://go-openapi.github.io/testify#usage-with-generics
193-
[godoc-badge]: https://pkg.go.dev/badge/github.com/go-openapi/testify
194-
[godoc-url]: http://pkg.go.dev/github.com/go-openapi/testify
193+
[godoc-badge]: https://pkg.go.dev/badge/github.com/go-openapi/testify/v2
194+
[godoc-url]: https://pkg.go.dev/github.com/go-openapi/testify/v2
195195
[slack-logo]: https://a.slack-edge.com/e6a93c1/img/icons/favicon-32.png
196196
[slack-badge]: https://img.shields.io/badge/slack-blue?link=https%3A%2F%2Fgoswagger.slack.com%2Farchives%2FC04R30YM
197197
[slack-url]: https://goswagger.slack.com/archives/C04R30YMU

codegen/internal/generator/funcmaps/markdown.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const sensiblePrealloc = 20
2525
// 1. Reference-style markdown links: [text]: url
2626
// 2. Godoc-style links: [errors.Is], [testing.T], etc.
2727
func FormatMarkdown(in string) string {
28-
2928
// Step 1: Extract reference-style link definitions
3029
// Pattern: [text]: url (at start of line or after whitespace)
3130
refLinks := make(map[string]string)

codegen/internal/model/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (f Function) GenericName(suffixes ...string) string {
133133
}
134134

135135
// GenericCallName renders the function name with explicit type parameters.
136-
// This is used when forwarding type parameters, as all type parameters may not be always infered from the arguments.
136+
// This is used when forwarding type parameters, as all type parameters may not be always inferred from the arguments.
137137
func (f Function) GenericCallName(suffixes ...string) string {
138138
suffix := strings.Join(suffixes, "")
139139
if !f.IsGeneric { // means len(f.TypeParams) == 0

codegen/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func registerFlags(cfg *config) {
6363
}
6464

6565
func execute(cfg *config) error {
66+
// 1. Scan internal/assertions
6667
scanner := scanner.New(
6768
scanner.WithWorkDir(cfg.dir),
6869
scanner.WithPackage(cfg.inputPkg),
@@ -73,6 +74,7 @@ func execute(cfg *config) error {
7374
return err
7475
}
7576

77+
// 2. Generate assert and require packages
7678
builder := generator.New(scanned)
7779
var doc model.Documentation
7880

@@ -105,7 +107,9 @@ func execute(cfg *config) error {
105107
return nil
106108
}
107109

108-
// and now for something completely different: generating the documentation
110+
// ... and now for something completely different: generating the documentation
111+
//
112+
// 3. Generate API documentation in docs/doc-site/api
109113
documentalist := generator.NewDocGenerator(doc)
110114
err = documentalist.Generate(
111115
// where to generate

docs/doc-site/_index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This is the go-openapi fork of the great [testify](https://github.com/stretchr/t
2020
{{% button href="https://github.com/go-openapi/testify/fork" hint="fork me on github" style=primary icon=code-fork %}}Fork me{{% /button %}}
2121
Design and exploration phase. Feedback, contributions and proposals are welcome.
2222

23-
See our [ROADMAP](./maintainers/ROADMAP.md).
23+
See our [ROADMAP](./project/maintainers/ROADMAP.md).
2424

2525
### Motivation
2626

@@ -31,7 +31,7 @@ See [why we wanted a v2](./MOTIVATION.md).
3131
Import this library in your project like so.
3232

3333
```cmd
34-
go get github.com/go-openapi/testify/v2
34+
go get github.com/go-openapi/testify/v2
3535
```
3636

3737
... and start writing tests. Look at our [examples][doc-examples].
@@ -43,7 +43,7 @@ Import this library in your project like so.
4343
{{< cards >}}
4444
{{% card title="Standard library" %}}
4545
```go
46-
import (
46+
import (
4747
"testing"
4848
)
4949
...
@@ -64,7 +64,7 @@ Import this library in your project like so.
6464

6565
{{% card title="testify" %}}
6666
```go
67-
import (
67+
import (
6868
"testing"
6969

7070
"github.com/go-openapi/testify/v2/require"
@@ -91,7 +91,7 @@ Obviously, the `Assertion` type cannot be extended with generic methods, as of `
9191
{{< cards >}}
9292
{{% card title="EqualT" %}}
9393
```go
94-
import (
94+
import (
9595
"testing"
9696

9797
"github.com/go-openapi/testify/v2/require"
@@ -107,7 +107,7 @@ Obviously, the `Assertion` type cannot be extended with generic methods, as of `
107107
{{% /card %}}
108108
{{% card title="InDeltaT" %}}
109109
```go
110-
import (
110+
import (
111111
"testing"
112112

113113
"github.com/go-openapi/testify/v2/require"

0 commit comments

Comments
 (0)