Skip to content

Commit

Permalink
More tests... (#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavaRa committed Feb 6, 2018
1 parent aa5c7ef commit c8e108c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 46 deletions.
79 changes: 40 additions & 39 deletions External/Plugins/ASCompletion/Completion/ASGenerator.cs
Expand Up @@ -297,8 +297,8 @@ protected virtual void ContextualGenerator(ScintillaControl sci, int position, A
{
var returnType = GetStatementReturnType(sci, found.inClass, sci.GetLine(curLine), sci.PositionFromLine(curLine));
if (returnType.resolve.Member?.Type == ASContext.Context.Features.voidKey) return;
if (returnType.resolve.Type == null && returnType.resolve.Context?.WordBefore == "new") ShowNewClassList(found, options, returnType.resolve.Context);
else ShowAssignStatementToVarList(found, options, returnType);
if (returnType.resolve.Type == null && returnType.resolve.Context?.WordBefore == "new") ShowNewClassList(found, returnType.resolve.Context, options);
else ShowAssignStatementToVarList(found, returnType, options);
return;
}
}
Expand Down Expand Up @@ -423,13 +423,13 @@ protected virtual void ContextualGenerator(ScintillaControl sci, int position, A
var constructorParametersCount = constructor.Parameters?.Count ?? 0;
var wordEndPosition = sci.WordEndPosition(sci.CurrentPos, true);
var parameters = ParseFunctionParameters(sci, wordEndPosition);
if (parameters.Count != constructorParametersCount) ShowChangeConstructorDeclarationList(found, options, parameters);
if (parameters.Count != constructorParametersCount) ShowChangeConstructorDeclarationList(found, parameters, options);
else
{
for (var i = 0; i < parameters.Count; i++)
{
if (parameters[i].paramType == constructor.Parameters[i].Type) continue;
ShowChangeConstructorDeclarationList(found, options, parameters);
ShowChangeConstructorDeclarationList(found, parameters, options);
break;
}
}
Expand Down Expand Up @@ -630,7 +630,7 @@ internal static string CheckEventType(string name)

#region generators lists

private static void ShowImportClass(List<MemberModel> matches, List<ICompletionListItem> options)
private static void ShowImportClass(List<MemberModel> matches, ICollection<ICompletionListItem> options)
{
if (matches.Count == 1)
{
Expand All @@ -647,7 +647,7 @@ private static void ShowImportClass(List<MemberModel> matches, List<ICompletionL
}
}

private static void ShowPromoteLocalAndAddParameter(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowPromoteLocalAndAddParameter(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
string label = TextHelper.GetString("ASCompletion.Label.PromoteLocal");
string labelMove = TextHelper.GetString("ASCompletion.Label.MoveDeclarationOnTop");
Expand All @@ -657,19 +657,19 @@ private static void ShowPromoteLocalAndAddParameter(FoundDeclaration found, List
options.Add(new GeneratorItem(labelParam, GeneratorJobType.AddAsParameter, found.member, found.inClass));
}

private static void ShowConvertToConst(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowConvertToConst(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
string label = TextHelper.GetString("ASCompletion.Label.ConvertToConst");
options.Add(new GeneratorItem(label, GeneratorJobType.ConvertToConst, found.member, found.inClass));
}

private static void ShowImplementInterface(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowImplementInterface(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
string label = TextHelper.GetString("ASCompletion.Label.ImplementInterface");
options.Add(new GeneratorItem(label, GeneratorJobType.ImplementInterface, null, found.inClass));
}

private static void ShowNewVarList(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowNewVarList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
bool generateClass = true;
ScintillaControl sci = ASContext.CurSciControl;
Expand Down Expand Up @@ -750,19 +750,19 @@ private static void ShowNewVarList(FoundDeclaration found, List<ICompletionListI
}
}

private static void ShowChangeMethodDeclList(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowChangeMethodDeclList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
string label = TextHelper.GetString("ASCompletion.Label.ChangeMethodDecl");
options.Add(new GeneratorItem(label, GeneratorJobType.ChangeMethodDecl, found.member, found.inClass));
}

private static void ShowChangeConstructorDeclarationList(FoundDeclaration found, ICollection<ICompletionListItem> options, IList<FunctionParameter> parameters)
private static void ShowChangeConstructorDeclarationList(FoundDeclaration found, IList<FunctionParameter> parameters, ICollection<ICompletionListItem> options)
{
var label = TextHelper.GetString("ASCompletion.Label.ChangeConstructorDecl");
options.Add(new GeneratorItem(label, GeneratorJobType.ChangeConstructorDecl, found.member, found.inClass, parameters));
}

private static void ShowNewMethodList(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowNewMethodList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
ScintillaControl sci = ASContext.CurSciControl;
ASResult result = ASComplete.GetExpressionType(sci, sci.WordEndPosition(sci.CurrentPos, true));
Expand All @@ -785,15 +785,15 @@ private static void ShowNewMethodList(FoundDeclaration found, List<ICompletionLi
options.Add(new GeneratorItem(label, GeneratorJobType.VariablePublic, found.member, found.inClass));
}

static void ShowAssignStatementToVarList(FoundDeclaration found, ICollection<ICompletionListItem> options, StatementReturnType data)
private static void ShowAssignStatementToVarList(FoundDeclaration found, StatementReturnType data, ICollection<ICompletionListItem> options)
{
var label = TextHelper.GetString("ASCompletion.Label.AssignStatementToVar");
options.Add(new GeneratorItem(label, GeneratorJobType.AssignStatementToVar, found.member, found.inClass, data));
}

private static void ShowNewClassList(FoundDeclaration found, ICollection<ICompletionListItem> options) => ShowNewClassList(found, options, null);
private static void ShowNewClassList(FoundDeclaration found, ICollection<ICompletionListItem> options) => ShowNewClassList(found, null, options);

static void ShowNewClassList(FoundDeclaration found, ICollection<ICompletionListItem> options, ASExpr expr)
private static void ShowNewClassList(FoundDeclaration found, ASExpr expr, ICollection<ICompletionListItem> options)
{
var label = TextHelper.GetString("ASCompletion.Label.GenerateClass");
options.Add(new GeneratorItem(label, GeneratorJobType.Class, found.member, found.inClass, expr));
Expand All @@ -814,13 +814,13 @@ private static void ShowConstructorAndToStringList(FoundDeclaration found, bool
}
}

private static void ShowEventMetatagList(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowEventMetatagList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
string label = TextHelper.GetString("ASCompletion.Label.GenerateEventMetatag");
options.Add(new GeneratorItem(label, GeneratorJobType.EventMetatag, found.member, found.inClass));
}

private static void ShowFieldFromParameter(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowFieldFromParameter(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
Hashtable parameters = new Hashtable();
parameters["scope"] = GetDefaultVisibility(found.inClass);
Expand All @@ -835,7 +835,7 @@ private static void ShowFieldFromParameter(FoundDeclaration found, List<IComplet
options.Add(new GeneratorItem(label, GeneratorJobType.FieldFromParameter, found.member, found.inClass, parameters));
}

static void ShowAddInterfaceDefList(FoundDeclaration found, IEnumerable<string> interfaces, ICollection<ICompletionListItem> options)
private static void ShowAddInterfaceDefList(FoundDeclaration found, IEnumerable<string> interfaces, ICollection<ICompletionListItem> options)
{
var label = TextHelper.GetString("ASCompletion.Label.AddInterfaceDef");
foreach (var interf in interfaces)
Expand All @@ -844,7 +844,7 @@ static void ShowAddInterfaceDefList(FoundDeclaration found, IEnumerable<string>
}
}

private static void ShowDelegateList(FoundDeclaration found, List<ICompletionListItem> options)
private static void ShowDelegateList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
string label = String.Format(TextHelper.GetString("ASCompletion.Label.GenerateHandler"), "Delegate");
options.Add(new GeneratorItem(label, GeneratorJobType.Delegate, found.member, found.inClass));
Expand All @@ -863,8 +863,9 @@ internal static void ShowEventList(FoundDeclaration found, List<ICompletionListI

for (int i = 0; i < choices.Length; i++)
{
options.Add(new GeneratorItem(choices[i],
choices[i] == labelContext ? GeneratorJobType.ComplexEvent : GeneratorJobType.BasicEvent,
var choice = choices[i];
options.Add(new GeneratorItem(choice,
choice == labelContext ? GeneratorJobType.ComplexEvent : GeneratorJobType.BasicEvent,
found.member, found.inClass));
}
}
Expand All @@ -874,36 +875,36 @@ private static bool HasDataEvent()
return !ASContext.Context.ResolveType("flash.events.DataEvent", ASContext.Context.CurrentModel).IsVoid();
}

private static void ShowGetSetList(FoundDeclaration found, List<ICompletionListItem> options)
{
string name = GetPropertyNameFor(found.member);
ASResult result = new ASResult();
ClassModel curClass = ASContext.Context.CurrentClass;
ASComplete.FindMember(name, curClass, result, FlagType.Getter, 0);
bool hasGetter = !result.IsNull();
ASComplete.FindMember(name, curClass, result, FlagType.Setter, 0);
private static void ShowGetSetList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
string name = GetPropertyNameFor(found.member);
ASResult result = new ASResult();
ClassModel curClass = ASContext.Context.CurrentClass;
ASComplete.FindMember(name, curClass, result, FlagType.Getter, 0);
bool hasGetter = !result.IsNull();
ASComplete.FindMember(name, curClass, result, FlagType.Setter, 0);
bool hasSetter = !result.IsNull();
if (hasGetter && hasSetter) return;
if (!hasGetter && !hasSetter)
{
string label = TextHelper.GetString("ASCompletion.Label.GenerateGetSet");
options.Add(new GeneratorItem(label, GeneratorJobType.GetterSetter, found.member, found.inClass));
if (!hasGetter && !hasSetter)
{
string label = TextHelper.GetString("ASCompletion.Label.GenerateGetSet");
options.Add(new GeneratorItem(label, GeneratorJobType.GetterSetter, found.member, found.inClass));
}
ShowGetterList(found, options);
ShowSetterList(found, options);
}

static void ShowGetterList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
var name = GetPropertyNameFor(found.member);
}

private static void ShowGetterList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
var name = GetPropertyNameFor(found.member);
var result = new ASResult();
ASComplete.FindMember(name, ASContext.Context.CurrentClass, result, FlagType.Getter, 0);
if (!result.IsNull()) return;
var label = TextHelper.GetString("ASCompletion.Label.GenerateGet");
options.Add(new GeneratorItem(label, GeneratorJobType.Getter, found.member, found.inClass));
}

static void ShowSetterList(FoundDeclaration found, ICollection<ICompletionListItem> options)
private static void ShowSetterList(FoundDeclaration found, ICollection<ICompletionListItem> options)
{
var name = GetPropertyNameFor(found.member);
var result = new ASResult();
Expand Down
Expand Up @@ -475,19 +475,19 @@ yield return
yield return
new TestCaseData(ReadAllText("GetExpression_operator_is"))
.Returns(";(\"s\" is String).")
.SetName("(\"s\" is String)");
.SetName("(\"s\" is String).|");
yield return
new TestCaseData(ReadAllText("GetExpression_operator_as"))
.Returns(";(\"s\" as String).")
.SetName("(\"s\" as String)");
.SetName("(\"s\" as String).|");
yield return
new TestCaseData(ReadAllText("GetExpression_return_operator_as"))
.Returns("return;(\"s\" as String).")
.SetName("return (\"s\" as String)");
.SetName("return (\"s\" as String).|");
yield return
new TestCaseData(ReadAllText("GetExpression_issue1954"))
.Returns(";re")
.SetName("function foo():Vector.<int> { re");
.SetName("function foo():Vector.<int> { re|");
yield return
new TestCaseData("[].$(EntryPoint)")
.Returns(" [].")
Expand Down Expand Up @@ -862,7 +862,7 @@ yield return
yield return
new TestCaseData(ReadAllText("GetExpression_issue1749_increment5"))
.Returns("=getId()++")
.SetName("var id = getId()++");
.SetName("var id = getId()++|");
yield return
new TestCaseData(ReadAllText("GetExpression_issue1749_decrement"))
.Returns("--1")
Expand All @@ -882,11 +882,43 @@ yield return
yield return
new TestCaseData(ReadAllText("GetExpression_issue1749_decrement5"))
.Returns("=getId()--")
.SetName("var id = getId()--");
.SetName("var id = getId()--|");
yield return
new TestCaseData(ReadAllText("GetExpression_issue1954"))
.Returns(";re")
.SetName("function foo():Array<Int> { re");
.SetName("function foo():Array<Int> { re|");
yield return
new TestCaseData("(v:String).$(EntryPoint)")
.Returns(" (v:String).")
.SetName("(v:String).|");
yield return
new TestCaseData("(v:Iterable<Dynamic>).$(EntryPoint)")
.Returns(" (v:Iterable<Dynamic>).")
.SetName("(v:Iterable<Dynamic>).|");
yield return
new TestCaseData("(v:{x:Int, y:Int}).$(EntryPoint)")
.Returns(" (v:{x:Int, y:Int}).")
.SetName("(v:{x:Int, y:Int}).|");
yield return
new TestCaseData("(v:{x:Int, y:Int->Array<Int>}).$(EntryPoint)")
.Returns(" (v:{x:Int, y:Int->Array<Int>}).")
.SetName("(v:{x:Int, y:Int->Array<Int>}).|");
yield return
new TestCaseData("return (v:{x:Int, y:Int->Array<Int>}).$(EntryPoint)")
.Returns("return;(v:{x:Int, y:Int->Array<Int>}).")
.SetName("return (v:{x:Int, y:Int->Array<Int>}).|");
yield return
new TestCaseData("[(v:{x:Int, y:Int->Array<Int>}).$(EntryPoint)")
.Returns(";(v:{x:Int, y:Int->Array<Int>}).")
.SetName("[(v:{x:Int, y:Int->Array<Int>}).|");
yield return
new TestCaseData("${(v:{x:Int, y:Int->Array<Int>}).$(EntryPoint)")
.Returns(";(v:{x:Int, y:Int->Array<Int>}).")
.SetName("${(v:{x:Int, y:Int->Array<Int>}).|");
yield return
new TestCaseData("case _: (v:{x:Int, y:Int->Array<Int>}).$(EntryPoint)")
.Returns(":(v:{x:Int, y:Int->Array<Int>}).")
.SetName("case _: {(v:{x:Int, y:Int->Array<Int>}).|");
}
}

Expand Down

0 comments on commit c8e108c

Please sign in to comment.