Skip to content

Commit

Permalink
Intellisence now properly only displays the values of enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
Þorgeir committed Aug 9, 2016
1 parent 1f49e0c commit 19ea2ab
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ from val in help.Value
private static Dictionary<string, List<MemberDetails>> GetAllMemberInfos(Type varType, BindingFlags bindings)
{
var helpList = new Dictionary<string, List<MemberDetails>>();

// If it is enum only display it's fields.
if (varType.IsEnum)
{
foreach (var field in varType.GetFields(bindings))
{
helpList.Add(field.Name, new List<MemberDetails> { RexReflectionUtils.GetMemberDetails(field) });
}
return helpList;
}

// properties
foreach (var prop in GetProperties(varType, bindings))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,175 +11,175 @@

namespace Rex.Utilities.Test
{
[TestFixture]
class InputStateMachineTest
{
[SetUp]
public void ClassSetup()
{
RexISM.Repaint = () => { };
RexISM.DebugLog = msg => Console.WriteLine(msg);
RexISM.ExecuteCode = TestExecute;
RexISM.Code = string.Empty;
RexISM.Enter_NoInput();
RexISM.IntelliSenceHelp.Clear();
RexISM.IntelliSenceLastCode = string.Empty;
RexISM.InputBuffer.Clear();
}

[Test]
public void UpdateTest()
{
Assert.AreEqual(RexInputState.NoInput, RexISM.State);

RexISM.Update();
Assert.AreEqual(RexInputState.NoInput, RexISM.State);

RexISM.Enter_Typing();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);

RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);

PressKey(KeyCode.Escape);
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsFalse(RexISM.DisplayHelp);
Assert.IsEmpty(RexISM.IntelliSenceHelp);
}

[Test]
public void IntellisenseTest()
{
RexISM.Enter_Typing();
RexISM.Code = "Math.P";
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);
Assert.IsNotEmpty(RexISM.IntelliSenceHelp);
}

[Test]
public void IntellisenseSelectionTest()
{
RexISM.Enter_Typing();
RexISM.Code = "Math.P";
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);
Assert.IsNotEmpty(RexISM.IntelliSenceHelp);
Assert.AreEqual(RexISM.SelectedHelp, -1);

PressKey(KeyCode.DownArrow);
Assert.AreEqual(RexInputState.IntelliSelect, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, 0);

RexISM.Enter_Typing();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, -1);

RexISM.Code = "x = Math.";
RexISM.Update();
PressKey(KeyCode.DownArrow);
Assert.AreEqual(RexInputState.IntelliSelect, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, 0);


PressKey(KeyCode.DownArrow);
Assert.AreEqual(RexInputState.IntelliSelect, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, 1);

PressKey(KeyCode.Return);
Assert.IsTrue(RexISM.Code.Contains("x = Math."));
}

[Test]
public void SelectHelpTest()
{
TestIntelliSelect("Math.Abs(Math.P",
new[] { "Math.Abs(Math.PI", "Math.Abs(Math.Pow" });
TestIntelliSelect("Math.Abs(String.Em",
new[] { "Math.Abs(String.Empty", "Math.Abs(String.IsNullOrEmpty" });
TestIntelliSelect("Math.Abs(TypeCode.",
Enum.GetNames(typeof(TypeCode)).OrderBy(i => i).Select(i => "Math.Abs(TypeCode." + i));

TestIntelliSelect("Math.Abs( 1, 2, Math.P",
new[] { "Math.Abs( 1, 2, Math.PI", "Math.Abs( 1, 2, Math.Pow" });
TestIntelliSelect("Math.Abs( 1, 2, String.Em",
new[] { "Math.Abs( 1, 2, String.Empty", "Math.Abs( 1, 2, String.IsNullOrEmpty" });
TestIntelliSelect("Math.Abs( 1, 2, TypeCode.",
Enum.GetNames(typeof(TypeCode)).OrderBy(i => i).Select(i => "Math.Abs( 1, 2, TypeCode." + i));

//Math.Cos(20).E
TestIntelliSelect("Math.Cos(20).E",
new[] { "Math.Cos(20).Equals" }, false);

TestIntelliSelect("Math.P",
new[] { "Math.PI", "Math.Pow" }, false);
TestIntelliSelect("Math.E",
new[] { "Math.E", "Math.Exp", "Math.Ceiling" }, false);

TestIntelliSelect("Environme",
new[] { "Environment" }, false);
}

