11package objx
22
33import (
4- "github.com/stretchr/testify/assert"
54 "testing"
5+
6+ "github.com/stretchr/testify/assert"
67)
78
89func TestAccessorsAccessGetSingleField (t * testing.T ) {
9-
1010 current := map [string ]interface {}{"name" : "Tyler" }
11- assert .Equal (t , "Tyler" , access (current , "name" , nil , false , true ))
1211
12+ assert .Equal (t , "Tyler" , access (current , "name" , nil , false , true ))
1313}
14- func TestAccessorsAccessGetDeep (t * testing.T ) {
1514
15+ func TestAccessorsAccessGetDeep (t * testing.T ) {
1616 current := map [string ]interface {}{"name" : map [string ]interface {}{"first" : "Tyler" , "last" : "Bunnell" }}
17+
1718 assert .Equal (t , "Tyler" , access (current , "name.first" , nil , false , true ))
1819 assert .Equal (t , "Bunnell" , access (current , "name.last" , nil , false , true ))
19-
2020}
21- func TestAccessorsAccessGetDeepDeep (t * testing.T ) {
2221
22+ func TestAccessorsAccessGetDeepDeep (t * testing.T ) {
2323 current := map [string ]interface {}{"one" : map [string ]interface {}{"two" : map [string ]interface {}{"three" : map [string ]interface {}{"four" : 4 }}}}
24- assert .Equal (t , 4 , access (current , "one.two.three.four" , nil , false , true ))
2524
25+ assert .Equal (t , 4 , access (current , "one.two.three.four" , nil , false , true ))
2626}
27- func TestAccessorsAccessGetInsideArray (t * testing.T ) {
2827
28+ func TestAccessorsAccessGetInsideArray (t * testing.T ) {
2929 current := map [string ]interface {}{"names" : []interface {}{map [string ]interface {}{"first" : "Tyler" , "last" : "Bunnell" }, map [string ]interface {}{"first" : "Capitol" , "last" : "Bollocks" }}}
30+
3031 assert .Equal (t , "Tyler" , access (current , "names[0].first" , nil , false , true ))
3132 assert .Equal (t , "Bunnell" , access (current , "names[0].last" , nil , false , true ))
3233 assert .Equal (t , "Capitol" , access (current , "names[1].first" , nil , false , true ))
3334 assert .Equal (t , "Bollocks" , access (current , "names[1].last" , nil , false , true ))
34-
3535 assert .Panics (t , func () {
3636 access (current , "names[2]" , nil , false , true )
3737 })
3838 assert .Nil (t , access (current , "names[2]" , nil , false , false ))
39-
4039}
4140
4241func TestAccessorsAccessGetFromArrayWithInt (t * testing.T ) {
43-
4442 current := []interface {}{map [string ]interface {}{"first" : "Tyler" , "last" : "Bunnell" }, map [string ]interface {}{"first" : "Capitol" , "last" : "Bollocks" }}
4543 one := access (current , 0 , nil , false , false )
4644 two := access (current , 1 , nil , false , false )
@@ -49,66 +47,59 @@ func TestAccessorsAccessGetFromArrayWithInt(t *testing.T) {
4947 assert .Equal (t , "Tyler" , one .(map [string ]interface {})["first" ])
5048 assert .Equal (t , "Capitol" , two .(map [string ]interface {})["first" ])
5149 assert .Nil (t , three )
52-
5350}
5451
5552func TestAccessorsGet (t * testing.T ) {
56-
5753 current := New (map [string ]interface {}{"name" : "Tyler" })
58- assert .Equal (t , "Tyler" , current .Get ("name" ).data )
5954
55+ assert .Equal (t , "Tyler" , current .Get ("name" ).data )
6056}
6157
6258func TestAccessorsAccessSetSingleField (t * testing.T ) {
63-
6459 current := map [string ]interface {}{"name" : "Tyler" }
65- access (current , "name" , "Mat" , true , false )
66- assert .Equal (t , current ["name" ], "Mat" )
6760
61+ access (current , "name" , "Mat" , true , false )
6862 access (current , "age" , 29 , true , true )
69- assert .Equal (t , current ["age" ], 29 )
7063
64+ assert .Equal (t , current ["name" ], "Mat" )
65+ assert .Equal (t , current ["age" ], 29 )
7166}
7267
7368func TestAccessorsAccessSetSingleFieldNotExisting (t * testing.T ) {
74-
7569 current := map [string ]interface {}{}
70+
7671 access (current , "name" , "Mat" , true , false )
77- assert .Equal (t , current ["name" ], "Mat" )
7872
73+ assert .Equal (t , current ["name" ], "Mat" )
7974}
8075
8176func TestAccessorsAccessSetDeep (t * testing.T ) {
82-
8377 current := map [string ]interface {}{"name" : map [string ]interface {}{"first" : "Tyler" , "last" : "Bunnell" }}
8478
8579 access (current , "name.first" , "Mat" , true , true )
8680 access (current , "name.last" , "Ryer" , true , true )
8781
8882 assert .Equal (t , "Mat" , access (current , "name.first" , nil , false , true ))
8983 assert .Equal (t , "Ryer" , access (current , "name.last" , nil , false , true ))
90-
9184}
92- func TestAccessorsAccessSetDeepDeep (t * testing.T ) {
9385
86+ func TestAccessorsAccessSetDeepDeep (t * testing.T ) {
9487 current := map [string ]interface {}{"one" : map [string ]interface {}{"two" : map [string ]interface {}{"three" : map [string ]interface {}{"four" : 4 }}}}
9588
9689 access (current , "one.two.three.four" , 5 , true , true )
9790
9891 assert .Equal (t , 5 , access (current , "one.two.three.four" , nil , false , true ))
99-
10092}
101- func TestAccessorsAccessSetArray (t * testing.T ) {
10293
94+ func TestAccessorsAccessSetArray (t * testing.T ) {
10395 current := map [string ]interface {}{"names" : []interface {}{"Tyler" }}
10496
10597 access (current , "names[0]" , "Mat" , true , true )
10698
10799 assert .Equal (t , "Mat" , access (current , "names[0]" , nil , false , true ))
108-
109100}
110- func TestAccessorsAccessSetInsideArray (t * testing.T ) {
111101
102+ func TestAccessorsAccessSetInsideArray (t * testing.T ) {
112103 current := map [string ]interface {}{"names" : []interface {}{map [string ]interface {}{"first" : "Tyler" , "last" : "Bunnell" }, map [string ]interface {}{"first" : "Capitol" , "last" : "Bollocks" }}}
113104
114105 access (current , "names[0].first" , "Mat" , true , true )
@@ -120,11 +111,9 @@ func TestAccessorsAccessSetInsideArray(t *testing.T) {
120111 assert .Equal (t , "Ryer" , access (current , "names[0].last" , nil , false , true ))
121112 assert .Equal (t , "Captain" , access (current , "names[1].first" , nil , false , true ))
122113 assert .Equal (t , "Underpants" , access (current , "names[1].last" , nil , false , true ))
123-
124114}
125115
126116func TestAccessorsAccessSetFromArrayWithInt (t * testing.T ) {
127-
128117 current := []interface {}{map [string ]interface {}{"first" : "Tyler" , "last" : "Bunnell" }, map [string ]interface {}{"first" : "Capitol" , "last" : "Bollocks" }}
129118 one := access (current , 0 , nil , false , false )
130119 two := access (current , 1 , nil , false , false )
@@ -133,13 +122,12 @@ func TestAccessorsAccessSetFromArrayWithInt(t *testing.T) {
133122 assert .Equal (t , "Tyler" , one .(map [string ]interface {})["first" ])
134123 assert .Equal (t , "Capitol" , two .(map [string ]interface {})["first" ])
135124 assert .Nil (t , three )
136-
137125}
138126
139127func TestAccessorsSet (t * testing.T ) {
140-
141128 current := New (map [string ]interface {}{"name" : "Tyler" })
129+
142130 current .Set ("name" , "Mat" )
143- assert .Equal (t , "Mat" , current .Get ("name" ).data )
144131
132+ assert .Equal (t , "Mat" , current .Get ("name" ).data )
145133}
0 commit comments