6464 var context = visitor . Visit ( tree ) . First ( ) ;
6565 var selection = new Selection ( 3 , 0 , 10 , 5 ) ;
6666
67- Assert . IsFalse ( context . Contains ( selection ) ) ;
67+ Assert . IsFalse ( selection . Contains ( context ) ) ;
68+ Assert . IsFalse ( selection . IsContainedIn ( context ) ) ;
6869 }
6970
7071 [ TestMethod ]
9293 var context = visitor . Visit ( tree ) . First ( ) ;
9394 var selection = new Selection ( 4 , 1 , 11 , 8 ) ;
9495
95- Assert . IsTrue ( context . Contains ( selection ) ) ;
96+ Assert . IsTrue ( selection . Contains ( context ) ) ;
97+ Assert . IsFalse ( selection . IsContainedIn ( context ) ) ;
9698 }
9799
98100 [ TestMethod ]
@@ -120,7 +122,8 @@ End _
120122 var context = visitor . Visit ( tree ) . First ( ) ;
121123 var selection = new Selection ( 5 , 1 , 11 , 8 ) ;
122124
123- Assert . IsFalse ( context . Contains ( selection ) ) ;
125+ Assert . IsFalse ( selection . Contains ( context ) ) ;
126+ Assert . IsFalse ( selection . IsContainedIn ( context ) ) ;
124127 }
125128
126129 [ TestMethod ]
@@ -148,7 +151,8 @@ End _
148151 var context = visitor . Visit ( tree ) . First ( ) ;
149152 var selection = new Selection ( 4 , 1 , 10 , 8 ) ;
150153
151- Assert . IsFalse ( context . Contains ( selection ) ) ;
154+ Assert . IsFalse ( selection . Contains ( context ) ) ;
155+ Assert . IsTrue ( selection . IsContainedIn ( context ) ) ;
152156 }
153157
154158 [ TestMethod ]
@@ -175,9 +179,11 @@ End _
175179 var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
176180 var visitor = new SubStmtContextElementCollectorVisitor ( ) ;
177181 var context = visitor . Visit ( tree ) . First ( ) ;
178- pane . Selection = new Selection ( 4 , 1 , 11 , 8 ) ;
182+ pane . Selection = new Selection ( 4 , 1 , 11 , 6 ) ;
179183
180- Assert . IsTrue ( context . Contains ( pane . Selection ) ) ;
184+ Assert . IsTrue ( context . GetSelection ( ) . Contains ( pane . Selection ) ) ;
185+ Assert . IsTrue ( pane . Selection . IsContainedIn ( context ) ) ;
186+ Assert . IsTrue ( pane . Selection . Contains ( context ) ) ;
181187 }
182188
183189 [ TestMethod ]
@@ -203,7 +209,9 @@ Public Sub foo()
203209 var context = visitor . Visit ( tree ) . First ( ) ;
204210 pane . Selection = new Selection ( 3 , 0 , 7 , 7 ) ;
205211
206- Assert . IsFalse ( context . Contains ( pane . Selection ) ) ;
212+ Assert . IsFalse ( context . GetSelection ( ) . Contains ( pane . Selection ) ) ;
213+ Assert . IsFalse ( pane . Selection . IsContainedIn ( context ) ) ;
214+ Assert . IsFalse ( pane . Selection . Contains ( context ) ) ;
207215 }
208216
209217 [ TestMethod ]
@@ -229,7 +237,9 @@ Public Sub foo()
229237 var context = visitor . Visit ( tree ) . First ( ) ;
230238 pane . Selection = new Selection ( 4 , 1 , 8 , 8 ) ;
231239
232- Assert . IsTrue ( context . Contains ( pane . Selection ) ) ;
240+ Assert . IsTrue ( context . GetSelection ( ) . Contains ( pane . Selection ) ) ;
241+ Assert . IsTrue ( pane . Selection . IsContainedIn ( context ) ) ;
242+ Assert . IsTrue ( pane . Selection . Contains ( context ) ) ;
233243 }
234244
235245 [ TestMethod ]
@@ -255,13 +265,14 @@ Public Sub foo()
255265 var context = visitor . Visit ( tree ) . First ( ) ;
256266 var selection = new Selection ( 4 , 1 , 8 , 8 ) ;
257267
258- Assert . IsTrue ( context . Contains ( selection ) ) ;
268+ Assert . IsTrue ( selection . Contains ( context ) ) ;
269+ Assert . IsTrue ( selection . IsContainedIn ( context ) ) ;
259270 }
260271
261272 [ TestMethod ]
262273 [ TestCategory ( "Grammar" ) ]
263274 [ TestCategory ( "Selection" ) ]
264- public void Context_NotIn_Selection_StartTooSoon_OneBased ( )
275+ public void Context_NotIn_Selection_StartTooLate_OneBased ( )
265276 {
266277 const string inputCode = @"
267278Option Explicit
@@ -281,7 +292,8 @@ Public Sub foo()
281292 var context = visitor . Visit ( tree ) . First ( ) ;
282293 var selection = new Selection ( 4 , 2 , 8 , 8 ) ;
283294
284- Assert . IsFalse ( context . Contains ( selection ) ) ;
295+ Assert . IsFalse ( selection . Contains ( context ) ) ;
296+ Assert . IsTrue ( selection . IsContainedIn ( context ) ) ;
285297 }
286298
287299 [ TestMethod ]
@@ -307,7 +319,8 @@ Public Sub foo()
307319 var context = visitor . Visit ( tree ) . First ( ) ;
308320 var selection = new Selection ( 4 , 1 , 8 , 7 ) ;
309321
310- Assert . IsFalse ( context . Contains ( selection ) ) ;
322+ Assert . IsFalse ( selection . Contains ( context ) ) ;
323+ Assert . IsTrue ( selection . IsContainedIn ( context ) ) ;
311324 }
312325
313326 [ TestMethod ]
@@ -342,8 +355,8 @@ End If
342355 var contexts = visitor . Visit ( tree ) ;
343356 var selection = new Selection ( 6 , 1 , 10 , 7 ) ;
344357
345- Assert . IsTrue ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // first If block
346- Assert . IsFalse ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // second If block
358+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 0 ) ) ) ; // first If block
359+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 1 ) ) ) ; // second If block
347360 }
348361
349362 [ TestMethod ]
@@ -379,8 +392,8 @@ End If
379392 var contexts = visitor . Visit ( tree ) ;
380393 var selection = new Selection ( 6 , 1 , 10 , 7 ) ;
381394
382- Assert . IsTrue ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // first If block
383- Assert . IsFalse ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // second If block
395+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 0 ) ) ) ; // first If block
396+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 1 ) ) ) ; // second If block
384397 }
385398
386399 [ TestMethod ]
@@ -416,8 +429,8 @@ End If
416429 var contexts = visitor . Visit ( tree ) ;
417430 var selection = new Selection ( 12 , 1 , 16 , 7 ) ;
418431
419- Assert . IsFalse ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // first If block
420- Assert . IsTrue ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // second If block
432+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 0 ) ) ) ; // first If block
433+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 1 ) ) ) ; // second If block
421434 }
422435
423436 [ TestMethod ]
@@ -455,8 +468,8 @@ End If
455468 var selection = new Selection ( 12 , 1 , 16 , 7 ) ;
456469
457470 Assert . IsTrue ( selection . Contains ( token ) ) ; // last token in second If block
458- Assert . IsFalse ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // first If block
459- Assert . IsTrue ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // second If block
471+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 0 ) ) ) ; // first If block
472+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 1 ) ) ) ; // second If block
460473 }
461474
462475 [ TestMethod ]
@@ -534,9 +547,9 @@ End If
534547 var selection = new Selection ( 8 , 1 , 10 , 9 ) ;
535548
536549 Assert . IsTrue ( selection . Contains ( token ) ) ; // last token in innermost If block
537- Assert . IsTrue ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // innermost If block
538- Assert . IsFalse ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // first outer If block
539- Assert . IsFalse ( contexts . ElementAt ( 2 ) . Contains ( selection ) ) ; // second outer If block
550+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 0 ) ) ) ; // innermost If block
551+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 1 ) ) ) ; // first outer If block
552+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 2 ) ) ) ; // second outer If block
540553 }
541554
542555 [ TestMethod ]
@@ -577,9 +590,9 @@ End If
577590 var selection = new Selection ( 6 , 1 , 13 , 7 ) ;
578591
579592 Assert . IsTrue ( selection . Contains ( token ) ) ; // last token in innermost If block
580- Assert . IsTrue ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // innermost If block
581- Assert . IsTrue ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // first outer If block
582- Assert . IsFalse ( contexts . ElementAt ( 2 ) . Contains ( selection ) ) ; // second outer If block
593+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 0 ) ) ) ; // innermost If block
594+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 1 ) ) ) ; // first outer If block
595+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 2 ) ) ) ; // second outer If block
583596 }
584597
585598 [ TestMethod ]
@@ -620,9 +633,9 @@ End If
620633 var selection = new Selection ( 15 , 1 , 19 , 7 ) ;
621634
622635 Assert . IsFalse ( selection . Contains ( token ) ) ; // last token in innermost If block
623- Assert . IsFalse ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // innermost If block
624- Assert . IsFalse ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // first outer if block
625- Assert . IsTrue ( contexts . ElementAt ( 2 ) . Contains ( selection ) ) ; // second outer If block
636+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 0 ) ) ) ; // innermost If block
637+ Assert . IsFalse ( selection . Contains ( contexts . ElementAt ( 1 ) ) ) ; // first outer if block
638+ Assert . IsTrue ( selection . Contains ( contexts . ElementAt ( 2 ) ) ) ; // second outer If block
626639 }
627640 }
628641}
0 commit comments