/
json_test.go
103 lines (83 loc) · 1.96 KB
/
json_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package json
import (
"testing"
"github.com/lmorg/murex/config"
"github.com/lmorg/murex/lang"
"github.com/lmorg/murex/lang/types"
"github.com/lmorg/murex/test"
"github.com/lmorg/murex/test/count"
)
func TestReadArray(t *testing.T) {
input := []byte(`
[
"foo",
"bar"
]`)
expected := []string{
"foo",
"bar",
}
test.ReadArrayTest(t, types.Json, input, expected)
}
func TestReadMap(t *testing.T) {
config := config.NewConfiguration()
input := []byte(`
{
"foo": "oof",
"bar": "rab"
}`)
expected := []test.ReadMapExpected{
{
Key: "foo",
Value: "oof",
Last: true,
},
{
Key: "bar",
Value: "rab",
Last: false,
},
}
test.ReadMapUnorderedTest(t, types.Json, input, expected, config)
}
func TestArrayWriter(t *testing.T) {
input := []string{"foo", "bar"}
output := `["foo","bar"]`
test.ArrayWriterTest(t, types.Json, input, output)
}
func TestMarshalArrayString(t *testing.T) {
count.Tests(t, 1)
input := []string{"e", "d", "c", "b", "a"} // lets prove the output retains sorting
output := `["e","d","c","b","a"]`
lang.InitEnv()
fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_NO_STDERR)
b, err := marshal(fork.Process, input)
if err != nil {
t.Error(err)
return
}
if string(b) != output {
t.Error("Marshaller output doesn't match expected:")
t.Logf(" Input: %v", input)
t.Logf(" Expected: '%s'", output)
t.Logf(" Actual: '%s'", b)
}
}
func TestMarshalArrayInt(t *testing.T) {
count.Tests(t, 1)
input := []int{5, 4, 3, 2, 1} // lets prove the output retains sorting
output := `[5,4,3,2,1]`
lang.InitEnv()
fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_NO_STDERR)
b, err := marshal(fork.Process, input)
if err != nil {
t.Error(err)
return
}
if string(b) != output {
t.Error("Marshaller output doesn't match expected:")
t.Logf(" Input: %v", input)
t.Logf(" Expected: '%s'", output)
t.Logf(" Actual: '%s'", b)
}
}