(t *testing.T)
| 418 | } |
| 419 | |
| 420 | func TestFilterReadsNoMoreThanRequested(t *testing.T) { |
| 421 | t.Parallel() |
| 422 | input := "firstline\nsecondline" |
| 423 | source := bytes.NewBufferString(input) |
| 424 | p := script.NewPipe().WithReader(source).Filter(func(r io.Reader, w io.Writer) error { |
| 425 | // read just the first line of input |
| 426 | var text string |
| 427 | _, err := fmt.Fscanln(r, &text) |
| 428 | if err != nil { |
| 429 | return err |
| 430 | } |
| 431 | fmt.Fprintln(w, text) |
| 432 | return nil |
| 433 | }) |
| 434 | want := "firstline\n" |
| 435 | got, err := p.String() |
| 436 | if err != nil { |
| 437 | t.Fatal(err) |
| 438 | } |
| 439 | if want != got { |
| 440 | t.Fatal(cmp.Diff(want, got)) |
| 441 | } |
| 442 | wantRemaining := "secondline" |
| 443 | if wantRemaining != source.String() { |
| 444 | t.Errorf("want %q remaining, got %q", wantRemaining, source.String()) |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | func TestFilterByFirstLineOnlyGivesFirstLineOfInput(t *testing.T) { |
| 449 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…