-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
escape_test.go
53 lines (42 loc) · 966 Bytes
/
escape_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
package memviz
import (
"bytes"
"fmt"
"github.com/bradleyjkemp/cupaloy/v2"
"testing"
"github.com/stretchr/testify/assert"
)
var cases = []struct {
input string
output string
}{
{"Hello world", "Hello world"},
// double quotes are escaped
{"\"Hello world\"", "\\\"Hello world\\\""},
// brackets not escaped
{"map[string]bool", "map[string]bool"},
// braces escaped
{"map[string]struct{}", "map[string]struct\\{\\}"},
}
func TestEscapeString(t *testing.T) {
for _, tc := range cases {
assert.Equal(t, tc.output, escapeString(tc.input))
}
}
func TestEmptyStruct(t *testing.T) {
set := make([]struct{}, 2)
set[0] = struct{}{}
set[1] = struct{}{}
b := &bytes.Buffer{}
Map(b, &set)
fmt.Println(b.String())
cupaloy.SnapshotT(t, b.Bytes())
}
func TestEmptyInterface(t *testing.T) {
set := map[string]interface{}{}
set["hello world"] = nil
b := &bytes.Buffer{}
Map(b, &set)
fmt.Println(b.String())
cupaloy.SnapshotT(t, b.Bytes())
}