2
2
using System . Collections . Generic ;
3
3
using ASCompletion . Context ;
4
4
using ASCompletion . Settings ;
5
+ using ASCompletion . TestUtils ;
5
6
using FlashDevelop ;
6
7
using NSubstitute ;
7
8
using NUnit . Framework ;
8
9
using PluginCore ;
9
10
using ScintillaNet ;
11
+ using ScintillaNet . Enums ;
10
12
11
13
namespace ASCompletion . Completion
12
14
{
@@ -22,6 +24,11 @@ public void FixtureSetUp()
22
24
{
23
25
mainForm = new MainForm ( ) ;
24
26
settings = Substitute . For < ISettings > ( ) ;
27
+ settings . UseTabs = true ;
28
+ settings . IndentSize = 4 ;
29
+ settings . SmartIndentType = SmartIndent . CPP ;
30
+ settings . TabIndents = true ;
31
+ settings . TabWidth = 4 ;
25
32
doc = Substitute . For < ITabbedDocument > ( ) ;
26
33
mainForm . Settings = settings ;
27
34
mainForm . CurrentDocument = doc ;
@@ -181,11 +188,12 @@ public void GenerateJob_FieldFromParameterPublicScope()
181
188
ASGenerator . GenerateJob ( GeneratorJobType . FieldFromPatameter , null , null , null , table ) ;
182
189
}
183
190
191
+ // TODO: Tests with different formatting options
184
192
[ Test ]
185
193
public void GenerateJob_ImplementFromInterface_FullAs3 ( )
186
194
{
187
- var interfaceModel = new Model . ClassModel { InFile = new Model . FileModel ( ) , Name = "ITest" } ;
188
- var classModel = new Model . ClassModel { InFile = new Model . FileModel ( ) , LineTo = 1 } ;
195
+ var interfaceModel = new Model . ClassModel { InFile = new Model . FileModel ( ) , Name = "ITest" , Type = "ITest" } ;
196
+ var classModel = new Model . ClassModel { InFile = new Model . FileModel ( ) , LineFrom = 1 , LineTo = 1 } ;
189
197
var pluginMain = Substitute . For < PluginMain > ( ) ;
190
198
var pluginUiMock = new PluginUIMock ( pluginMain ) ;
191
199
pluginMain . MenuItems . Returns ( new List < System . Windows . Forms . ToolStripItem > ( ) ) ;
@@ -197,7 +205,7 @@ public void GenerateJob_ImplementFromInterface_FullAs3()
197
205
ASContext . Context . Features . voidKey = "void" ;
198
206
199
207
var sci = GetBaseScintillaControl ( ) ;
200
- sci . Text = "package test():void {\r \n \t }" ;
208
+ sci . Text = "package generatortest {\r \n \t public class ImplementTest{} \r \n }" ;
201
209
sci . ConfigurationLanguage = "as3" ;
202
210
doc . SciControl . Returns ( sci ) ;
203
211
@@ -211,22 +219,80 @@ public void GenerateJob_ImplementFromInterface_FullAs3()
211
219
new Model . MemberModel ( "testMethod" , "Number" , Model . FlagType . Function , Model . Visibility . Public ) ,
212
220
new Model . MemberModel ( "testMethodArgs" , "int" , Model . FlagType . Function , Model . Visibility . Public )
213
221
{
214
- Parameters = new List < Model . MemberModel > { new Model . MemberModel ( "arg" , "Number" , Model . FlagType . Variable , Model . Visibility . Default ) }
222
+ Parameters = new List < Model . MemberModel >
223
+ {
224
+ new Model . MemberModel ( "arg" , "Number" , Model . FlagType . Variable , Model . Visibility . Default ) ,
225
+ new Model . MemberModel ( "arg2" , "Boolean" , Model . FlagType . Variable , Model . Visibility . Default )
226
+ }
215
227
}
216
228
} ) ;
217
229
218
230
ASGenerator . GenerateJob ( GeneratorJobType . ImplementInterface , null , classModel , null , null ) ;
231
+ Assert . AreEqual ( TestFile . ReadAllText ( "ASCompletion.Test_Files.generated.as3.ImplementInterfaceNoMembers.as" ) , sci . Text ) ;
219
232
}
220
233
221
- private static ScintillaControl GetBaseScintillaControl ( )
234
+ [ Test ]
235
+ public void GenerateJob_ImplementFromInterface_FullAs3WithPublicMemberBehindPrivate ( )
236
+ {
237
+ var interfaceModel = new Model . ClassModel { InFile = new Model . FileModel ( ) , Name = "ITest" , Type = "ITest" } ;
238
+ var classModel = new Model . ClassModel { InFile = new Model . FileModel ( ) , LineFrom = 1 , LineTo = 10 } ;
239
+ var pluginMain = Substitute . For < PluginMain > ( ) ;
240
+ var pluginUiMock = new PluginUIMock ( pluginMain ) ;
241
+ pluginMain . MenuItems . Returns ( new List < System . Windows . Forms . ToolStripItem > ( ) ) ;
242
+ pluginMain . Settings . Returns ( new GeneralSettings ( ) ) ;
243
+ pluginMain . Panel . Returns ( pluginUiMock ) ;
244
+ ASContext . GlobalInit ( pluginMain ) ;
245
+ ASContext . Context = Substitute . For < IASContext > ( ) ;
246
+ ASContext . Context . ResolveType ( null , null ) . ReturnsForAnyArgs ( interfaceModel ) ;
247
+ ASContext . Context . Features . voidKey = "void" ;
248
+
249
+ var sci = GetBaseScintillaControl ( ) ;
250
+ sci . Text = TestFile . ReadAllText ( "ASCompletion.Test_Files.generated.as3.BeforeImplementInterfacePublicMemberBehindPrivate.as" ) ;
251
+ sci . ConfigurationLanguage = "as3" ;
252
+ doc . SciControl . Returns ( sci ) ;
253
+
254
+ classModel . Members . Add ( new Model . MemberList
255
+ {
256
+ new Model . MemberModel ( "publicMember" , "void" , Model . FlagType . Function , Model . Visibility . Public )
257
+ { LineFrom = 3 , LineTo = 5 } ,
258
+ new Model . MemberModel ( "privateMember" , "String" , Model . FlagType . Function , Model . Visibility . Private )
259
+ { LineFrom = 7 , LineTo = 9 }
260
+ } ) ;
261
+
262
+ interfaceModel . Members . Add ( new Model . MemberList
263
+ {
264
+ new Model . MemberModel ( "getter" , "String" , Model . FlagType . Getter , Model . Visibility . Public ) ,
265
+ new Model . MemberModel ( "setter" , "void" , Model . FlagType . Setter , Model . Visibility . Public )
266
+ {
267
+ Parameters = new List < Model . MemberModel > { new Model . MemberModel ( "value" , "String" , Model . FlagType . Variable , Model . Visibility . Default ) }
268
+ } ,
269
+ new Model . MemberModel ( "testMethod" , "Number" , Model . FlagType . Function , Model . Visibility . Public ) ,
270
+ new Model . MemberModel ( "testMethodArgs" , "int" , Model . FlagType . Function , Model . Visibility . Public )
271
+ {
272
+ Parameters = new List < Model . MemberModel >
273
+ {
274
+ new Model . MemberModel ( "arg" , "Number" , Model . FlagType . Variable , Model . Visibility . Default ) ,
275
+ new Model . MemberModel ( "arg2" , "Boolean" , Model . FlagType . Variable , Model . Visibility . Default )
276
+ }
277
+ }
278
+ } ) ;
279
+
280
+ ASGenerator . GenerateJob ( GeneratorJobType . ImplementInterface , null , classModel , null , null ) ;
281
+ Assert . AreEqual ( TestFile . ReadAllText ( "ASCompletion.Test_Files.generated.as3.ImplementInterfacePublicMemberBehindPrivate.as" ) , sci . Text ) ;
282
+ }
283
+
284
+ private ScintillaControl GetBaseScintillaControl ( )
222
285
{
223
286
return new ScintillaControl
224
287
{
225
288
Encoding = System . Text . Encoding . UTF8 ,
226
289
CodePage = 65001 ,
227
- Indent = 4 ,
290
+ Indent = settings . IndentSize ,
228
291
Lexer = 3 ,
229
- StyleBits = 7
292
+ StyleBits = 7 ,
293
+ IsTabIndents = settings . TabIndents ,
294
+ IsUseTabs = settings . UseTabs ,
295
+ TabWidth = settings . TabWidth
230
296
} ;
231
297
}
232
298
0 commit comments