-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder_test.go
More file actions
42 lines (35 loc) · 873 Bytes
/
encoder_test.go
File metadata and controls
42 lines (35 loc) · 873 Bytes
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
package zon
import (
"bytes"
"strings"
"testing"
)
func TestEncoder(t *testing.T) {
for _, tt := range []struct {
name string
input map[string]int
want string
}{
{"key with dot", map[string]int{".a": 1}, ".{\n .a = 1,\n}\n"},
{"key without dot", map[string]int{"b": 2}, ".{\n .b = 2,\n}\n"},
} {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
enc := NewEncoder(&buf)
if err := enc.Encode(tt.input); err != nil {
t.Errorf("Encoder.Encode returned error: %v", err)
}
if buf.Len() == 0 {
t.Error("Encoder.Encode wrote no data")
}
for k := range tt.input {
if !strings.Contains(buf.String(), k) {
t.Errorf("Encoded output does not contain key %q: %s", k, buf.String())
}
}
if got := buf.String(); got != tt.want {
t.Fatalf("buf.String() = %q, want %q", got, tt.want)
}
})
}
}