1
- using System . Linq ;
1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
2
3
using System . Threading ;
3
4
using Microsoft . Vbe . Interop ;
4
5
using Microsoft . VisualStudio . TestTools . UnitTesting ;
5
6
using Moq ;
6
7
using Rubberduck . Inspections ;
7
8
using Rubberduck . Parsing ;
9
+ using Rubberduck . Parsing . Annotations ;
8
10
using Rubberduck . Parsing . Symbols ;
9
11
using Rubberduck . Parsing . VBA ;
10
12
using Rubberduck . VBEditor ;
@@ -16,7 +18,7 @@ namespace RubberduckTests.Inspections
16
18
[ TestClass ]
17
19
public class ImplicitActiveSheetReferenceInspectionTests
18
20
{
19
- [ TestMethod , Ignore ] // doesn't pick up the reference to "Range".
21
+ [ TestMethod ] // doesn't pick up the reference to "Range".
20
22
[ TestCategory ( "Inspections" ) ]
21
23
public void ReportsRange ( )
22
24
{
@@ -29,12 +31,9 @@ End Sub
29
31
30
32
//Arrange
31
33
var builder = new MockVbeBuilder ( ) ;
32
- var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
34
+ var project = builder . ProjectBuilder ( "TestProject1" , "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
33
35
. AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
34
- . AddReference ( "Excel" , string . Empty , true )
35
-
36
- // Apparently, the COM loader can't find it when it isn't actually loaded...
37
- //.AddReference("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", true)
36
+ . AddReference ( "Excel" , "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , true )
38
37
. Build ( ) ;
39
38
var vbe = builder . AddProject ( project ) . Build ( ) ;
40
39
@@ -46,22 +45,55 @@ End Sub
46
45
var excelDeclaration = new ProjectDeclaration ( new QualifiedMemberName ( new QualifiedModuleName ( "Excel" ,
47
46
"C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "Excel" ) , "Excel" ) , "Excel" , true ) ;
48
47
49
- var listColumnDeclaration = new ClassModuleDeclaration ( new QualifiedMemberName (
48
+ var globalDeclaration = new ClassModuleDeclaration ( new QualifiedMemberName (
49
+ new QualifiedModuleName ( "Excel" ,
50
+ "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "_Global" ) ,
51
+ "_Global" ) , excelDeclaration , "_Global" , true , null , null ) ;
52
+
53
+ var globalCoClassDeclarationAttributes = new Attributes ( ) ;
54
+ globalCoClassDeclarationAttributes . AddPredeclaredIdTypeAttribute ( ) ;
55
+ globalCoClassDeclarationAttributes . AddGlobalClassAttribute ( ) ;
56
+
57
+ var globalCoClassDeclaration = new ClassModuleDeclaration ( new QualifiedMemberName (
58
+ new QualifiedModuleName ( "Excel" ,
59
+ "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "Global" ) ,
60
+ "Global" ) , excelDeclaration , "Global" , true , null , globalCoClassDeclarationAttributes ) ;
61
+
62
+ globalDeclaration . AddSubtype ( globalCoClassDeclaration ) ;
63
+ globalCoClassDeclaration . AddSupertype ( globalDeclaration ) ;
64
+ globalCoClassDeclaration . AddSupertype ( "_Global" ) ;
65
+
66
+ var rangeClassModuleDeclaration = new ClassModuleDeclaration ( new QualifiedMemberName (
67
+ new QualifiedModuleName ( "Excel" ,
68
+ "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "Range" ) ,
69
+ "Range" ) , excelDeclaration , "Range" , true , new List < IAnnotation > ( ) , new Attributes ( ) ) ;
70
+
71
+ var rangeDeclaration = new PropertyGetDeclaration ( new QualifiedMemberName (
72
+ new QualifiedModuleName ( "Excel" ,
73
+ "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "_Global" ) , "Range" ) ,
74
+ globalDeclaration , globalDeclaration , "Range" , null , null , Accessibility . Global , null , Selection . Home ,
75
+ false , true , new List < IAnnotation > ( ) , new Attributes ( ) ) ;
76
+
77
+ var firstParamDeclaration = new ParameterDeclaration ( new QualifiedMemberName (
78
+ new QualifiedModuleName ( "Excel" ,
79
+ "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "_Global" ) ,
80
+ "Cell1" ) , rangeDeclaration , "Variant" , null , null , false , false ) ;
81
+
82
+ var secondParamDeclaration = new ParameterDeclaration ( new QualifiedMemberName (
50
83
new QualifiedModuleName ( "Excel" ,
51
- "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "ListColumn " ) ,
52
- "ListColumn " ) , excelDeclaration , "ListColumn " , true , null , null ) ;
84
+ "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "_Global " ) ,
85
+ "Cell2 " ) , rangeDeclaration , "Variant " , null , null , true , false ) ;
53
86
54
- var rangeDeclaration =
55
- new Declaration (
56
- new QualifiedMemberName (
57
- new QualifiedModuleName ( "Excel" ,
58
- "C:\\ Program Files\\ Microsoft Office\\ Root\\ Office 16\\ EXCEL.EXE" , "ListColumn" ) , "Range" ) ,
59
- listColumnDeclaration , "EXCEL.EXE;Excel.ListColumn" , "Range" , null , false , false , Accessibility . Global ,
60
- ( DeclarationType ) 3712 , false , null , true , null , new Attributes ( ) ) ;
87
+ rangeDeclaration . AddParameter ( firstParamDeclaration ) ;
88
+ rangeDeclaration . AddParameter ( secondParamDeclaration ) ;
61
89
62
90
parser . State . AddDeclaration ( excelDeclaration ) ;
63
- parser . State . AddDeclaration ( listColumnDeclaration ) ;
91
+ parser . State . AddDeclaration ( globalDeclaration ) ;
92
+ parser . State . AddDeclaration ( globalCoClassDeclaration ) ;
93
+ parser . State . AddDeclaration ( rangeClassModuleDeclaration ) ;
64
94
parser . State . AddDeclaration ( rangeDeclaration ) ;
95
+ parser . State . AddDeclaration ( firstParamDeclaration ) ;
96
+ parser . State . AddDeclaration ( secondParamDeclaration ) ;
65
97
66
98
parser . Parse ( new CancellationTokenSource ( ) ) ;
67
99
if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
0 commit comments