MCPcopy Index your code
hub / github.com/bitfield/script / TestFilterReadsNoMoreThanRequested

Function TestFilterReadsNoMoreThanRequested

script_test.go:420–446  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

418}
419
420func 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
448func TestFilterByFirstLineOnlyGivesFirstLineOfInput(t *testing.T) {
449 t.Parallel()

Callers

nothing calls this directly

Calls 4

NewPipeFunction · 0.92
FilterMethod · 0.80
WithReaderMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…