Skip to content

Commit 56f8881

Browse files
committed
The possible start of ASComplete tests.
1 parent 06118ee commit 56f8881

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Reference Include="System.Xml" />
9797
</ItemGroup>
9898
<ItemGroup>
99+
<Compile Include="Completion\ASCompleteTests.cs" />
99100
<Compile Include="Completion\ASGeneratorTests.cs" />
100101
<Compile Include="MainForm.cs">
101102
<SubType>Form</SubType>
@@ -148,6 +149,7 @@
148149
<EmbeddedResource Include="Test Files\generated\haxe\ImplementInterfaceNoMembers.hx" />
149150
<EmbeddedResource Include="Test Files\generated\haxe\ImplementInterfaceNoPublicMember.hx" />
150151
<EmbeddedResource Include="Test Files\generated\haxe\ImplementInterfacePublicMemberBehindPrivate.hx" />
152+
<EmbeddedResource Include="Test Files\completion\as3\SimpleTest.as" />
151153
</ItemGroup>
152154
<ItemGroup>
153155
<ProjectReference Include="..\..\..\..\External\Plugins\AS2Context\AS2Context.csproj">
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using AS3Context;
6+
using ASCompletion.Context;
7+
using ASCompletion.Model;
8+
using ASCompletion.Settings;
9+
using ASCompletion.TestUtils;
10+
using FlashDevelop;
11+
using NSubstitute;
12+
using NUnit.Framework;
13+
using PluginCore;
14+
using ScintillaNet;
15+
using ScintillaNet.Enums;
16+
17+
//TODO: Sadly most of ASComplete is currently untestable in a proper way. Work on this branch solves it: https://github.com/Neverbirth/flashdevelop/tree/completionlist
18+
19+
namespace ASCompletion.Completion
20+
{
21+
[TestFixture]
22+
public class ASCompleteTests
23+
{
24+
private MainForm mainForm;
25+
private ISettings settings;
26+
private ITabbedDocument doc;
27+
28+
[TestFixtureSetUp]
29+
public void FixtureSetUp()
30+
{
31+
mainForm = new MainForm();
32+
settings = Substitute.For<ISettings>();
33+
settings.UseTabs = true;
34+
settings.IndentSize = 4;
35+
settings.SmartIndentType = SmartIndent.CPP;
36+
settings.TabIndents = true;
37+
settings.TabWidth = 4;
38+
doc = Substitute.For<ITabbedDocument>();
39+
mainForm.Settings = settings;
40+
mainForm.CurrentDocument = doc;
41+
mainForm.StandaloneMode = false;
42+
PluginBase.Initialize(mainForm);
43+
FlashDevelop.Managers.ScintillaManager.LoadConfiguration();
44+
}
45+
46+
[TestFixtureTearDown]
47+
public void FixtureTearDown()
48+
{
49+
settings = null;
50+
doc = null;
51+
mainForm.Dispose();
52+
mainForm = null;
53+
}
54+
55+
private ScintillaControl GetBaseScintillaControl()
56+
{
57+
return new ScintillaControl
58+
{
59+
Encoding = System.Text.Encoding.UTF8,
60+
CodePage = 65001,
61+
Indent = settings.IndentSize,
62+
Lexer = 3,
63+
StyleBits = 7,
64+
IsTabIndents = settings.TabIndents,
65+
IsUseTabs = settings.UseTabs,
66+
TabWidth = settings.TabWidth
67+
};
68+
}
69+
70+
// TODO: Add more tests!
71+
[Test]
72+
public void GetExpressionType_SimpleTest()
73+
{
74+
//TODO: Improve this test with more checks!
75+
var pluginMain = Substitute.For<PluginMain>();
76+
var pluginUiMock = new PluginUIMock(pluginMain);
77+
pluginMain.MenuItems.Returns(new List<System.Windows.Forms.ToolStripItem>());
78+
pluginMain.Settings.Returns(new GeneralSettings());
79+
pluginMain.Panel.Returns(pluginUiMock);
80+
ASContext.GlobalInit(pluginMain);
81+
ASContext.Context = Substitute.For<IASContext>();
82+
ASContext.Context.CurrentLine = 9;
83+
var asContext = new AS3Context.Context(new AS3Settings());
84+
ASContext.Context.Features.Returns(asContext.Features);
85+
ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x => asContext.GetCodeModel(x.ArgAt<string>(0)));
86+
87+
// Maybe we want to get the filemodel from ASFileParser even if we won't get a controlled environment?
88+
var member = new MemberModel("test1", "void", FlagType.Function, Visibility.Public)
89+
{
90+
LineFrom = 4,
91+
LineTo = 10,
92+
Parameters = new List<MemberModel>
93+
{
94+
new MemberModel("arg1", "String", FlagType.ParameterVar, Visibility.Default),
95+
new MemberModel("arg2", "Boolean", FlagType.ParameterVar, Visibility.Default) {Value = "false"}
96+
}
97+
};
98+
99+
var classModel = new ClassModel();
100+
classModel.Name = "ASCompleteTest";
101+
classModel.Members.Add(member);
102+
103+
var fileModel = new FileModel();
104+
fileModel.Classes.Add(classModel);
105+
106+
classModel.InFile = fileModel;
107+
108+
ASContext.Context.CurrentModel.Returns(fileModel);
109+
ASContext.Context.CurrentClass.Returns(classModel);
110+
ASContext.Context.CurrentMember.Returns(member);
111+
112+
var sci = GetBaseScintillaControl();
113+
sci.Text = TestFile.ReadAllText("ASCompletion.Test_Files.completion.as3.SimpleTest.as");
114+
sci.ConfigurationLanguage = "as3";
115+
sci.Colourise(0, -1);
116+
117+
var result = ASComplete.GetExpressionType(sci, 185);
118+
119+
Assert.True(result.Context != null && result.Context.LocalVars != null);
120+
Assert.AreEqual(4, result.Context.LocalVars.Count);
121+
}
122+
}
123+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test {
2+
3+
public class ASCompleteTest
4+
{
5+
public function test1(arg1:String, arg2:Boolean = false):void
6+
{
7+
var local1:String = "ASD";
8+
var local2:String;
9+
10+
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)