Exemple #1
0
func ExampleIter() {
	input := `one two
three
four

five`
	r := strings.NewReader(input)
	readlines.Iter(r, 1024*1024, func(line []byte) error {
		fmt.Printf("%q\n", line)
		return nil
	})
	// Output:
	// "one two"
	// "three"
	// "four"
	// ""
	// "five"
}
Exemple #2
0
func TestLines(t *testing.T) {
	for i, test := range linesTests {
		var r io.Reader = strings.NewReader(test.input)
		if test.bufioSize > 0 {
			r = bufio.NewReaderSize(r, test.bufioSize)
		}
		var lines []string
		err := readlines.Iter(r, test.maxSize, func(line []byte) error {
			lines = append(lines, string(line))
			return nil
		})
		if err != nil {
			t.Errorf("test %d; unexpected error: %v", i, err)
		}
		if !reflect.DeepEqual(lines, test.lines) {
			t.Errorf("test %d; want %q; got %q", i, test.lines, lines)
		}
	}
}