1
+ using System . Linq ;
2
+ using System . Threading ;
3
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
4
+ using Rubberduck . Parsing . Symbols ;
5
+ using Rubberduck . Parsing . VBA ;
6
+ using Rubberduck . VBEditor ;
7
+ using Rubberduck . VBEditor . SafeComWrappers ;
8
+ using RubberduckTests . Mocks ;
9
+
10
+ namespace RubberduckTests . Symbols
11
+ {
12
+ [ TestClass ]
13
+ public class DeclarationFinderTests
14
+ {
15
+ [ TestMethod ]
16
+ [ Ignore ] // ref. https://github.com/rubberduck-vba/Rubberduck/issues/2330
17
+ public void FiendishlyAmbiguousNameSelectsSmallestScopedDeclaration ( )
18
+ {
19
+ var code = @"
20
+ Option Explicit
21
+
22
+ Public Sub foo()
23
+ Dim foo As Long
24
+ foo = 42
25
+ Debug.Print foo
26
+ End Sub
27
+ " ;
28
+ var vbe = new MockVbeBuilder ( )
29
+ . ProjectBuilder ( "foo" , ProjectProtection . Unprotected )
30
+ . AddComponent ( "foo" , ComponentType . StandardModule , code , new Selection ( 6 , 6 ) )
31
+ . MockVbeBuilder ( )
32
+ . Build ( ) ;
33
+
34
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object ) ) ;
35
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
36
+
37
+ var expected = parser . State . AllDeclarations . Single ( item => item . DeclarationType == DeclarationType . Variable ) ;
38
+ var actual = parser . State . DeclarationFinder . FindSelectedDeclaration ( vbe . Object . ActiveCodePane ) ;
39
+
40
+ Assert . AreEqual ( expected , actual , "Expected {0}, resolved to {1}" , expected . DeclarationType , actual . DeclarationType ) ;
41
+ }
42
+
43
+ [ TestMethod ]
44
+ [ Ignore ] // bug: this test should pass... it's not all that evil
45
+ public void AmbiguousNameSelectsSmallestScopedDeclaration ( )
46
+ {
47
+ var code = @"
48
+ Option Explicit
49
+
50
+ Public Sub foo()
51
+ Dim foo As Long
52
+ foo = 42
53
+ Debug.Print foo
54
+ End Sub
55
+ " ;
56
+ var vbe = new MockVbeBuilder ( )
57
+ . ProjectBuilder ( "TestProject" , ProjectProtection . Unprotected )
58
+ . AddComponent ( "TestModule" , ComponentType . StandardModule , code , new Selection ( 6 , 6 ) )
59
+ . MockVbeBuilder ( )
60
+ . Build ( ) ;
61
+
62
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( vbe . Object ) ) ;
63
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
64
+
65
+ var expected = parser . State . AllDeclarations . Single ( item => item . DeclarationType == DeclarationType . Variable ) ;
66
+ var actual = parser . State . DeclarationFinder . FindSelectedDeclaration ( vbe . Object . ActiveCodePane ) ;
67
+
68
+ Assert . AreEqual ( expected , actual , "Expected {0}, resolved to {1}" , expected . DeclarationType , actual . DeclarationType ) ;
69
+ }
70
+ }
71
+ }
0 commit comments