-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathformat_test.go
49 lines (38 loc) · 1 KB
/
format_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
package maputil_test
import (
"fmt"
"testing"
"github.com/gookit/goutil/maputil"
"github.com/gookit/goutil/testutil"
"github.com/gookit/goutil/testutil/assert"
)
func TestNewFormatter(t *testing.T) {
mp := map[string]any{"a": "v0", "b": 23}
mf := maputil.NewFormatter(mp)
assert.Contains(t, mf.String(), "b:23")
buf := testutil.NewTestWriter()
mf = maputil.NewFormatter(mp).WithFn(func(f *maputil.MapFormatter) {
f.Indent = " "
})
mf.FormatTo(buf)
assert.Contains(t, buf.String(), "\n ")
fmt.Println(buf.String())
s := maputil.FormatIndent(mp, " ")
fmt.Println(s)
assert.Contains(t, s, "\n ")
s = maputil.FormatIndent(mp, "")
fmt.Println(s)
assert.NotContains(t, s, "\n ")
}
func TestFormatIndent_mlevel(t *testing.T) {
mp := map[string]any{"a": "v0", "b": 23}
mp["subs"] = map[string]string{
"sub_k1": "sub val1",
"sub_k2": "sub val2",
}
s := maputil.FormatIndent(mp, "")
fmt.Println(s)
assert.NotContains(t, s, "\n ")
s = maputil.FormatIndent(mp, " ")
fmt.Println(s)
}