[Test]
public void NestedTypeTest()
{
// Nested Types, need to chcek them.
TestIntelliSelect("MyNestedClass",
new[] { "NestedTest.MyNestedClass" }, false);
}

void TestIntelliSelect(string code, IEnumerable<string> selections, bool withMethodOverloads = true)
{
RexISM.Enter_Typing();
RexISM.Code = code;
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);

var help = RexISM.IntelliSenceHelp.Where(i => !i.IsMethodOverload);
var meth = RexISM.IntelliSenceHelp.Where(i => i.IsMethodOverload);

Assert.IsNotEmpty(help);
if (withMethodOverloads)
Assert.IsNotEmpty(meth);
else
Assert.IsEmpty(meth);

Assert.AreEqual(-1, RexISM.SelectedHelp);
var count = 0;
foreach (var select in selections)
{
PressKey(KeyCode.DownArrow);
Assert.AreEqual(select, RexISM.ReplacementString(), "At i = " + count);
Assert.AreEqual(count++, RexISM.SelectedHelp);
}
}

public void TestExecute(string code)
{
Console.WriteLine(code);
RexHelperTest.CompileAndRun(code);
}
public static void PressKey(KeyCode key, int repeat = 1)
{
for (int i = 0; i < repeat; i++)
{
RexISM.PressKey(key);
RexISM.Update();
}
}
}

public class NestedTest
{
public class MyNestedClass
{
public class NestTest2 { }
}
}
[TestFixture]
class InputStateMachineTest
{
[SetUp]
public void ClassSetup()
{
RexISM.Repaint = () => { };
RexISM.DebugLog = msg => Console.WriteLine(msg);
RexISM.ExecuteCode = TestExecute;
RexISM.Code = string.Empty;
RexISM.Enter_NoInput();
RexISM.IntelliSenceHelp.Clear();
RexISM.IntelliSenceLastCode = string.Empty;
RexISM.InputBuffer.Clear();
}

[Test]
public void UpdateTest()
{
Assert.AreEqual(RexInputState.NoInput, RexISM.State);

RexISM.Update();
Assert.AreEqual(RexInputState.NoInput, RexISM.State);

RexISM.Enter_Typing();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);

RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);

PressKey(KeyCode.Escape);
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsFalse(RexISM.DisplayHelp);
Assert.IsEmpty(RexISM.IntelliSenceHelp);
}

[Test]
public void IntellisenseTest()
{
RexISM.Enter_Typing();
RexISM.Code = "Math.P";
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);
Assert.IsNotEmpty(RexISM.IntelliSenceHelp);
}

[Test]
public void IntellisenseSelectionTest()
{
RexISM.Enter_Typing();
RexISM.Code = "Math.P";
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);
Assert.IsNotEmpty(RexISM.IntelliSenceHelp);
Assert.AreEqual(RexISM.SelectedHelp, -1);

PressKey(KeyCode.DownArrow);
Assert.AreEqual(RexInputState.IntelliSelect, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, 0);

RexISM.Enter_Typing();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, -1);

RexISM.Code = "x = Math.";
RexISM.Update();
PressKey(KeyCode.DownArrow);
Assert.AreEqual(RexInputState.IntelliSelect, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, 0);


PressKey(KeyCode.DownArrow);
Assert.AreEqual(RexInputState.IntelliSelect, RexISM.State);
Assert.AreEqual(RexISM.SelectedHelp, 1);

PressKey(KeyCode.Return);
Assert.IsTrue(RexISM.Code.Contains("x = Math."));
}

