@@ -188,6 +188,70 @@ func testVariable() {
188188 let result = try variable. resolve ( context) as? Int
189189 try expect ( result) == 2
190190 }
191+
192+ $0. describe ( " Indirection " ) {
193+ $0. it ( " can resolve an indirect variable " ) {
194+ try context. push ( dictionary: [ " property " : " name " ] ) {
195+ let variable = Variable ( " $property " )
196+ let result = try variable. resolve ( context) as? String
197+ try expect ( result) == " Kyle "
198+ }
199+ }
200+
201+ $0. it ( " can resolve an indirect variable via reflection " ) {
202+ try context. push ( dictionary: [ " property " : " name " ] ) {
203+ let variable = Variable ( " article.author.$property " )
204+ let result = try variable. resolve ( context) as? String
205+ try expect ( result) == " Kyle "
206+ }
207+ }
208+
209+ $0. it ( " can resolve an item from an array via it's indirect index " ) {
210+ try context. push ( dictionary: [ " property " : 0 ] ) {
211+ let variable = Variable ( " contacts.$property " )
212+ let result = try variable. resolve ( context) as? String
213+ try expect ( result) == " Katie "
214+ }
215+ }
216+
217+ $0. it ( " can resolve an item from an array via unknown index " ) {
218+ try context. push ( dictionary: [ " property " : 5 ] ) {
219+ let variable = Variable ( " contacts.$property " )
220+ let result = try variable. resolve ( context) as? String
221+ try expect ( result) . to. beNil ( )
222+ }
223+ }
224+
225+ #if os(OSX)
226+ $0. it ( " can resolve an indirect variable via KVO " ) {
227+ try context. push ( dictionary: [ " property " : " name " ] ) {
228+ let variable = Variable ( " object.$property " )
229+ let result = try variable. resolve ( context) as? String
230+ try expect ( result) == " Foo "
231+ }
232+ }
233+ #endif
234+
235+ $0. it ( " can resolve a value via reflection " ) {
236+ try context. push ( dictionary: [ " property " : " articles " ] ) {
237+ let variable = Variable ( " blog.$property.0.author.name " )
238+ let result = try variable. resolve ( context) as? String
239+ try expect ( result) == " Kyle "
240+ }
241+ }
242+
243+ $0. it ( " can resolve multiple indirections " ) {
244+ try context. push ( dictionary: [
245+ " prop1 " : " articles " ,
246+ " prop2 " : 0 ,
247+ " prop3 " : " name "
248+ ] ) {
249+ let variable = Variable ( " blog.$prop1.$prop2.author.$prop3 " )
250+ let result = try variable. resolve ( context) as? String
251+ try expect ( result) == " Kyle "
252+ }
253+ }
254+ }
191255 }
192256
193257 describe ( " RangeVariable " ) {
0 commit comments