Skip to content

Commit

Permalink
Add test coverage. (#4)
Browse files Browse the repository at this point in the history
* Add test coverage.

* Add test coverage. Use Go multierrors instead of go.uber.org/multierr.

* More tests and some refactoring.
  • Loading branch information
bobg committed Jan 21, 2024
1 parent bdea9ff commit c958f04
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if it has a more-specific type than it actually needs.
For example,
if your function takes a `*os.File` parameter,
but it’s only ever used for its `Read` method,
it could be specified as an abstract `io.Reader` instead
it could be specified as an abstract `io.Reader` instead.

## Why decouple?

Expand Down
45 changes: 43 additions & 2 deletions _testdata/foo.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func F12(f *os.File) ([]byte, error) {
}

// {"ctx": {"Done": "func() <-chan struct{}"},
// "r": {"Read": "func([]byte) (int, error)"}}
//
// "r": {"Read": "func([]byte) (int, error)"}}
func F13(ctx context.Context, ch chan<- io.Reader, r *os.File) {
for {
select {
Expand Down Expand Up @@ -337,7 +338,8 @@ func F41(w io.Writer, readers []io.Reader) error {
}

// {"ctx": {"Done": "func() <-chan struct{}", "Err": "func() error"},
// "f": {"Name": "func() string"}}
//
// "f": {"Name": "func() string"}}
func F42(ctx context.Context, f *os.File, ch <-chan struct{}) (string, error) {
select {
case <-ctx.Done():
Expand All @@ -359,3 +361,42 @@ func F43(w io.Writer, f *os.File) error {
}
return fn(f)
}

// {}
func F44(s []int, x, y, z int) []int {
return s[(x+1)*2 : y : z] // exercises *ast.ParenExpr and *ast.SliceExpr
}

// {}
func F45(m map[string]int, k string) int {
return m[k]
}

// {"f": {"Read": "func([]byte) (int, error)"}}
func F46(f *os.File) ([]byte, error) {
fn := func(r io.Reader) ([]byte, error) {
return io.ReadAll(r)
}
return fn(f)
}

type t47 struct {
f *os.File
r io.Reader
}

// {}
func F47(f *os.File) t47 {
return t47{f: f, r: f}
}

// {"f": {"Read": "func([]byte) (int, error)"}}
func F48(f *os.File) t47 {
return t47{r: f}
}

// {}
func F49(n int) int {
n++
return n
}
Loading

0 comments on commit c958f04

Please sign in to comment.