Esempio n. 1
0
        public void EnterCommitsCompleteNoNewLine()
        {
            using (PythonEditor view = new PythonEditor())
            {
                view.AdvancedOptions.AddNewLineAtEndOfFullyTypedWord = true;
                view.AdvancedOptions.AutoListMembers     = true;
                view.AdvancedOptions.AutoListIdentifiers = false;
                view.AdvancedOptions.HideAdvancedMembers = false;

                view.Type("min.__");

                using (var sh = view.View.WaitForSession <ICompletionSession>())
                {
                    AssertUtil.ContainsAtLeast(sh.Session.Completions(), "__class__");

                    view.Type("class__\r");
                }
                Assert.AreEqual("min.__class__\r\n", view.Text);
            }
        }
Esempio n. 2
0
        public void DecoratorCompletions()
        {
            using (PythonEditor view = new PythonEditor())
            {
                view.Type("@");

                using (var sh = view.View.WaitForSession <ICompletionSession>())
                {
                    AssertUtil.ContainsAtLeast(sh.Session.Completions(), "property", "staticmethod");
                }
            }
        }
Esempio n. 3
0
        public void TabCommits()
        {
            using (PythonEditor view = new PythonEditor())
            {
                view.AdvancedOptions.EnterCommitsIntellisense = false;
                view.AdvancedOptions.AutoListMembers          = true;
                view.AdvancedOptions.AutoListIdentifiers      = false;
                view.AdvancedOptions.HideAdvancedMembers      = false;

                view.Type("min.");

                using (var sh = view.View.WaitForSession <ICompletionSession>())
                {
                    AssertUtil.ContainsAtLeast(sh.Session.Completions(), "__class__");

                    view.Type("class\t");
                }

                Assert.AreEqual("min.__class__", view.Text);
            }
        }
Esempio n. 4
0
        public void BuiltinFunctionCompletions()
        {
            using (PythonEditor view = new PythonEditor())
            {
                view.TypeAndWaitForAnalysis("min");
                view.Type(".");

                using (var sh = view.View.WaitForSession <ICompletionSession>())
                {
                    AssertUtil.Contains(sh.Session.Completions(), "__call__");
                }
            }
        }
Esempio n. 5
0
        public void AutoListIdentifierCompletions()
        {
            using (PythonEditor view = new PythonEditor())
            {
                view.AdvancedOptions.AutoListIdentifiers = true;

                view.Type("a = ");

                foreach (var c in "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ")
                {
                    // x<space> should bring up a completion session
                    Console.WriteLine("Typing {0}", c);
                    view.Type(c.ToString());

                    using (var sh = view.View.WaitForSession <ICompletionSession>())
                    {
                        sh.Session.Dismiss();
                    }

                    view.Backspace();
                }

                view.View.AssertNoIntellisenseSession();

                // x<space> should not bring up a completion session
                // Don't check too many items, since asserting that no session
                // starts is slow.
                foreach (var c in "1234567890([{")
                {
                    Console.WriteLine("Typing {0}", c);
                    view.Type(c.ToString());

                    view.View.AssertNoIntellisenseSession();

                    view.Backspace();
                }
            }
        }
Esempio n. 6
0
        public void DisableAutoCompletions()
        {
            using (PythonEditor view = new PythonEditor())
            {
                view.AdvancedOptions.AutoListMembers     = false;
                view.AdvancedOptions.AutoListIdentifiers = false;

                foreach (global::System.String t in new[] { "a", "a.", "import " })
                {
                    Console.WriteLine("Typed " + t);
                    view.Type(t);

                    view.View.AssertNoIntellisenseSession();

                    view.Clear();
                }
            }
        }
Esempio n. 7
0
        public void BuiltinFunctionSigHelp()
        {
            using (PythonEditor view = new PythonEditor())
            {
                view.TypeAndWaitForAnalysis("min");
                view.Type("(");

                for (int retries = 10; retries > 0; --retries)
                {
                    using (var sh = view.View.WaitForSession <ISignatureHelpSession>())
                    {
                        var doc = sh.Session.Signatures[0].Documentation;
                        if (doc.Contains("still being calculated"))
                        {
                            view.VS.Sleep(100);
                            continue;
                        }
                        AssertUtil.AreEqual(new Regex(@".*min\([^)]+\).*"), doc);
                        break;
                    }
                }
            }
        }
Esempio n. 8
0
        private void AutoListTest(string code, PythonLanguageVersion version, params int[] triggerAtIndex)
        {
            using (PythonEditor view = new PythonEditor(version: version))
            {
                view.AdvancedOptions.AutoListIdentifiers = true;
                view.AdvancedOptions.AutoListMembers     = true;

                int    lastStart = 0;
                string text;
                foreach (global::System.Int32 _i in triggerAtIndex)
                {
                    bool expectCompletions = _i >= 0;
                    int  expected          = _i > 0 ? _i : -_i;

                    text = code.Substring(lastStart, expected - lastStart);
                    if (!string.IsNullOrEmpty(text))
                    {
                        Console.WriteLine("Typing '{0}' [{1}, {2})", text, lastStart, expected);
                        view.Type(text);

                        using (var sh = view.View.WaitForSession <ICompletionSession>(false))
                        {
                            // Having a session here is okay as long as nothing is selected
                            var hasCommittableCompletion = sh?.Session?.SelectedCompletionSet?.SelectionStatus?.IsSelected ?? false;
                            if (hasCommittableCompletion)
                            {
                                sh.Session.Dismiss();
                                Assert.Fail($"Completion for {text} should not have any item selected");
                            }
                            else if (sh != null)
                            {
                                sh.Session.Dismiss();
                            }
                        }
                    }

                    lastStart = expected;

                    if (expectCompletions)
                    {
                        text = code.Substring(expected, 1);
                        Console.WriteLine("Typing '{0}' [{1}, {2}) and expect completions", text, expected, expected + 1);
                        view.Type(text);

                        using (var sh = view.View.WaitForSession <ICompletionSession>())
                        {
                            sh.Session.Dismiss();
                        }

                        lastStart = expected + 1;
                    }
                }
                text = code.Substring(lastStart);
                if (!string.IsNullOrEmpty(text))
                {
                    Console.WriteLine("Typing '{0}' [{1}, {2})", text, lastStart, code.Length);
                    view.Type(text);

                    view.View.AssertNoIntellisenseSession();
                }
            }
        }