You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1000 B
Go
49 lines
1000 B
Go
1 year ago
|
package nmap_test
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"git.noahlan.cn/noahlan/ntool/nmap"
|
||
|
"git.noahlan.cn/noahlan/ntool/ntest"
|
||
|
"git.noahlan.cn/noahlan/ntool/ntest/assert"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestNewFormatter(t *testing.T) {
|
||
|
mp := map[string]any{"a": "v0", "b": 23}
|
||
|
|
||
|
mf := nmap.NewFormatter(mp)
|
||
|
assert.Contains(t, mf.String(), "b:23")
|
||
|
|
||
|
buf := ntest.NewTestWriter()
|
||
|
mf = nmap.NewFormatter(mp).WithFn(func(f *nmap.MapFormatter) {
|
||
|
f.Indent = " "
|
||
|
})
|
||
|
mf.FormatTo(buf)
|
||
|
assert.Contains(t, buf.String(), "\n ")
|
||
|
fmt.Println(buf.String())
|
||
|
|
||
|
s := nmap.FormatIndent(mp, " ")
|
||
|
fmt.Println(s)
|
||
|
assert.Contains(t, s, "\n ")
|
||
|
|
||
|
s = nmap.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 := nmap.FormatIndent(mp, "")
|
||
|
fmt.Println(s)
|
||
|
assert.NotContains(t, s, "\n ")
|
||
|
|
||
|
s = nmap.FormatIndent(mp, " ")
|
||
|
fmt.Println(s)
|
||
|
}
|