-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode_test.go
45 lines (39 loc) · 1.14 KB
/
encode_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
// Copyright 2014 Alvaro J. Genial. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package form
import (
"bytes"
"reflect"
"testing"
)
func TestEncodeToString(t *testing.T) {
for _, c := range testCases(encOnly) {
if s, err := EncodeToString(c.b); err != nil {
t.Errorf("EncodeToString(%v): %s", c.b, err)
} else if !reflect.DeepEqual(c.s, s) {
t.Errorf("EncodeToString(%v)\nwant (%v)\nhave (%v)", c.b, c.s, s)
}
}
}
func TestEncodeToValues(t *testing.T) {
for _, c := range testCases(encOnly) {
cvs := mustParseQuery(c.s)
if vs, err := EncodeToValues(c.b); err != nil {
t.Errorf("EncodeToValues(%v): %s", c.b, err)
} else if !reflect.DeepEqual(cvs, vs) {
t.Errorf("EncodeToValues(%v)\nwant (%v)\nhave (%v)", c.b, cvs, vs)
}
}
}
func TestEncode(t *testing.T) {
for _, c := range testCases(encOnly) {
var w bytes.Buffer
e := NewEncoder(&w)
if err := e.Encode(c.b); err != nil {
t.Errorf("Encode(%v): %s", w, err)
} else if s := w.String(); !reflect.DeepEqual(c.s, s) {
t.Errorf("Encode(%v)\nwant (%v)\nhave (%v)", w, c.s, s)
}
}
}