Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage. #4

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading