public void GetAddLocalEventHandlerCompletion() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Windows.Forms; class Script { static public void Main() { Script.Load +=| } static event EventHandler Load; static void OnLoad1(){} }"; int pos = GetCaretPosition(ref code); var data = SimpleCodeCompletion.GetCompletionData(code, pos, "test.cs"); Assert.Equal(3, data.Count()); Assert.Contains(data, x => x.DisplayText == "OnLoad - lambda"); Assert.Contains(data, x => x.DisplayText == "OnLoad - delegate"); Assert.Contains(data, x => x.DisplayText == "OnLoad - method"); Assert.Equal("OnLoad2;", data.Last().CompletionText); }
public void GenerateMemeberFullInfo() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Linq; class Script { static public void Main(string[] args) { Console.WriteLine(|args.Length); } }"; int pos = GetCaretPosition(ref code); //Console.WriteLine(| string[] info = SimpleCodeCompletion.GetMemberInfo(code, 131, "test.cs", false) .OrderBy(x => x) .ToArray(); Assert.Equal(19, info.Count()); Assert.Equal("Method: void Console.WriteLine()", info[0].GetLine(0).RemoveOverloadsInfo()); Assert.Equal("Method: void Console.WriteLine(bool value)", info[1].GetLine(0).RemoveOverloadsInfo()); }
public void GetAddExternalEventHandlerCompletion() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Windows.Forms; class Script { static public void Main() { AppDomain.CurrentDomain.AssemblyResolve += | //var form = new Form(); //form.Load+= | } }"; int pos = GetCaretPosition(ref code); var data = SimpleCodeCompletion.GetCompletionData(code, pos, "test.cs"); Assert.Equal(3, data.Count()); Assert.Contains(data, x => x.DisplayText == "OnLoad - lambda"); Assert.Contains(data, x => x.DisplayText == "OnLoad - delegate"); Assert.Contains(data, x => x.DisplayText == "OnLoad - method"); //Assert.Equal("OnLoad;", data.Last().CompletionText); }
public void ComposeMethodFieldTooltip() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Collections.Generic; using System.Linq; class Script { static IEnumerable<List<int>> test = new List<List<int>>(); static public void Main(string[] args) { test.Co|ncat(null); var t = """".Ca|st<char>(); Console.WriteLine(1); } }"; int pos = GetCaretPosition(ref code); var tooltip = SimpleCodeCompletion.GetMemberInfo(code, pos, "test.cs", true); Assert.StartsWith("Method (extension): IEnumerable<List<int>> IEnumerable<List<int>>.Concat<List<int>>(IEnumerable<List<int>> second)", tooltip.First()); //.Ca|st<char>(); tooltip = SimpleCodeCompletion.GetMemberInfo(code, pos - 4, "test.cs", true); Assert.StartsWith("Field: IEnumerable<List<int>> Script.test", tooltip.First()); //Console.Write|Line tooltip = SimpleCodeCompletion.GetMemberInfo(code, pos + 70, "test.cs", true); Assert.StartsWith("Method: void Console.WriteLine(int value) (+ 18 overloads)", tooltip.First()); }
public void GetWordAt() { //Console.Wri|teLine string word = SimpleCodeCompletion.GetWordAt("Console.WriteLine;", 11); Assert.Equal("WriteLine", word); }
public void FindReferences() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Linq; class Script { static public void Main(string[] args) { var s = new Script(); s.Test(); s.Te|st(); s.Test(); s.Test(); } static void Test(){}; }"; int pos = GetCaretPosition(ref code); //test.cs(9,11): s.Test(); var locations = SimpleCodeCompletion.FindReferences(code, pos, "test.cs"); }
public void ComposeEventPropTooltip() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Collections.Generic; using System.Linq; static class Script { static IEnumerable<List<int>> test = new List<List<int>>(); IEnumerable<List<int>> Test {get { return test;} } event Action action; static public void Main(string[] args) { var t = Script.T|est; action = null; } }"; int pos = GetCaretPosition(ref code); var tooltip = SimpleCodeCompletion.GetMemberInfo(code, pos, "test.cs", true); Assert.StartsWith("Property: IEnumerable<List<int>> Script.Test { get; }", tooltip.First()); //act|ion tooltip = SimpleCodeCompletion.GetMemberInfo(code, pos + 17, "test.cs", true); Assert.StartsWith("Event: Action Script.action", tooltip.First()); }
public void ResolveSymbolFromAsm() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Linq; class Script { static public void Main(string[] args) { var t2 = ""dsfas"".Repla|ce(""tttt"", ""); var t = ""dsfas"".Leng|th; var err = Cons|ole.Error; //Console.Write|Line(""Test {0}"", args.Length); } static int Test; }"; int pos = GetCaretPosition(ref code); var region = SimpleCodeCompletion.ResolveMember(code, pos, "test.cs"); //Assert.Equal(16, region.BeginColumn); //Assert.Equal(11, region.BeginLine); //Assert.Equal(11, region.EndLine); //Assert.Equal("test.cs", region.FileName); }
public void ResolveSymbolFromCSharp_7_Code() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Linq; class Script { static public void Main(string[] args) { Te|st = 5; Console.WriteLine(args.Length); } static int Test; }"; int pos = GetCaretPosition(ref code); var region = SimpleCodeCompletion.ResolveMember(code, pos, "test.cs"); Assert.Equal(16, region.BeginColumn); Assert.Equal(11, region.BeginLine); Assert.Equal(11, region.EndLine); Assert.Equal("test.cs", region.FileName); }
public void ResolveConstructor() { var tt = AppDomain.CurrentDomain.BaseDirectory; tt = Environment.CurrentDirectory; tt = Assembly.GetExecutingAssembly().Location; SimpleCodeCompletion.ResetProject(); //Te|st( => 127 var result = SimpleCodeCompletion.ResolveMember(@"using System; using System.Linq; class Script { static public void Main(string[] args) { var t = new Test(); Console.WriteLine(""test""); System.IO.File.Delete(""file""); } } class Test { //public Test(int count){} }", 127, "test.cs"); Assert.EndsWith(".cs", result.FileName); Assert.Equal(15, result.BeginLine); Assert.Equal(18, result.EndLine); }
public void GenerateTypeQuickInfo() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Linq; /// <summary> /// class decl /// </summary> class Script<T,T1,T2> { static public void Main(string[] args) { var p = new Script<int, int, int>(); var d = new DateT|ime(1); } }"; int pos = GetCaretPosition(ref code); string[] info = SimpleCodeCompletion.GetMemberInfo(code, pos, "test.cs", true); var p = Console.Out; Assert.Equal(1, info.Count()); Assert.Equal("Constructor: DateTime(long ticks) (+ 11 overloads)", info.First().GetLine(0)); }
public void ProcessMethodOverloadsHint() { SimpleCodeCompletion.ResetProject(); //Simulate invoking ShowMathodInfo //Console.WriteLine(| string[] signatures = SimpleCodeCompletion.GetMemberInfo(@"using System; using System.Linq; class Script { static public void Main(string[] args) { Console.WriteLine(args.Length); } }", 131, "test.cs", false); Assert.Equal(19, signatures.Count()); // may need to be updated for the new .NET versions //Simulate typing... //Console.WriteLine("Time {0}", DateTime.| var popup = new MemberInfoPanel(); popup.AddData(signatures); Assert.Equal(19, popup.items.Count); popup.ProcessMethodOverloadHint(new[] { "Time {0}" }); //'single and more' parameter methods Assert.Equal(18, popup.items.Count); popup.ProcessMethodOverloadHint(new[] { "\"Time {0}\"", "DateTime." }); //'two and more' parameter methods Assert.Equal(6, popup.items.Count); }
public void CompleteAtEmptySpace() { SimpleCodeCompletion.ResetProject(); var data = SimpleCodeCompletion.GetCompletionData(code, 129, "test.cs"); Assert.True(data.Count() > 0); }
public void CompletePartialWord() { SimpleCodeCompletion.ResetProject(); // Messa|geBox.Show("Just a test!"); var data = SimpleCodeCompletion.GetCompletionData(code, 129, "test.cs"); Assert.True(data.Where(x => x.DisplayText == "MessageBox").Any()); }
public void SuggestMissingUsingsForNestedType() { SimpleCodeCompletion.ResetProject(); var info = SimpleCodeCompletion.GetPossibleNamespaces(code, "SubTest", "test.cs").FirstOrDefault(); Assert.Equal("NSTest", info.Namespace); Assert.Equal("NSTest.TopTest.SubTest", info.FullName); }
public void TypeNamespaceRemoved() { SimpleCodeCompletion.ResetProject(); var data = SimpleCodeCompletion.GetCompletionData(code, 129, "test.cs"); //no items in display text with full namespace present Assert.True(data.Where(x => x.DisplayText == "Environment").Count() > 0); Assert.True(data.Where(x => x.DisplayText == "System.Environment").Count() == 0); }
public void SuggestMissingUsingsForPartialWordAtCaret() { SimpleCodeCompletion.ResetProject(); // F|ile. var info = SimpleCodeCompletion.GetMissingUsings(code, 184, "test.cs").FirstOrDefault(); Assert.Equal("System.IO", info.Namespace); Assert.Equal("System.IO.File", info.FullName); }
public void SuggestMissingUsingsForTopLevelType() { SimpleCodeCompletion.ResetProject(); var info = SimpleCodeCompletion.GetPossibleNamespaces(code, "File", "test.cs").ToArray(); Assert.Equal("System.IO", info[0].Namespace); Assert.Equal("System.IO.File", info[0].FullName); Assert.Equal("System.Net", info[1].Namespace); Assert.Equal("System.Net.WebRequestMethods.File", info[1].FullName); Assert.False(info[0].IsNested); Assert.True(info[1].IsNested); }
private void button1_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; listBox1.Items.Clear(); textBox1.SelectionLength = 0; int caretPos = textBox1.SelectionStart; string code = textBox1.Text; string documentName = "script.cs"; var data = SimpleCodeCompletion.GetCompletionData(code, caretPos, documentName); listBox1.Items.AddRange(data.Select(x => x.DisplayText).ToArray()); Cursor = Cursors.Default; }
public void GenerateConstructorFullInfo() { SimpleCodeCompletion.ResetProject(); //126 - new DateTime(| string[] info = SimpleCodeCompletion.GetMemberInfo(@"using System; using System.Linq; class Script { static public void Main(string[] args) { new DateTime(1, 1, 1);new Script(); } }", 126, "test.cs", false); Assert.Equal(12, info.Count()); Assert.Equal("Constructor: DateTime() (+ 11 overloads)", info.OrderBy(x => x).First().GetLine(0)); }
public void GenerateConstructorQuickInfo1() { SimpleCodeCompletion.ResetProject(); //121 - new Scrip|t() string[] info = SimpleCodeCompletion.GetMemberInfo(@"using System; using System.Linq; class Script { static public void Main(string[] args) { new Script(); } }", 121, "test.cs", true); Assert.Equal(1, info.Count()); Assert.Equal("Constructor: Script()", info.First()); }
public void GenerateMemberMethodQuickInfo() { SimpleCodeCompletion.ResetProject(); //Console.Wri|teLine string[] info = SimpleCodeCompletion.GetMemberInfo(@"using System; using System.Linq; class Script { static public void Main(string[] args) { Console.WriteLine(args.Length); } }", 124, "test.cs", true); Assert.Equal(1, info.Count()); Assert.Equal("Method: void Console.WriteLine() (+ 18 overload(s))", info.First().GetLines(2).First()); }
public void ResolveMember() { SimpleCodeCompletion.ResetProject(); //str|ing( => 85 //Tes|t( => 116 //Con|sole => 132 //Console.Write|Line => 142 //Test|Cls => 172 //int.Ma|xValue => 202 //Even|tHandler => 223 //System.IO.File.De|lete => 267 var result = SimpleCodeCompletion.ResolveMember(@"using System; using System.Linq; class Script { static public void Main(string[] args) { Test(); Console.WriteLine(""test""); TestCls t; int m = int.MaxValue; EventHandler handler; System.IO.File.Delete(""file""); System.Threading.Tasks.Task.Run(()=>Thread.Sleep(1000)); } static void Test() { } } class TestCls<T> { }", 267, "test.cs"); Assert.EndsWith(".cs", result.FileName); Assert.Equal(240, result.BeginLine); Assert.Equal(240, result.EndLine); }
public void GetCreateNewCompletion() { SimpleCodeCompletion.ResetProject(); var code = @"using System; using System.Windows.Forms; class Script { static public void Main() { Script.dialog =| } static Form dialog; "; int pos = GetCaretPosition(ref code); var data = SimpleCodeCompletion.GetCompletionData(code, pos, "test.cs"); }
public void GenerateTypeDeclarationQuickInfo() { SimpleCodeCompletion.ResetProject(); //61 - Scr|ipt string[] info = SimpleCodeCompletion.GetMemberInfo(@"using System; using System.Linq; class Script { Script script; static public void Main(string[] args) { } }", 61, "test.cs", true); Assert.Equal(1, info.Count()); Assert.Equal("Type: Script", info.First()); }
public void AddEventHandlerRespectsIncrement() { SimpleCodeCompletion.ResetProject(); var code = @"using System; class Script { static public void Main() { var text = ""test""; text +=| } }"; int pos = GetCaretPosition(ref code); var data = SimpleCodeCompletion.GetCompletionData(code, pos, "test.cs"); Assert.Empty(data); }
public void GenerateConstructorQuickInfo() { SimpleCodeCompletion.ResetProject(); //124 - new DateTim|e( string[] info = SimpleCodeCompletion.GetMemberInfo(@"using System; using System.Linq; class Script { static public void Main(string[] args) { new DateTime(1, 1, 1); } }", 124, "test.cs", true); Assert.Equal(1, info.Count()); var firstLine = info.First().GetLines(2).First(); Assert.Equal("Constructor: DateTime(int year, int month, int day) (+ 11 overloads)", firstLine); }
public void GetSimpleReferences() { SimpleCodeCompletion.ResetProject(); //MessageBox.Sh|ow var refs = SimpleCodeCompletion.FindReferences(code, 152, "test.cs"); Assert.Equal(2, refs.Count()); Assert.Equal(refs[0], @"test.cs(9,20): MessageBox.Show(""Just a test!"");"); Assert.Equal(refs[1], @"test.cs(15,20): MessageBox.Show(""Done..."");"); //Main(string[] ar|gs refs = SimpleCodeCompletion.FindReferences(code, 119, "test.cs"); Assert.True(refs.Count() == 3); Assert.Equal(refs[0], "test.cs(7,38): static public void Main(string[] args)"); Assert.Equal(refs[1], "test.cs(10,29): for (int i = 0; i < args.Length; i++)"); Assert.Equal(refs[2], "test.cs(12,31): Console.WriteLine(args[i]);"); //Main(strin|g[] args refs = SimpleCodeCompletion.FindReferences(code, 113, "test.cs"); Assert.True(refs.Count() == 1); Assert.Equal(refs[0], "test.cs(7,29): static public void Main(string[] args)"); //MessageBo|x.Show refs = SimpleCodeCompletion.FindReferences(code, 148, "test.cs"); Assert.True(refs.Count() == 3); Assert.Equal(refs[0], @"test.cs(9,9): MessageBox.Show(""Just a test!"");"); Assert.Equal(refs[1], @"test.cs(14,9): MessageBox.Show(""Done..."", ""Testing"");"); Assert.Equal(refs[2], @"test.cs(15,9): MessageBox.Show(""Done..."");"); //for (int |i refs = SimpleCodeCompletion.FindReferences(code, 190, "test.cs"); Assert.True(refs.Count() == 4); Assert.Equal(refs[0], @"test.cs(10,18): for (int i = 0; i < args.Length; i++)"); Assert.Equal(refs[1], @"test.cs(10,25): for (int i = 0; i < args.Length; i++)"); Assert.Equal(refs[2], @"test.cs(10,42): for (int i = 0; i < args.Length; i++)"); Assert.Equal(refs[3], @"test.cs(12,36): Console.WriteLine(args[i]);"); }
public void Testbed() { SimpleCodeCompletion.ResetProject(); //str|ing( => 85 //Tes|t( => 116 //Con|sole => 132 //Console.Write|Line => 142 //Test|Cls => 172 //int.Ma|xValue => 202 //Even|tHandler => 223 //System.IO.File.De|lete => 267 var result = SimpleCodeCompletion.ResolveMember(@"using System; using System.Linq; class Script { static public void Main(string[] args) { Test(); Console.WriteLine(""test""); TestCls t; int m = int.MaxValue; EventHandler handler; System.IO.File.Delete(""file"") } static void Test() { } } class TestCls<T> { }", 85, "test.cs"); }
public void GenerateMemberQuickInfo() { SimpleCodeCompletion.ResetProject(); //132 - Console.Out|putEncoding; var code = @"using System; using System.Linq; class Script { static public void Main(string[] args) { var p = Console.O|ut; } }"; int pos = GetCaretPosition(ref code); string[] info = SimpleCodeCompletion.GetMemberInfo(code, pos, "test.cs", true); var p = Console.Out; Assert.Equal(1, info.Count()); Assert.Equal("Property: TextWriter Console.Out { get; }", info.First().GetLine(0)); }