8
8
using Rubberduck . Navigation . CodeExplorer ;
9
9
using Rubberduck . Parsing . VBA ;
10
10
using Rubberduck . Settings ;
11
+ using Rubberduck . SmartIndenter ;
11
12
using Rubberduck . UI ;
12
13
using Rubberduck . UI . CodeExplorer . Commands ;
13
14
using Rubberduck . UnitTesting ;
14
15
using Rubberduck . VBEditor . VBEHost ;
16
+ using Rubberduck . VBEditor . Extensions ;
15
17
using RubberduckTests . Mocks ;
16
18
17
19
namespace RubberduckTests . CodeExplorer
@@ -136,6 +138,50 @@ public void RemoveModule_Cancel()
136
138
Assert . IsTrue ( vbComponents . Count ( c => c . Type == vbext_ComponentType . vbext_ct_StdModule ) == 0 ) ;
137
139
}
138
140
141
+ [ TestMethod ]
142
+ public void IndentModule ( )
143
+ {
144
+ var inputCode =
145
+ @"Sub Foo()
146
+ Dim d As Boolean
147
+ d = True
148
+ End Sub" ;
149
+
150
+ var expectedCode =
151
+ @"Sub Foo()
152
+ Dim d As Boolean
153
+ d = True
154
+ End Sub" ;
155
+
156
+ var builder = new MockVbeBuilder ( ) ;
157
+ VBComponent component ;
158
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
159
+ var mockHost = new Mock < IHostApplication > ( ) ;
160
+ mockHost . SetupAllProperties ( ) ;
161
+ var project = vbe . Object . VBProjects . Item ( 0 ) ;
162
+ var module = project . VBComponents . Item ( 0 ) . CodeModule ;
163
+
164
+ var configLoader = new Mock < ConfigurationLoader > ( null , null ) ;
165
+ configLoader . Setup ( c => c . LoadConfiguration ( ) ) . Returns ( GetDefaultUnitTestConfig ( ) ) ;
166
+
167
+ var state = new RubberduckParserState ( ) ;
168
+ var commands = new List < ICommand >
169
+ {
170
+ new CodeExplorer_IndentCommand ( state , new Indenter ( vbe . Object , GetDefaultIndenterSettings ) , null )
171
+ } ;
172
+
173
+ var vm = new CodeExplorerViewModel ( state , commands ) ;
174
+
175
+ var parser = MockParser . Create ( vbe . Object , state ) ;
176
+ parser . Parse ( ) ;
177
+ if ( parser . State . Status == ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
178
+
179
+ vm . SelectedItem = vm . Projects . First ( ) . Items . First ( ) . Items . First ( ) ;
180
+ vm . IndenterCommand . Execute ( vm . SelectedItem ) ;
181
+
182
+ Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
183
+ }
184
+
139
185
#region
140
186
private Configuration GetDefaultUnitTestConfig ( )
141
187
{
@@ -151,6 +197,32 @@ private Configuration GetDefaultUnitTestConfig()
151
197
var userSettings = new UserSettings ( null , null , null , unitTestSettings , null ) ;
152
198
return new Configuration ( userSettings ) ;
153
199
}
200
+
201
+
202
+ private IIndenterSettings GetDefaultIndenterSettings ( )
203
+ {
204
+ var indenterSettings = new IndenterSettings
205
+ {
206
+ IndentEntireProcedureBody = true ,
207
+ IndentFirstCommentBlock = true ,
208
+ IndentFirstDeclarationBlock = true ,
209
+ AlignCommentsWithCode = true ,
210
+ AlignContinuations = true ,
211
+ IgnoreOperatorsInContinuations = true ,
212
+ IndentCase = false ,
213
+ ForceDebugStatementsInColumn1 = false ,
214
+ ForceCompilerDirectivesInColumn1 = false ,
215
+ IndentCompilerDirectives = true ,
216
+ AlignDims = false ,
217
+ AlignDimColumn = 15 ,
218
+ EnableUndo = true ,
219
+ EndOfLineCommentStyle = EndOfLineCommentStyle . AlignInColumn ,
220
+ EndOfLineCommentColumnSpaceAlignment = 50 ,
221
+ IndentSpaces = 4
222
+ } ;
223
+
224
+ return indenterSettings ;
225
+ }
154
226
#endregion
155
227
}
156
228
}
0 commit comments