@@ -339,10 +339,11 @@ End If
339
339
var state = MockParser . CreateAndParse ( vbe . Object ) ;
340
340
var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
341
341
var visitor = new IfStmtContextElementCollectorVisitor ( ) ;
342
- var context = visitor . Visit ( tree ) . First ( ) ;
342
+ var contexts = visitor . Visit ( tree ) ;
343
343
var selection = new Selection ( 6 , 1 , 10 , 7 ) ;
344
344
345
- Assert . IsTrue ( context . Contains ( selection ) ) ;
345
+ Assert . IsTrue ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // first If block
346
+ Assert . IsFalse ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // second If block
346
347
}
347
348
348
349
[ TestMethod ]
@@ -375,10 +376,11 @@ End If
375
376
var state = MockParser . CreateAndParse ( vbe . Object ) ;
376
377
var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
377
378
var visitor = new IfStmtContextElementCollectorVisitor ( ) ;
378
- var context = visitor . Visit ( tree ) . Last ( ) ;
379
+ var contexts = visitor . Visit ( tree ) ;
379
380
var selection = new Selection ( 6 , 1 , 10 , 7 ) ;
380
381
381
- Assert . IsFalse ( context . Contains ( selection ) ) ;
382
+ Assert . IsTrue ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // first If block
383
+ Assert . IsFalse ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // second If block
382
384
}
383
385
384
386
[ TestMethod ]
@@ -411,10 +413,11 @@ End If
411
413
var state = MockParser . CreateAndParse ( vbe . Object ) ;
412
414
var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
413
415
var visitor = new IfStmtContextElementCollectorVisitor ( ) ;
414
- var context = visitor . Visit ( tree ) . Last ( ) ;
416
+ var contexts = visitor . Visit ( tree ) ;
415
417
var selection = new Selection ( 12 , 1 , 16 , 7 ) ;
416
418
417
- Assert . IsTrue ( context . Contains ( selection ) ) ;
419
+ Assert . IsFalse ( contexts . ElementAt ( 0 ) . Contains ( selection ) ) ; // first If block
420
+ Assert . IsTrue ( contexts . ElementAt ( 1 ) . Contains ( selection ) ) ; // second If block
418
421
}
419
422
420
423
[ TestMethod ]
@@ -447,11 +450,13 @@ End If
447
450
var state = MockParser . CreateAndParse ( vbe . Object ) ;
448
451
var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
449
452
var visitor = new IfStmtContextElementCollectorVisitor ( ) ;
450
- var context = visitor . Visit ( tree ) . Last ( ) ;
451
- var token = context . Stop ;
453
+ var contexts = visitor . Visit ( tree ) ;
454
+ var token = contexts . ElementAt ( 1 ) . Stop ;
452
455
var selection = new Selection ( 12 , 1 , 16 , 7 ) ;
453
456
454
- Assert . IsTrue ( selection . Contains ( token ) ) ;
457
+ 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
455
460
}
456
461
457
462
[ TestMethod ]
@@ -494,7 +499,7 @@ End If
494
499
[ TestMethod ]
495
500
[ TestCategory ( "Grammar" ) ]
496
501
[ TestCategory ( "Selection" ) ]
497
- public void Selection__Contains_Only_Innermost_Nested_Context ( )
502
+ public void Selection_Contains_Only_Innermost_Nested_Context ( )
498
503
{
499
504
const string inputCode = @"
500
505
Option Explicit
@@ -524,17 +529,20 @@ End If
524
529
var state = MockParser . CreateAndParse ( vbe . Object ) ;
525
530
var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
526
531
var visitor = new IfStmtContextElementCollectorVisitor ( ) ;
527
- var context = visitor . Visit ( tree ) . First ( ) ; //returns innermost statement first then topmost consecutively
528
- var token = context . Stop ;
532
+ var contexts = visitor . Visit ( tree ) ;
533
+ var token = contexts . ElementAt ( 0 ) . Stop ;
529
534
var selection = new Selection ( 8 , 1 , 10 , 9 ) ;
530
535
531
- Assert . IsTrue ( selection . Contains ( token ) ) ;
536
+ 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
532
540
}
533
541
534
542
[ TestMethod ]
535
543
[ TestCategory ( "Grammar" ) ]
536
544
[ TestCategory ( "Selection" ) ]
537
- public void Selection__Contains_Both_Nested_Context ( )
545
+ public void Selection_Contains_Both_Nested_Context ( )
538
546
{
539
547
const string inputCode = @"
540
548
Option Explicit
@@ -564,11 +572,14 @@ End If
564
572
var state = MockParser . CreateAndParse ( vbe . Object ) ;
565
573
var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
566
574
var visitor = new IfStmtContextElementCollectorVisitor ( ) ;
567
- var context = visitor . Visit ( tree ) . First ( ) ; //returns innermost statement first then topmost consecutively
568
- var token = context . Stop ;
575
+ var contexts = visitor . Visit ( tree ) ; //returns innermost statement first then topmost consecutively
576
+ var token = contexts . ElementAt ( 0 ) . Stop ;
569
577
var selection = new Selection ( 6 , 1 , 13 , 7 ) ;
570
578
571
- Assert . IsTrue ( selection . Contains ( token ) ) ;
579
+ 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
572
583
}
573
584
574
585
[ TestMethod ]
@@ -604,11 +615,14 @@ End If
604
615
var state = MockParser . CreateAndParse ( vbe . Object ) ;
605
616
var tree = state . GetParseTree ( new QualifiedModuleName ( component ) ) ;
606
617
var visitor = new IfStmtContextElementCollectorVisitor ( ) ;
607
- var context = visitor . Visit ( tree ) . First ( ) ; //returns innermost statement first then topmost consecutively
608
- var token = context . Stop ;
618
+ var contexts = visitor . Visit ( tree ) ; //returns innermost statement first then topmost consecutively
619
+ var token = contexts . ElementAt ( 0 ) . Stop ;
609
620
var selection = new Selection ( 15 , 1 , 19 , 7 ) ;
610
621
611
- Assert . IsFalse ( selection . Contains ( token ) ) ;
622
+ 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
612
626
}
613
627
}
614
628
}
0 commit comments