forked from gobwas/httphead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_test.go
76 lines (68 loc) · 1.37 KB
/
writer_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
73
74
75
76
package httphead
import (
"bufio"
"bytes"
"fmt"
"testing"
)
func ExampleWriteOptions() {
opts := []Option{
NewOption("foo", map[string]string{
"param": "hello, world!",
}),
NewOption("bar", nil),
NewOption("b a z", nil),
}
buf := bytes.Buffer{}
bw := bufio.NewWriter(&buf)
WriteOptions(bw, opts)
bw.Flush()
// Output: foo;param="hello, world!",bar,"b a z"
fmt.Println(buf.String())
}
func TestWriteOptions(t *testing.T) {
for _, test := range []struct {
options []Option
exp string
}{
{
options: []Option{
NewOption("foo", map[string]string{"bar": "baz"}),
},
exp: "foo;bar=baz",
},
{
options: []Option{
NewOption("foo", map[string]string{"bar": "baz"}),
NewOption("a", nil),
NewOption("b", map[string]string{"c": "10"}),
},
exp: "foo;bar=baz,a,b;c=10",
},
{
options: []Option{
NewOption("foo", map[string]string{"a b c": "10,2"}),
},
exp: `foo;"a b c"="10,2"`,
},
{
options: []Option{
NewOption(`"foo"`, nil),
NewOption(`"bar"`, nil),
},
exp: `"\"foo\"","\"bar\""`,
},
} {
t.Run("", func(t *testing.T) {
buf := bytes.Buffer{}
bw := bufio.NewWriter(&buf)
WriteOptions(bw, test.options)
if err := bw.Flush(); err != nil {
t.Fatal(err)
}
if act := buf.String(); act != test.exp {
t.Errorf("WriteOptions = %#q; want %#q", act, test.exp)
}
})
}
}