-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
52 lines (48 loc) · 846 Bytes
/
main_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 main
import (
"testing"
)
func TestCleanTrailingCommas(t *testing.T) {
cases := []struct {
name string
input string
output string
}{
{
name: "nothing to do",
input: `{"foo": "bar"}`,
output: `{"foo": "bar"}`,
},
{
name: "trailing comma in object",
input: `{"foo": "bar",}`,
output: `{"foo": "bar"}`,
},
{
name: "trailing comman in array",
input: `[1,2,3,]`,
output: `[1,2,3]`,
},
{
name: "newlines don't matter",
input: `{
"foo": 1,
}`,
output: `{
"foo": 1
}`,
},
}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
out, err := cleanTrailingCommas([]byte(c.input))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if string(out) != c.output {
t.Errorf("incorrect output: %s", out)
}
})
}
}