Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/fuzz/component/value_test.go
2070 views
1
package component
2
3
import (
4
"testing"
5
6
"github.com/leslie-qiwa/flat"
7
"github.com/stretchr/testify/require"
8
)
9
10
func TestFlatMap_FlattenUnflatten(t *testing.T) {
11
data := map[string]interface{}{
12
"foo": "bar",
13
"bar": map[string]interface{}{
14
"baz": "foo",
15
},
16
"slice": []interface{}{
17
"foo",
18
"bar",
19
},
20
"with.dot": map[string]interface{}{
21
"foo": "bar",
22
},
23
}
24
25
opts := &flat.Options{
26
Safe: true,
27
Delimiter: "~",
28
}
29
flattened, err := flat.Flatten(data, opts)
30
if err != nil {
31
t.Fatal(err)
32
}
33
34
nested, err := flat.Unflatten(flattened, opts)
35
if err != nil {
36
t.Fatal(err)
37
}
38
require.Equal(t, data, nested, "unexpected data")
39
}
40
41
func TestAnySlice(t *testing.T) {
42
data := []any{}
43
data = append(data, []int{1, 2, 3})
44
data = append(data, []string{"foo", "bar"})
45
data = append(data, []bool{true, false})
46
data = append(data, []float64{1.1, 2.2, 3.3})
47
48
for _, d := range data {
49
val, ok := IsTypedSlice(d)
50
require.True(t, ok, "expected slice")
51
require.True(t, val != nil, "expected value but got nil")
52
}
53
}
54
55