Skip to content

Commit 8d54285

Browse files
committed
A couple of ImplementInterface working tests. NOTE: Removed unneeded blank line when no members defined in the implementing class.
Test for identifiers with unicode characters. Moved test files to sub folder for better organization.
1 parent e4ac1df commit 8d54285

33 files changed

+292
-78
lines changed

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -947,13 +947,18 @@ static public void GenerateJob(GeneratorJobType job, MemberModel member, ClassMo
947947

948948
latest = GetLatestMemberForFunction(inClass, Visibility.Public, null);
949949
if (latest == null)
950-
latest = FindLatest(0, 0, inClass, false, false);
951-
952-
position = latest == null ? GetBodyStart(inClass.LineFrom, inClass.LineTo, sci) :
953-
sci.PositionFromLine(latest.LineTo + 1) - ((sci.EOLMode == 0) ? 2 : 1);
950+
latest = FindLatest(0, 0, inClass, false, false);
951+
952+
if (latest == null)
953+
{
954+
position = GetBodyStart(inClass.LineFrom, inClass.LineTo, sci);
955+
detach = false;
956+
}
957+
else
958+
position = sci.PositionFromLine(latest.LineTo + 1) - ((sci.EOLMode == 0) ? 2 : 1);
954959

955960
sci.SetSel(position, position);
956-
GenerateImplementation(iType, inClass, sci);
961+
GenerateImplementation(iType, inClass, sci, detach);
957962
break;
958963

959964
case GeneratorJobType.MoveLocalUp:
@@ -3094,11 +3099,18 @@ private static string GuessVarName(string name, string type)
30943099
return name;
30953100
}
30963101