[Test]
public void SelectHelpTest()
{
TestIntelliSelect("Math.Abs(Math.P",
new[] { "Math.Abs(Math.PI", "Math.Abs(Math.Pow" });
TestIntelliSelect("Math.Abs(String.Em",
new[] { "Math.Abs(String.Empty", "Math.Abs(String.IsNullOrEmpty" });
TestIntelliSelect("Math.Abs(TypeCode.",
Enum.GetNames(typeof(TypeCode)).OrderBy(i => i).Select(i => "Math.Abs(TypeCode." + i));

TestIntelliSelect("Math.Abs( 1, 2, Math.P",
new[] { "Math.Abs( 1, 2, Math.PI", "Math.Abs( 1, 2, Math.Pow" });
TestIntelliSelect("Math.Abs( 1, 2, String.Em",
new[] { "Math.Abs( 1, 2, String.Empty", "Math.Abs( 1, 2, String.IsNullOrEmpty" });
TestIntelliSelect("Math.Abs( 1, 2, TypeCode.",
Enum.GetNames(typeof(TypeCode)).OrderBy(i => i).Select(i => "Math.Abs( 1, 2, TypeCode." + i));

//Math.Cos(20).E
TestIntelliSelect("Math.Cos(20).E",
new[] { "Math.Cos(20).Equals" }, false);

TestIntelliSelect("Math.P",
new[] { "Math.PI", "Math.Pow" }, false);
TestIntelliSelect("String.Em",
new[] { "String.Empty", "String.IsNullOrEmpty" }, false);

TestIntelliSelect("Environme",
new[] { "Environment" }, false);
}

[Test]
public void NestedTypeTest()
{
// Nested Types, need to chcek them.
TestIntelliSelect("MyNestedClass",
new[] { "NestedTest.MyNestedClass" }, false);
}

void TestIntelliSelect(string code, IEnumerable<string> selections, bool withMethodOverloads = true)
{
RexISM.Enter_Typing();
RexISM.Code = code;
RexISM.Update();
Assert.AreEqual(RexInputState.Typing, RexISM.State);
Assert.IsTrue(RexISM.DisplayHelp);

var help = RexISM.IntelliSenceHelp.Where(i => !i.IsMethodOverload);
var meth = RexISM.IntelliSenceHelp.Where(i => i.IsMethodOverload);

Assert.IsNotEmpty(help);
if (withMethodOverloads)
Assert.IsNotEmpty(meth);
else
Assert.IsEmpty(meth);

Assert.AreEqual(-1, RexISM.SelectedHelp);
var count = 0;
foreach (var select in selections)
{
PressKey(KeyCode.DownArrow);
Assert.AreEqual(select, RexISM.ReplacementString(), "At i = " + count);
Assert.AreEqual(count++, RexISM.SelectedHelp);
}
}

public void TestExecute(string code)
{
Console.WriteLine(code);
RexHelperTest.CompileAndRun(code);
}
public static void PressKey(KeyCode key, int repeat = 1)
{
for (int i = 0; i < repeat; i++)
{
RexISM.PressKey(key);
RexISM.Update();
}
}
}

public class NestedTest
{
public class MyNestedClass
{
public class NestTest2 { }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,27 @@ public void IntellisenseCaseInsensitveTest()

// Variables:
SetVar("myVar", new DummyOutput());
EqualIntellisence("myVar.V", "myVar.V");
EqualIntellisence("myVar.Va", "myVar.Va");
EqualIntellisence("myVar.V", "myVar.v");
EqualIntellisence("myVar.Va", "myVar.va");
}

struct ArgsTester
{
public void WithDefaultArg(int myInt = 42) { }
public void WithoutDefaultArg(int myInt) { }
}

[Test]
public void DefaultArgs()
{
// Variables:
SetVar("myVar", new ArgsTester());
var results = Parser.Intellisence("myVar.With").ToArray();
var with = results[0].ToString();
var without = results[1].ToString();

Assert.AreEqual("void WithDefaultArg(int myInt = 42)", with);
Assert.AreEqual("void WithoutDefaultArg(int myInt)", with);
}

private void EqualIntellisence(string search1, string search2)
Expand Down
Loading

0 comments on commit 19ea2ab

Please sign in to comment.