-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag_test.go
74 lines (66 loc) · 1.98 KB
/
tag_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
package rjson
import (
"fmt"
"os"
"testing"
assert "github.com/BatteredBunny/testingassert"
)
type testStruct struct {
One string `rjson:"uwu.nya"`
Two int `rjson:"one.two.three.num"`
Three []string `rjson:"one.arr"`
Four string `rjson:"one.arr[0]"`
Five string `rjson:"jarray[0].mrow"`
Six []string `rjson:"combined[].str"`
Seven []int `rjson:"combined[]num"`
Eight struct {
Text string `rjson:"nya"`
} `rjson:"uwu"`
Nine []struct {
Text string `rjson:"str"`
} `rjson:"combined"`
Ten string `rjson:"combined[-].str"`
Eleven string `rjson:"nestedarr[0].test[0].test"`
Elevenv2 string `rjson:"nestedarr[-].test[-].test"`
Twelve [][]string `rjson:"nesteditter[].thing[].a"`
Twelvev2 [][]string `rjson:"nesteditterv2[].thing.thingv2.thingv3[].a.value"`
Thirteen []string `rjson:"badges[].metadata.value"`
Fourteen struct {
Eight struct {
Text string `rjson:"nya"`
} `rjson:"uwu"`
} `rjson:"."`
}
func TestTag(t *testing.T) {
one := ">_<"
two := 1
three := []string{"mrow", "OWO"}
five := "asdasdasdasd"
bs, err := os.ReadFile("test.json")
if err != nil {
t.Fatal(err)
}
rawJson := fmt.Sprintf(string(bs), one, five, two, three[0], three[1])
var out testStruct
if err := Unmarshal([]byte(rawJson), &out); err != nil {
t.Fatal(err)
}
assert.TestState = t
assert.Equals(out.One, one)
assert.Equals(out.Two, two)
assert.Equals(out.Three, three)
assert.Equals(out.Four, three[0])
assert.Equals(out.Five, five)
assert.Equals(out.Six, []string{"1", "2"})
assert.Equals(out.Seven, []int{1, 2})
assert.Equals(out.Eight.Text, one)
assert.Equals(out.Nine[0].Text, "1")
assert.Equals(out.Nine[1].Text, "2")
assert.Equals(out.Ten, "2")
assert.Equals(out.Eleven, "aaa")
assert.Equals(out.Elevenv2, "aaa")
assert.Equals(out.Twelve, [][]string{{"1", "3"}, {"1", "4"}})
assert.Equals(out.Twelvev2, [][]string{{"1", "3"}, {"1", "4"}})
assert.Equals(out.Thirteen, []string{"Verified"})
assert.Equals(out.Fourteen.Eight.Text, one)
}