3097-
private static void GenerateImplementation(ClassModel iType, ClassModel inClass, ScintillaControl sci)
3102+
private static void GenerateImplementation(ClassModel iType, ClassModel inClass, ScintillaControl sci, bool detached)
30983103
{
30993104
List<string> typesUsed = new List<string>();
31003105

3101-
StringBuilder sb = new StringBuilder(TemplateUtils.ReplaceTemplateVariable(TemplateUtils.GetTemplate("ImplementHeader"), "Class", iType.Type));
3106+
StringBuilder sb = new StringBuilder();
3107+
3108+
string header = TemplateUtils.ReplaceTemplateVariable(TemplateUtils.GetTemplate("ImplementHeader"), "Class",
3109+
iType.Type);
3110+
3111+
header = TemplateUtils.ReplaceTemplateVariable(header, "BlankLine", detached ? BlankLine : null);
3112+
3113+
sb.Append(header);
31023114
sb.Append(NewLine);
31033115
bool entry = true;
31043116
ASResult result = new ASResult();
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11

2-
3-
/* INTERFACE $(Class) */
2+
$(BlankLine)/* INTERFACE $(Class) */

Tests/External/Plugins/ASCompletion.Tests/ASCompletion.Tests.csproj

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,33 @@
114114
</ItemGroup>
115115
<ItemGroup>
116116
<None Include="packages.config" />
117-
<EmbeddedResource Include="Test Files\as3\SimpleClassTest.as" />
118-
<EmbeddedResource Include="Test Files\haxe\SimpleClassTest.hx" />
119-
<EmbeddedResource Include="Test Files\as3\OverrideFunctionTest.as" />
120-
<EmbeddedResource Include="Test Files\haxe\OverrideFunctionTest.hx" />
121-
<EmbeddedResource Include="Test Files\haxe\TypeDefsTest.hx" />
122-
<EmbeddedResource Include="Test Files\haxe\GenericsTest.hx" />
123-
<EmbeddedResource Include="Test Files\haxe\GenericsObjectConstraintTest.hx" />
124-
<EmbeddedResource Include="Test Files\haxe\ImplementClassTest.hx" />
125-
<EmbeddedResource Include="Test Files\haxe\ImportTest.hx" />
126-
<EmbeddedResource Include="Test Files\haxe\InterfaceTest.hx" />
127-
<EmbeddedResource Include="Test Files\haxe\PrivateClassTest.hx" />
128-
<EmbeddedResource Include="Test Files\haxe\RegExTest.hx" />
129-
<EmbeddedResource Include="Test Files\haxe\ImportAliasTest.hx" />
130-
<EmbeddedResource Include="Test Files\haxe\ComplexClassTest.hx" />
131-
<EmbeddedResource Include="Test Files\haxe\MultiLineStringsTest.hx" />
132-
<EmbeddedResource Include="Test Files\haxe\EscapedStringsTest.hx" />
133-
<EmbeddedResource Include="Test Files\haxe\EnumsTest.hx" />
134-
<EmbeddedResource Include="Test Files\haxe\AbstractsTest.hx" />
135-
<EmbeddedResource Include="Test Files\haxe\RegionsTest.hx" />
136-
<EmbeddedResource Include="Test Files\haxe\FunctionTypesTest.hx" />
137-
<EmbeddedResource Include="Test Files\haxe\FunctionTypesWithSubTypesTest.hx" />
138-
<EmbeddedResource Include="Test Files\haxe\CommentsTest.hx" />
139-
<EmbeddedResource Include="Test Files\haxe\SpecialClassesCommentsTest.hx" />
117+
<EmbeddedResource Include="Test Files\parser\as3\OverrideFunctionTest.as" />
118+
<EmbeddedResource Include="Test Files\parser\as3\SimpleClassTest.as" />
119+
<EmbeddedResource Include="Test Files\parser\haxe\AbstractsTest.hx" />
120+
<EmbeddedResource Include="Test Files\parser\haxe\CommentsTest.hx" />
121+
<EmbeddedResource Include="Test Files\parser\haxe\ComplexClassTest.hx" />
122+
<EmbeddedResource Include="Test Files\parser\haxe\EnumsTest.hx" />
123+
<EmbeddedResource Include="Test Files\parser\haxe\EscapedStringsTest.hx" />
124+
<EmbeddedResource Include="Test Files\parser\haxe\FunctionTypesTest.hx" />
125+
<EmbeddedResource Include="Test Files\parser\haxe\FunctionTypesWithSubTypesTest.hx" />
126+
<EmbeddedResource Include="Test Files\parser\haxe\GenericsObjectConstraintTest.hx" />
127+
<EmbeddedResource Include="Test Files\parser\haxe\GenericsTest.hx" />
128+
<EmbeddedResource Include="Test Files\parser\haxe\ImplementClassTest.hx" />
129+
<EmbeddedResource Include="Test Files\parser\haxe\ImportAliasTest.hx" />
130+
<EmbeddedResource Include="Test Files\parser\haxe\ImportTest.hx" />
131+
<EmbeddedResource Include="Test Files\parser\haxe\InterfaceTest.hx" />
132+
<EmbeddedResource Include="Test Files\parser\haxe\MultiLineStringsTest.hx" />
133+
<EmbeddedResource Include="Test Files\parser\haxe\OverrideFunctionTest.hx" />
134+
<EmbeddedResource Include="Test Files\parser\haxe\PrivateClassTest.hx" />
135+
<EmbeddedResource Include="Test Files\parser\haxe\RegExTest.hx" />
136+
<EmbeddedResource Include="Test Files\parser\haxe\RegionsTest.hx" />
137+
<EmbeddedResource Include="Test Files\parser\haxe\SimpleClassTest.hx" />
138+
<EmbeddedResource Include="Test Files\parser\haxe\SpecialClassesCommentsTest.hx" />
139+
<EmbeddedResource Include="Test Files\parser\haxe\TypeDefsTest.hx" />
140+
<EmbeddedResource Include="Test Files\generated\as3\ImplementInterfaceNoMembers.as" />
141+
<EmbeddedResource Include="Test Files\parser\haxe\IdentifiersWithUnicodeCharsTest.hx" />
142+
<EmbeddedResource Include="Test Files\generated\as3\BeforeImplementInterfacePublicMemberBehindPrivate.as" />
143+
<EmbeddedResource Include="Test Files\generated\as3\ImplementInterfacePublicMemberBehindPrivate.as" />
140144
</ItemGroup>
141145
<ItemGroup>
142146
<ProjectReference Include="..\..\..\..\External\Plugins\AS2Context\AS2Context.csproj">

Tests/External/Plugins/ASCompletion.Tests/Completion/ASGeneratorTests.cs

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Collections.Generic;
33
using ASCompletion.Context;
44
using ASCompletion.Settings;
5+
using ASCompletion.TestUtils;
56
using FlashDevelop;
67
using NSubstitute;
78
using NUnit.Framework;
89
using PluginCore;
910
using ScintillaNet;
11+
using ScintillaNet.Enums;
1012

1113
namespace ASCompletion.Completion
1214
{
@@ -22,6 +24,11 @@ public void FixtureSetUp()
2224
{
2325
mainForm = new MainForm();
2426
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;
2532
doc = Substitute.For<ITabbedDocument>();
2633
mainForm.Settings = settings;
2734
mainForm.CurrentDocument = doc;
@@ -181,11 +188,12 @@ public void GenerateJob_FieldFromParameterPublicScope()
181188
ASGenerator.GenerateJob(GeneratorJobType.FieldFromPatameter, null, null, null, table);
182189
}
183190

191+
// TODO: Tests with different formatting options
184192
[Test]
185193
public void GenerateJob_ImplementFromInterface_FullAs3()
186194
{
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};
189197
var pluginMain = Substitute.For<PluginMain>();
190198
var pluginUiMock = new PluginUIMock(pluginMain);
191199
pluginMain.MenuItems.Returns(new List<System.Windows.Forms.ToolStripItem>());
@@ -197,7 +205,7 @@ public void GenerateJob_ImplementFromInterface_FullAs3()
197205
ASContext.Context.Features.voidKey = "void";
198206

199207
var sci = GetBaseScintillaControl();
200-
sci.Text = "package test():void{\r\n\t}";
208+
sci.Text = "package generatortest {\r\n\tpublic class ImplementTest{}\r\n}";
201209
sci.ConfigurationLanguage = "as3";
202210
doc.SciControl.Returns(sci);
203211

@@ -211,22 +219,80 @@ public void GenerateJob_ImplementFromInterface_FullAs3()
211219
new Model.MemberModel("testMethod", "Number", Model.FlagType.Function, Model.Visibility.Public),
212220
new Model.MemberModel("testMethodArgs", "int", Model.FlagType.Function, Model.Visibility.Public)
213221
{
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+
}
215227
}
216228
});
217229

218230
ASGenerator.GenerateJob(GeneratorJobType.ImplementInterface, null, classModel, null, null);
231+
Assert.AreEqual(TestFile.ReadAllText("ASCompletion.Test_Files.generated.as3.ImplementInterfaceNoMembers.as"), sci.Text);
219232
}
220233

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()
222285
{
223286
return new ScintillaControl
224287
{
225288
Encoding = System.Text.Encoding.UTF8,
226289
CodePage = 65001,
227-
Indent = 4,
290+
Indent = settings.IndentSize,
228291
Lexer = 3,
229-
StyleBits = 7
292+
StyleBits = 7,
293+
IsTabIndents = settings.TabIndents,
294+
IsUseTabs = settings.UseTabs,
295+
TabWidth = settings.TabWidth
230296
};
231297
}
232298

0 commit comments

Comments
 (0)