-
Notifications
You must be signed in to change notification settings - Fork 3
/
udf_test.go
52 lines (49 loc) · 853 Bytes
/
udf_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
package asc
import (
"github.com/stretchr/testify/assert"
"github.com/viant/assertly"
"testing"
)
func TestAsArray(t *testing.T) {
var source = map[string]interface{}{
"k": map[interface{}]interface{}{
"a": 1,
"b": 2,
},
}
array, err := AsArray("k", source)
assert.Nil(t, err)
var expected = `[
{
"@indexBy@":"key"
},
{
"key": "b",
"value": 2
},
{
"key": "a",
"value": 1
}
]`
assertly.AssertValues(t, expected, array)
}
func TestAsJSON(t *testing.T) {
var source = map[string]interface{}{
"k1": []int{1, 2, 3},
"k2": map[interface{}]interface{}{
"a": 1,
"b": 2,
},
}
{
JSON, err := AsJSON("k1", source)
assert.Nil(t, err)
assert.Equal(t, "[\n\t1,\n\t2,\n\t3\n]", JSON)
}
{
JSON, err := AsJSON("k2", source)
assert.Nil(t, err)
assert.Equal(t, "{\n\t\"a\": 1,\n\t\"b\": 2\n}", JSON)
}
}