Skip to content

Commit 66413a0

Browse files
committed
Test coverage of contextual generators list
1 parent 7da0956 commit 66413a0

File tree

2 files changed

+92
-7
lines changed

2 files changed

+92
-7
lines changed

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public class ASGenerator
3434
static private Regex reModifier = new Regex("(public |private |protected )", RegexOptions.Compiled);
3535
static private Regex reSuperCall = new Regex("^super\\s*\\(", RegexOptions.Compiled);
3636

37-
static private string contextToken;
38-
static private string contextParam;
39-
static private Match contextMatch;
40-
static private ASResult contextResolved;
41-
static private MemberModel contextMember;
37+
static internal string contextToken;
38+
static internal string contextParam;
39+
static internal Match contextMatch;
40+
static internal ASResult contextResolved;
41+
static internal MemberModel contextMember;
4242
static private bool firstVar;
4343

4444
static private bool IsHaxe
@@ -795,7 +795,7 @@ private static void ShowDelegateList(FoundDeclaration found, List<ICompletionLis
795795
options.Add(new GeneratorItem(label, GeneratorJobType.Delegate, found.member, found.inClass));
796796
}
797797

798-
private static void ShowEventList(FoundDeclaration found, List<ICompletionListItem> options)
798+
internal static void ShowEventList(FoundDeclaration found, List<ICompletionListItem> options)
799799
{
800800
string tmp = TextHelper.GetString("ASCompletion.Label.GenerateHandler");
801801
string labelEvent = String.Format(tmp, "Event");
@@ -4611,7 +4611,7 @@ public Object Data
46114611
}
46124612
}
46134613

4614-
class FoundDeclaration
4614+
internal class FoundDeclaration
46154615
{
46164616
public MemberModel member;
46174617
public ClassModel inClass;

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using PluginCore;
1414
using ScintillaNet;
1515
using ScintillaNet.Enums;
16+
using System.Text.RegularExpressions;
1617

1718
namespace ASCompletion.Completion
1819
{
@@ -103,6 +104,90 @@ public void Common(string text, int lineStart, int lineEnd, string resultText, i
103104
}
104105
}
105106

107+
[TestFixture]
108+
public class ContextualActions : ASGeneratorTests
109+
{
110+
[TestFixtureSetUp]
111+
public void ContextualActionsSetup()
112+
{
113+
var pluginMain = Substitute.For<PluginMain>();
114+
var pluginUiMock = new PluginUIMock(pluginMain);
115+
pluginMain.MenuItems.Returns(new List<System.Windows.Forms.ToolStripItem>());
116+
pluginMain.Settings.Returns(new GeneralSettings());
117+
pluginMain.Panel.Returns(pluginUiMock);
118+
ASContext.GlobalInit(pluginMain);
119+
ASContext.Context = Substitute.For<IASContext>();
120+
}
121+
122+
[TestFixture]
123+
class ShowEventsList : ContextualActions
124+
{
125+
ClassModel dataEventModel;
126+
FoundDeclaration found;
127+
128+
[TestFixtureSetUp]
129+
public void ShowEventsListSetup()
130+
{
131+
ASContext.Context.SetAs3Features();
132+
ASContext.Context.CurrentModel.Returns(new FileModel());
133+
dataEventModel = CreateDataEventModel();
134+
found = new FoundDeclaration
135+
{
136+
inClass = new ClassModel(),
137+
member = new MemberModel()
138+
};
139+
}
140+
141+
[Test]
142+
public void ShowEventsList_EventWithDataEvent()
143+
{
144+
ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(dataEventModel);
145+
ASGenerator.contextParam = "Event";
146+
var options = new List<ICompletionListItem>();
147+
ASGenerator.ShowEventList(found, options);
148+
Assert.AreEqual(2, options.Count);
149+
Assert.IsTrue(Regex.IsMatch(options[0].Label, "\\bEvent\\b"));
150+
Assert.IsTrue(Regex.IsMatch(options[1].Label, "\\bDataEvent\\b"));
151+
}
152+
153+
[Test]
154+
public void ShowEventsList_EventWithoutDataEvent()
155+
{
156+
ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(ClassModel.VoidClass);
157+
var options = new List<ICompletionListItem>();
158+
ASGenerator.contextParam = "Event";
159+
ASGenerator.ShowEventList(found, options);
160+
Assert.AreEqual(1, options.Count);
161+
Assert.IsTrue(Regex.IsMatch(options[0].Label, "\\bEvent\\b"));
162+
}
163+
164+
[Test]
165+
public void ShowEventsList_CustomEventWithDataEvent()
166+
{
167+
ASContext.Context.ResolveType(null, null).ReturnsForAnyArgs(dataEventModel);
168+
var options = new List<ICompletionListItem>();
169+
ASGenerator.contextParam = "CustomEvent";
170+
ASGenerator.ShowEventList(found, options);
171+
Assert.AreEqual(2, options.Count);
172+
Assert.IsTrue(Regex.IsMatch(options[0].Label, "\\bCustomEvent\\b"));
173+
Assert.IsTrue(Regex.IsMatch(options[1].Label, "\\bEvent\\b"));
174+
}
175+
176+
private ClassModel CreateDataEventModel()
177+
{
178+
var dataEventFile = new FileModel();
179+
var dataEventModel = new ClassModel
180+
{
181+
Name = "DataEvent",
182+
InFile = dataEventFile
183+
};
184+
dataEventFile.Classes.Add(dataEventModel);
185+
return dataEventModel;
186+
}
187+
}
188+
189+
}
190+
106191
[TestFixture]
107192
public class GenerateJob : ASGeneratorTests
108193
{

0 commit comments

Comments
 (0)