Ejemplo n.º 1
0
        public void CanMatchImportSystemLibraryWithComment()
        {
            var str     = "# Write your script here.\r\nimport System.";
            var matches = DSCPythonCodeCompletionProviderCore.FindBasicImportStatements(str);

            Assert.AreEqual(1, matches.Count);
            Assert.IsTrue(matches.ContainsKey("System"));
        }
Ejemplo n.º 2
0
        public void CanIdentifyVariableTypeAndGetCompletionData()
        {
            var str = "a = 5.0\na.";

            var completionProvider = new DSCPythonCodeCompletionProviderCore();
            var completionData     = completionProvider.GetCompletionData(str);

            Assert.AreNotEqual(0, completionData.Length);
        }
Ejemplo n.º 3
0
        public void CanMatchImportSystemAndLoadLibraryAndWithComment()
        {
            var str = "# Write your script here.\r\nimport System.";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            completionProvider.UpdateImportedTypes(str);

            Assert.AreEqual(2, completionProvider.ImportedTypes.Count);
            Assert.IsTrue(defaultImports.SequenceEqual(completionProvider.ImportedTypes.Keys.ToList()));
        }
Ejemplo n.º 4
0
        public void DuplicateCallsToImportShouldBeFine()
        {
            var str = "\nimport System\nimport System";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            completionProvider.UpdateImportedTypes(str);

            Assert.AreEqual(2, completionProvider.ImportedTypes.Count);
            Assert.IsTrue(defaultImports.SequenceEqual(completionProvider.ImportedTypes.Keys.ToList()));
        }
Ejemplo n.º 5
0
        public void CanImportLibrary()
        {
            var str = "\nimport System\n";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            completionProvider.UpdateImportedTypes(str);

            Assert.AreEqual(2, completionProvider.ImportedTypes.Count);
            Assert.IsTrue(completionProvider.ImportedTypes.ContainsKey("System"));
        }
Ejemplo n.º 6
0
        public void CanMatchAllVariablesSingleLine()
        {
            var str = "a = { 'Alice': 7, 'Toby': 'Nuts' }";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            var matches = completionProvider.FindAllVariables(str);

            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(typeof(Python.Runtime.PyDict), matches["a"].Item3);
        }
Ejemplo n.º 7
0
        public void CanFindSystemCollectionsAssignmentAndType()
        {
            var str = "from System.Collections import ArrayList\na = ArrayList()\n";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            completionProvider.UpdateImportedTypes(str);
            completionProvider.UpdateVariableTypes(str);

            Assert.IsTrue(completionProvider.VariableTypes.ContainsKey("a"));
            Assert.AreEqual(typeof(System.Collections.ArrayList), completionProvider.VariableTypes["a"]);
        }
Ejemplo n.º 8
0
        public void CanImportSystemCollectionsLibraryAndGetCompletionData()
        {
            var str = "\nimport System.Collections\nSystem.Collections.";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            var completionData = completionProvider.GetCompletionData(str);
            var completionList = completionData.Select(d => d.Text);

            Assert.IsTrue(completionList.Any());
            Assert.IsTrue(completionList.Intersect(new[] { "Hashtable", "Queue", "Stack" }).Count() == 3);
            // Serial tests load an extra type (System.Collections.Immutable) in the Python engine
            Assert.IsTrue(completionData.Length >= 29 && completionData.Length <= 30);
        }
Ejemplo n.º 9
0
        public void CanGetCompletionDataForArrayListVariable()
        {
            var str = "from System.Collections import ArrayList\na = ArrayList()\na.";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();
            var matches            = completionProvider.GetCompletionData(str);

            var matchedTexts     = matches.Select(x => x.Text);
            var arrayListMembers = typeof(System.Collections.ArrayList).GetMembers()
                                   .Select(x => x.Name);
            var commonMembers = arrayListMembers.Intersect(matchedTexts).ToList();

            Assert.AreNotEqual(0, matches.Length);
            Assert.AreEqual(matches.Length, commonMembers.Count());
        }
Ejemplo n.º 10
0
        public void CanMatchAllVariableTypes()
        {
            var str = "a = { 'Alice': 7, 'Toby': 'Nuts' }\nb = {}\nc = 5.0\nd = 'pete'\ne = []";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            var matches = completionProvider.FindAllVariables(str);

            Assert.AreEqual(5, matches.Count);
            Assert.AreEqual(typeof(Python.Runtime.PyDict), matches["a"].Item3);
            Assert.AreEqual(typeof(Python.Runtime.PyDict), matches["b"].Item3);
            Assert.AreEqual(typeof(Python.Runtime.PyFloat), matches["c"].Item3);
            Assert.AreEqual(typeof(Python.Runtime.PyString), matches["d"].Item3);
            Assert.AreEqual(typeof(Python.Runtime.PyList), matches["e"].Item3);
        }
Ejemplo n.º 11
0
        public void CanImportSystemLibraryAndGetCompletionData()
        {
            var str = "\nimport System\nSystem.";
            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            var completionData = completionProvider.GetCompletionData(str);

            // Randomly verify some namepsaces are in the completion list
            var completionList = completionData.Select(d => d.Text);

            Assert.IsTrue(completionList.Any());
            Assert.IsTrue(completionList.Intersect(new[] { "IO", "Console", "Reflection" }).Count() == 3);
            Assert.AreEqual(2, completionProvider.ImportedTypes.Count);
            Assert.IsTrue(defaultImports.SequenceEqual(completionProvider.ImportedTypes.Keys.ToList()));
        }
Ejemplo n.º 12
0
        public void CanFindDifferentTypesOfImportsAndLoad()
        {
            var str = "from itertools import *\nimport math\nfrom sys import callstats\n";

            var completionProvider = new DSCPythonCodeCompletionProviderCore();

            try
            {
                completionProvider.UpdateImportedTypes(str);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }


            Assert.AreEqual(3, completionProvider.ImportedTypes.Count);
            Assert.IsTrue(completionProvider.ScopeHasVariable("repeat"));
            Assert.IsTrue(completionProvider.ScopeHasVariable("math"));
            Assert.IsTrue(completionProvider.ScopeHasVariable("callstats"));
        }
Ejemplo n.º 13
0
        public void CanGetCompletionDataForPyBuiltInTypes()
        {
            var completionProvider = new DSCPythonCodeCompletionProviderCore();
            var code    = "str.";
            var matches = completionProvider.GetCompletionData(code);

            Assert.AreNotEqual(0, matches.Length);
            Assert.IsTrue(matches.Any(x => x.Text.Contains("capitalize")));
            Assert.IsTrue(matches.Any(x => x.Text.Contains("count")));

            code    = "sys.";
            matches = completionProvider.GetCompletionData(code);
            Assert.AreNotEqual(0, matches.Length);
            Assert.IsTrue(matches.Any(x => x.Text.Contains("path")));
            Assert.IsTrue(matches.Any(x => x.Text.Contains("modules")));

            code    = "clr.";
            matches = completionProvider.GetCompletionData(code);
            Assert.AreNotEqual(0, matches.Length);
            Assert.IsTrue(matches.Any(x => x.Text.Contains("GetClrType")));
            Assert.IsTrue(matches.Any(x => x.Text.Contains("AddReference")));
        }