-
Notifications
You must be signed in to change notification settings - Fork 8
/
tsvreader_example_test.go
72 lines (62 loc) · 1.08 KB
/
tsvreader_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package tsvreader_test
import (
"bytes"
"fmt"
"github.com/valyala/tsvreader"
)
func ExampleReader() {
bs := bytes.NewBufferString(
"foo\t42\n" +
"bar\t123\n")
r := tsvreader.New(bs)
for r.Next() {
col1 := r.String()
col2 := r.Int()
fmt.Printf("col1=%s, col2=%d\n", col1, col2)
}
if err := r.Error(); err != nil {
fmt.Printf("unexpected error: %s", err)
}
// Output:
// col1=foo, col2=42
// col1=bar, col2=123
}
func ExampleReader_HasCols() {
bs := bytes.NewBufferString(
"foo\n" +
"bar\tbaz\n" +
"\n" +
"a\tb\tc\n")
r := tsvreader.New(bs)
for r.Next() {
for r.HasCols() {
s := r.String()
fmt.Printf("%q,", s)
}
fmt.Printf("\n")
}
if err := r.Error(); err != nil {
fmt.Printf("unexpected error: %s", err)
}
// Output:
// "foo",
// "bar","baz",
//
// "a","b","c",
}
func ExampleReader_Next() {
bs := bytes.NewBufferString("1\n2\n3\n42\n")
r := tsvreader.New(bs)
for r.Next() {
n := r.Int()
fmt.Printf("%d\n", n)
}
if err := r.Error(); err != nil {
fmt.Printf("unexpected error: %s", err)
}
// Output:
// 1
// 2
// 3
// 42
}