|
13 | 13 | using PluginCore;
|
14 | 14 | using ScintillaNet;
|
15 | 15 | using ScintillaNet.Enums;
|
| 16 | +using System.Text.RegularExpressions; |
16 | 17 |
|
17 | 18 | namespace ASCompletion.Completion
|
18 | 19 | {
|
@@ -103,6 +104,90 @@ public void Common(string text, int lineStart, int lineEnd, string resultText, i
|
103 | 104 | }
|
104 | 105 | }
|
105 | 106 |
|
| 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 | + |
106 | 191 | [TestFixture]
|
107 | 192 | public class GenerateJob : ASGeneratorTests
|
108 | 193 | {
|
|
0 commit comments