/// <summary>
        /// Single auto indent test
        /// </summary>
        /// <param name="project">containting project</param>
        /// <param name="filename">filename in the project</param>
        /// <param name="line">zero-based line</param>
        /// <param name="column">zero based column</param>
        /// <param name="expectedText"></param>
        private static void TypingTest(VisualStudioApp app, Project project, string filename, int line, int column, string expectedText, Action typing)
        {
            var item   = project.ProjectItems.Item(filename);
            var window = item.Open();

            window.Activate();

            var doc      = app.GetDocument(item.Document.FullName);
            var textLine = doc.TextView.TextViewLines[line];

            ((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
                try {
                    doc.TextView.Caret.MoveTo(textLine.Start + column);
                } catch (Exception) {
                    Debug.Fail("Bad position for moving caret");
                }
            }));

            typing();

            string actual = null;

            for (int i = 0; i < 100; i++)
            {
                actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                if (expectedText == actual)
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            Assert.AreEqual(expectedText, actual);
        }
예제 #2
0
        private void OutlineTest(string filename, params ExpectedTag[] expected)
        {
            using (var app = new VisualStudioApp()) {
                var prevOption = NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen;
                try {
                    NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen = true;

                    var project = app.OpenProject(@"TestData\Outlining\Outlining.sln");

                    var item   = project.ProjectItems.Item(filename);
                    var window = item.Open();
                    window.Activate();

                    System.Threading.Thread.Sleep(2000);

                    var doc      = app.GetDocument(item.Document.FullName);
                    var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                    var tags     = doc.GetTaggerAggregator <IOutliningRegionTag>(doc.TextView.TextBuffer).GetTags(new SnapshotSpan(snapshot, 0, snapshot.Length));

                    VerifyTags(doc.TextView.TextBuffer, tags, expected);
                }
                finally {
                    NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen = prevOption;
                }
            }
        }
예제 #3
0
        private static void AutoBraceCompetionTest(VisualStudioApp app, Project project, string typedText, string expectedText)
        {
            var item   = project.ProjectItems.Item("Program.py");
            var window = item.Open();

            window.Activate();

            Keyboard.Type(typedText);

            var doc = app.GetDocument(item.Document.FullName);

            string actual = null;

            for (int i = 0; i < 100; i++)
            {
                actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                if (expectedText == actual)
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }

            Assert.AreEqual(expectedText, actual);

            window.Document.Close(vsSaveChanges.vsSaveChangesNo);
        }
예제 #4
0
        /// <summary>
        /// Single auto indent test
        /// </summary>
        /// <param name="project">containting project</param>
        /// <param name="filename">filename in the project</param>
        /// <param name="line">zero-based line</param>
        /// <param name="column">zero based column</param>
        /// <param name="expectedText"></param>
        private static void AutoIndentExistingTest(VisualStudioApp app, Project project, string filename, int line, int column, string expectedText)
        {
            var item   = project.ProjectItems.Item(filename);
            var window = item.Open();

            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);

            doc.SetFocus();
            var textLine = doc.TextView.TextViewLines[line];

            ((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
                doc.TextView.Caret.MoveTo(textLine.Start + column);
                ((UIElement)doc.TextView).Focus();
            }));

            Keyboard.Type("\r");

            string actual = null;

            for (int i = 0; i < 100; i++)
            {
                actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                if (expectedText == actual)
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            Assert.AreEqual(actual, expectedText);
        }
예제 #5
0
        private static void RemoveSmartTagTest(VisualStudioApp app, string filename, int line, int column, bool allScopes, string expectedText)
        {
            var project = app.OpenProject(app.CopyProjectForTest(@"TestData\RemoveImport.sln"));
            var item    = project.ProjectItems.Item(filename);
            var window  = item.Open();

            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);

            VsProjectAnalyzer analyzer = null;

            doc.InvokeTask(async() => {
                var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                doc.TextView.Caret.MoveTo(point);
                analyzer = await doc.WaitForAnalyzerAtCaretAsync();
            });

            Assert.IsNotNull(analyzer, "Failed to get analyzer");
            analyzer.WaitForCompleteAnalysis(_ => true);

            if (allScopes)
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
            }
            else
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
            }

            doc.WaitForText(expectedText);
        }
예제 #6
0
        private static void RemoveSmartTagTest(string filename, int line, int column, bool allScopes, string expectedText)
        {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\RemoveImport.sln");
                var item    = project.ProjectItems.Item(filename);
                var window  = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);

                doc.Invoke(() => {
                    var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                    doc.TextView.Caret.MoveTo(point);
                });

                if (allScopes)
                {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
                }
                else
                {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
                }

                doc.WaitForText(expectedText);
            }
        }
예제 #7
0
        public void ClassificationTest()
        {
            var project = DebugProject.OpenProject(@"Python.VS.TestData\Classification.sln");

            var item   = project.ProjectItems.Item("Program.py");
            var window = item.Open();

            window.Activate();


            var app = new VisualStudioApp(VsIdeTestHostContext.Dte);
            var doc = app.GetDocument(item.Document.FullName);

            var snapshot   = doc.TextView.TextBuffer.CurrentSnapshot;
            var classifier = doc.Classifier;
            var spans      = classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));

            VerifyClassification(doc.TextView.TextBuffer, spans,
                                 new Classifcation("comment", 0, 8, "#comment"),
                                 new Classifcation("whitespace", 8, 10, "\r\n"),
                                 new Classifcation("literal", 10, 11, "1"),
                                 new Classifcation("whitespace", 11, 13, "\r\n"),
                                 new Classifcation("string", 13, 18, "\"abc\""),
                                 new Classifcation("whitespace", 18, 20, "\r\n"),
                                 new Classifcation("keyword", 20, 23, "def"),
                                 new Classifcation("identifier", 24, 25, "f"),
                                 new Classifcation("Python open grouping", 25, 26, "("),
                                 new Classifcation("Python close grouping", 26, 27, ")"),
                                 new Classifcation("operator", 27, 28, ":"),
                                 new Classifcation("keyword", 29, 33, "pass"),
                                 new Classifcation("whitespace", 33, 35, "\r\n"),
                                 new Classifcation("string", 35, 46, "'abc\\\r\ndef'")
                                 );
        }
예제 #8
0
        private static void AutoIndentTest(VisualStudioApp app, Project project, string typedText, string expectedText)
        {
            var item   = project.ProjectItems.Item("Program.py");
            var window = item.Open();

            window.Activate();

            expectedText = Regex.Replace(expectedText, "^\\s+$", "", RegexOptions.Multiline);

            var doc = app.GetDocument(item.Document.FullName);

            doc.InvokeTask(() => doc.WaitForAnalysisAtCaretAsync());
            // A little extra time for things to load, because VS...
            System.Threading.Thread.Sleep(500);

            Keyboard.Type(typedText);

            string actual = null;

            for (int i = 0; i < 100; i++)
            {
                actual = Regex.Replace(doc.TextView.TextBuffer.CurrentSnapshot.GetText(),
                                       "^\\s+$", "", RegexOptions.Multiline);

                if (expectedText == actual)
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            Assert.AreEqual(expectedText, actual);

            window.Document.Close(vsSaveChanges.vsSaveChangesNo);
        }
예제 #9
0
        private static void RemoveLightBulbTest(VisualStudioApp app, string filename, int line, int column, bool allScopes, string expectedText)
        {
            var project = app.OpenProject(app.CopyProjectForTest(@"TestData\RemoveImport.sln"));
            var item    = project.ProjectItems.Item(filename);
            var window  = item.Open();

            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);

            doc.InvokeTask(async() => {
                var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                doc.TextView.Caret.MoveTo(point);

                // Note that this waits for language server to be up and running
                // but that doesn't mean the quick actions are ready for that document
                // so the test will need to wait/try again until the correct results
                // are in or until a predetermined timeout.
                await doc.WaitForLanguageServerInitializedAtCaretAsync();
            });

            if (allScopes)
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
            }
            else
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
            }

            doc.WaitForText(expectedText);
        }
예제 #10
0
        private static void AddSmartTagTest(VisualStudioApp app, string filename, int line, int column, string[] expectedActions, int invokeAction = -1, string expectedText = null)
        {
            var project = app.OpenProject(@"TestData\AddImport.sln");
            var item    = project.ProjectItems.Item(filename);
            var window  = item.Open();

            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);

            AddSmartTagTest(doc, line, column, expectedActions, invokeAction, expectedText);
        }
예제 #11
0
		public void CreateNewScript() {
			using (var app = new VisualStudioApp()) {
				var project = app.CreateProject(
					RConstants.TemplateLanguageName, RConstants.ProjectTemplate_EmptyProject,
					System.IO.Path.GetTempPath(), "RTestProject");
				app.OpenSolutionExplorer().SelectProject(project);
				using (var newItem = NewItemDialog.FromDte(app)) {
					AutomationWrapper.Select(newItem.ProjectTypes.FindItem("R Script"));
					newItem.FileName = "my-script.r";
					newItem.OK();
				}

				var document = app.GetDocument("my-script.r");
				document.SetFocus();
				document.Type("2 -> a");
				document.Text.Should().Be("2 -> a# R Script");
			}
		}
예제 #12
0
        public void CreateNewScript()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    RConstants.TemplateLanguageName, RConstants.ProjectTemplate_EmptyProject,
                    System.IO.Path.GetTempPath(), "RTestProject");
                app.OpenSolutionExplorer().SelectProject(project);
                using (var newItem = NewItemDialog.FromDte(app)) {
                    AutomationWrapper.Select(newItem.ProjectTypes.FindItem("R Script"));
                    newItem.FileName = "my-script.r";
                    newItem.OK();
                }

                var document = app.GetDocument("my-script.r");
                document.SetFocus();
                document.Type("2 -> a");
                document.Text.Should().Be("2 -> a# R Script");
            }
        }
예제 #13
0
        public void Parameters()
        {
            var getreclimit = new[] { "from sys import getrecursionlimit" };

            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\AddImport.sln");
                var item    = project.ProjectItems.Item("Parameters.py");
                var window  = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);

                AddSmartTagTest(doc, 1, 19, _NoSmartTags);
                AddSmartTagTest(doc, 1, 30, getreclimit);

                AddSmartTagTest(doc, 4, 18, _NoSmartTags);
                AddSmartTagTest(doc, 7, 18, _NoSmartTags);
                AddSmartTagTest(doc, 10, 20, _NoSmartTags);
                AddSmartTagTest(doc, 13, 22, _NoSmartTags);
                AddSmartTagTest(doc, 16, 22, _NoSmartTags);
                AddSmartTagTest(doc, 19, 22, _NoSmartTags);

                AddSmartTagTest(doc, 19, 35, getreclimit);

                AddSmartTagTest(doc, 22, 25, _NoSmartTags);
                AddSmartTagTest(doc, 22, 56, getreclimit);

                AddSmartTagTest(doc, 25, 38, _NoSmartTags);
                AddSmartTagTest(doc, 25, 38, _NoSmartTags);
                AddSmartTagTest(doc, 25, 48, getreclimit);

                AddSmartTagTest(doc, 29, 12, _NoSmartTags);
                AddSmartTagTest(doc, 29, 42, getreclimit);

                AddSmartTagTest(doc, 34, 26, _NoSmartTags);
                AddSmartTagTest(doc, 34, 31, getreclimit);

                AddSmartTagTest(doc, 42, 16, _NoSmartTags);
                AddSmartTagTest(doc, 51, 16, _NoSmartTags);
            }
        }
예제 #14
0
        public void OutliningTest()
        {
            var project = DebugProject.OpenProject(@"Python.VS.TestData\Outlining.sln");

            var item   = project.ProjectItems.Item("Program.py");
            var window = item.Open();

            window.Activate();


            var app = new VisualStudioApp(VsIdeTestHostContext.Dte);
            var doc = app.GetDocument(item.Document.FullName);

            var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
            var tags     = doc.GetTaggerAggregator <IOutliningRegionTag>(doc.TextView.TextBuffer).GetTags(new SnapshotSpan(snapshot, 0, snapshot.Length));

            VerifyTags(doc.TextView.TextBuffer, tags,
                       new ExpectedTag(8, 18, "\r\n    pass"),
                       new ExpectedTag(40, 50, "\r\n    pass"),
                       new ExpectedTag(72, 82, "\r\n    pass"),
                       new ExpectedTag(104, 131, "\r\n    pass\r\nelse:\r\n    pass"),
                       new ExpectedTag(153, 185, "\r\n    pass\r\nelif True:\r\n    pass")
                       );
        }
예제 #15
0
        private static EditorWindow OpenItem(VisualStudioApp app, string startItem, Project project, out Window window)
        {
            EnvDTE.ProjectItem item = null;
            if (startItem.IndexOf('\\') != -1)
            {
                var items = project.ProjectItems;
                foreach (var itemName in startItem.Split('\\'))
                {
                    Console.WriteLine(itemName);
                    item  = items.Item(itemName);
                    items = item.ProjectItems;
                }
            }
            else
            {
                item = project.ProjectItems.Item(startItem);
            }

            Assert.IsNotNull(item);

            window = item.Open();
            window.Activate();
            return(app.GetDocument(item.Document.FullName));
        }
예제 #16
0
        private static void AddSmartTagTest(string filename, int line, int column, string[] expectedActions, int invokeAction = -1, string expectedText = null) {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\AddImport.sln");
                var item = project.ProjectItems.Item(filename);
                var window = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);

                AddSmartTagTest(doc, line, column, expectedActions, invokeAction, expectedText);
            }
        }
예제 #17
0
        /// <summary>
        /// Single auto indent test
        /// </summary>
        /// <param name="project">containting project</param>
        /// <param name="filename">filename in the project</param>
        /// <param name="line">zero-based line</param>
        /// <param name="column">zero based column</param>
        /// <param name="expectedText"></param>
        private static void AutoIndentExistingTest(VisualStudioApp app, Project project, string filename, int line, int column, string expectedText) {
            var item = project.ProjectItems.Item(filename);
            var window = item.Open();
            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);
            doc.SetFocus();
            var textLine = doc.TextView.TextViewLines[line];

            ((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
                doc.TextView.Caret.MoveTo(textLine.Start + column);
                ((UIElement)doc.TextView).Focus();
            }));

            Keyboard.Type("\r");

            string actual = null;
            for (int i = 0; i < 100; i++) {
                actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                if (expectedText == actual) {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            Assert.AreEqual(actual, expectedText);
        }
예제 #18
0
        private static void RemoveSmartTagTest(string filename, int line, int column, bool allScopes, string expectedText) {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\RemoveImport.sln");
                var item = project.ProjectItems.Item(filename);
                var window = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);

                doc.Invoke(() => {
                    var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                    doc.TextView.Caret.MoveTo(point);
                });

                if (allScopes) {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
                } else {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
                }

                doc.WaitForText(expectedText);
            }
        }
예제 #19
0
        /// <summary>
        /// Single auto indent test
        /// </summary>
        /// <param name="project">containting project</param>
        /// <param name="filename">filename in the project</param>
        /// <param name="line">zero-based line</param>
        /// <param name="column">zero based column</param>
        /// <param name="expectedText"></param>
        private static void TypingTest(VisualStudioApp app, Project project, string filename, int line, int column, string expectedText, Action typing) {
            var item = project.ProjectItems.Item(filename);
            var window = item.Open();
            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);
            doc.SetFocus();
            var textLine = doc.TextView.TextViewLines[line];

            ((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
                try {
                    doc.TextView.Caret.MoveTo(textLine.Start + column);
                    ((UIElement)doc.TextView).Focus();
                } catch (Exception) {
                    Debug.Fail("Bad position for moving caret");
                }
            }));

            typing();

            string actual = null;
            for (int i = 0; i < 100; i++) {
                actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                if (expectedText == actual) {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            Assert.AreEqual(expectedText, actual);
        }
예제 #20
0
        private static void AutoIndentTest(VisualStudioApp app, Project project, string typedText, string expectedText) {
            var item = project.ProjectItems.Item("Program.py");
            var window = item.Open();
            window.Activate();

            Keyboard.Type(typedText);

            var doc = app.GetDocument(item.Document.FullName);

            string actual = null;
            for (int i = 0; i < 100; i++) {
                actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                if (expectedText == actual) {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            Assert.AreEqual(expectedText, actual);

            window.Document.Close(vsSaveChanges.vsSaveChangesNo);
        }
예제 #21
0
        /// <summary>
        /// Runs a single formatting test
        /// </summary>
        /// <param name="filename">The filename of the document to perform formatting in (lives in FormattingTests.sln)</param>
        /// <param name="selection">The selection to format, or null if formatting the entire document</param>
        /// <param name="expectedText">The expected source code after the formatting</param>
        /// <param name="changedSpans">The spans which should be marked as changed in the buffer after formatting</param>
        private static void FormattingTest(string filename, Span?selection, string expectedText, Span[] changedSpans)
        {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\FormattingTests\FormattingTests.sln");
                var item    = project.ProjectItems.Item(filename);
                var window  = item.Open();
                window.Activate();
                var doc = app.GetDocument(item.Document.FullName);

                var aggFact    = app.ComponentModel.GetService <IViewTagAggregatorFactoryService>();
                var changeTags = aggFact.CreateTagAggregator <ChangeTag>(doc.TextView);

                // format the selection or document
                if (selection == null)
                {
                    DoFormatDocument();
                }
                else
                {
                    doc.Invoke(() => doc.TextView.Selection.Select(new SnapshotSpan(doc.TextView.TextBuffer.CurrentSnapshot, selection.Value), false));
                    DoFormatSelection();
                }

                // verify the contents are correct
                string actual = null;
                for (int i = 0; i < 100; i++)
                {
                    actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                    if (expectedText == actual)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(100);
                }
                Assert.AreEqual(expectedText, actual);

                // verify the change tags are correct
                var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                var tags     = changeTags.GetTags(
                    new SnapshotSpan(
                        doc.TextView.TextBuffer.CurrentSnapshot,
                        new Span(0, doc.TextView.TextBuffer.CurrentSnapshot.Length)
                        )
                    );
                List <Span> result = new List <Span>();
                foreach (var tag in tags)
                {
                    result.Add(
                        new Span(
                            tag.Span.Start.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position,
                            tag.Span.End.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position
                            )
                        );
                }

                // dump the spans for creating tests easier
                foreach (var span in result)
                {
                    Console.WriteLine(span);
                }

                Assert.AreEqual(result.Count, changedSpans.Length);
                for (int i = 0; i < result.Count; i++)
                {
                    Assert.AreEqual(result[i], changedSpans[i]);
                }
            }
        }
        public void TestClientServerIntelliSenseModes()
        {
            string
                solutionLabel                       = "Solution 'ClientServerCode' (1 project)",
                projectLabel                        = "ClientServerCode",
                nodeDirectoryLabel                  = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node),
                nodeSubDirectoryLabel               = NodejsFolderNode.AppendLabel("NodeSubDirectory", FolderContentType.Node),
                browserDirectoryLabel               = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser),
                emptyBrowserSubDirectoryLabel       = "BrowserSubDirectory",
                browserSubDirectoryLabel            = NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Browser),
                mixedDirectoryLabel                 = NodejsFolderNode.AppendLabel("MixedDirectory", FolderContentType.Mixed),
                mixedDirectoryBrowserDirectoryLabel = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser),
                mixedDirectoryNodeDirectoryLabel    = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node),
                browserCodeLabel                    = "browserCode.js",
                mixedDirectoryRenamedLabel          = NodejsFolderNode.AppendLabel("MixedDirectoryRenamed", FolderContentType.Mixed);

            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\ClientServerCode\ClientServerCode.sln");

                using (new NodejsOptionHolder(NodejsPackage.Instance.GeneralOptionsPage, "ShowBrowserAndNodeLabels", true)) {
                    // Wait until project is loaded
                    var solutionExplorer = app.OpenSolutionExplorer();

                    solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        "app.js");

                    var nodejsProject = app.GetProject("ClientServerCode").GetNodejsProject();

                    var projectNode = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel);

                    var browserDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserDirectory,
                        "Browser directories should be labeled as such. Could not find " + browserDirectoryLabel);

                    var browserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        emptyBrowserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserSubDirectory,
                        "Project initialization: could not find " + emptyBrowserSubDirectoryLabel);

                    var nodeDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        nodeDirectoryLabel
                        );
                    Assert.IsNotNull(
                        nodeDirectory,
                        "Node directories should be labeled as such. Could not find " + nodeDirectoryLabel);

                    var nodeSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        nodeDirectoryLabel,
                        nodeSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        nodeSubDirectory,
                        "Project initialization: could not find " + nodeSubDirectoryLabel);

                    projectNode.Select();
                    using (var newItem = NewItemDialog.FromDte(app)) {
                        newItem.FileName = "newItem.js";
                        newItem.OK();
                    }

                    Assert.AreEqual(
                        "Compile",
                        nodejsProject.GetItemType("newItem.js"),
                        "Top level files should be set to item type 'Compile'");

                    Keyboard.Type("process.");
                    Keyboard.Type(Keyboard.CtrlSpace.ToString());

                    using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"newItem.js")).WaitForSession <ICompletionSession>()) {
                        var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText);
                        Assert.IsTrue(
                            completions.Contains("env"),
                            "New documents of the node type should open with default VS editor"
                            );
                    }

                    browserSubDirectory.Select();
                    using (var newBrowserItem = NewItemDialog.FromDte(app)) {
                        newBrowserItem.FileName = "newBrowserItem.js";
                        newBrowserItem.OK();
                    }

                    Keyboard.Type("document.");
                    System.Threading.Thread.Sleep(2000);
                    Keyboard.Type(Keyboard.CtrlSpace.ToString());

                    using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\browserSubDirectory\newBrowserItem.js")).WaitForSession <ICompletionSession>()) {
                        var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText);
                        Assert.IsTrue(
                            completions.Contains("body"),
                            "New documents of the browser type should open with default VS editor"
                            );
                    }

                    browserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserSubDirectory,
                        "Folder label was not updated to " + browserSubDirectoryLabel);

                    var newBrowserItemFile = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel,
                        "newBrowserItem.js"
                        );
                    Assert.AreEqual(
                        "Content",
                        nodejsProject.GetItemType(@"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js"),
                        "Adding a javascript file to a 'browser' directory should set the item type as Content.");

                    var mixedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryLabel
                        );
                    Assert.IsNotNull(
                        mixedDirectory,
                        "Folder with mixed browser/node content should be specified as such. Could not find: " + mixedDirectoryLabel);

                    nodeDirectory.Select();
                    using (var newTypeScriptItem = NewItemDialog.FromDte(app)) {
                        newTypeScriptItem.FileName = "newTypeScriptItem.ts";
                        newTypeScriptItem.OK();
                    }

                    Assert.AreEqual(
                        "TypeScriptCompile",
                        nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"),
                        "Non-javascript files should retain their content type.");

                    var newBrowserItemNode = nodejsProject.FindNodeByFullPath(
                        Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js")
                        );

                    newBrowserItemNode.ExcludeFromProject();
                    var excludedBrowserItem = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        emptyBrowserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        emptyBrowserSubDirectoryLabel,
                        "Label should be removed when there are no included javascript files the directory. Could not find " + emptyBrowserSubDirectoryLabel);

                    (newBrowserItemNode as NodejsFileNode).IncludeInProject(false);
                    var includedBrowserItem = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        includedBrowserItem,
                        "Label should be added when a javascript file is included in the directory. Could not find " + browserSubDirectoryLabel);

                    var mixedDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath(
                        Path.Combine(nodejsProject.ProjectHome, @"MixedDirectory\"));

                    System.Threading.Thread.Sleep(2000);
                    mixedDirectory.Select();
                    Keyboard.PressAndRelease(Key.F2);
                    Keyboard.Type("MixedDirectoryRenamed");
                    Keyboard.PressAndRelease(Key.Enter);

                    mixedDirectoryNode.ExpandItem(EXPANDFLAGS.EXPF_ExpandFolderRecursively);
                    var renamedMixedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryBrowserDirectoryLabel,
                        browserCodeLabel
                        );

                    Assert.IsNotNull(
                        renamedMixedDirectory,
                        "Renaming mixed directory failed: could not find " + browserCodeLabel);

                    newBrowserItemNode.ItemNode.ItemTypeName = "Compile";

                    var nodeBrowserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed),
                        NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node)
                        );
                    Assert.IsNotNull(
                        nodeBrowserSubDirectory,
                        "Changing the item type should change the directory label. Could not find " +
                        NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node)
                        );

                    var nodeDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath(
                        Path.Combine(app.GetProject("ClientServerCode").GetNodejsProject().ProjectHome,
                                     @"NodeDirectory\"));
                    (nodeDirectoryNode as NodejsFolderNode).SetItemTypeRecursively(VSLangProj.prjBuildAction.prjBuildActionContent);

                    Assert.AreEqual(
                        "Content",
                        nodejsProject.GetItemType(@"NodeDirectory\NodeSubDirectory\nodeCode.js"),
                        "nodeCode.js file should be marked as content after recursively setting directory contents as Content."
                        );
                    Assert.AreEqual(
                        "TypeScriptCompile",
                        nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"),
                        "Only javascript file item types should change when marking item types recursively."
                        );

                    var fromPoint = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryNodeDirectoryLabel
                        ).GetClickablePoint();

                    var toPoint = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryBrowserDirectoryLabel
                        ).GetClickablePoint();

                    Mouse.MoveTo(fromPoint);
                    Mouse.Down(MouseButton.Left);

                    Mouse.MoveTo(toPoint);
                    Mouse.Up(MouseButton.Left);

                    var draggedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed),
                        NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node)
                        );
                    Assert.IsNotNull(
                        draggedDirectory,
                        "Labels not properly updated after dragging and dropping directory."
                        );
                }
            }
        }
예제 #23
0
        private static EditorWindow OpenItem(VisualStudioApp app, string startItem, Project project, out Window window)
        {
            EnvDTE.ProjectItem item = null;
            if (startItem.IndexOf('\\') != -1) {
                var items = project.ProjectItems;
                foreach (var itemName in startItem.Split('\\')) {
                    Console.WriteLine(itemName);
                    item = items.Item(itemName);
                    items = item.ProjectItems;
                }
            } else {
                item = project.ProjectItems.Item(startItem);
            }

            Assert.IsNotNull(item);

            window = item.Open();
            window.Activate();
            return app.GetDocument(item.Document.FullName);
        }
예제 #24
0
        private void OutlineTest(string filename, params ExpectedTag[] expected) {
            using (var app = new VisualStudioApp()) {
                var prevOption = NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen;
                try {
                    NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen = true;
                    
                    var project = app.OpenProject(@"TestData\Outlining\Outlining.sln");

                    var item = project.ProjectItems.Item(filename);
                    var window = item.Open();
                    window.Activate();

                    System.Threading.Thread.Sleep(2000);

                    var doc = app.GetDocument(item.Document.FullName);
                    var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                    var tags = doc.GetTaggerAggregator<IOutliningRegionTag>(doc.TextView.TextBuffer).GetTags(new SnapshotSpan(snapshot, 0, snapshot.Length));

                    VerifyTags(doc.TextView.TextBuffer, tags, expected);
                }
                finally {
                    NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen = prevOption;
                }
            }
        }
예제 #25
0
        public void Parameters() {
            var getreclimit = new[] { "from sys import getrecursionlimit" };

            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\AddImport.sln");
                var item = project.ProjectItems.Item("Parameters.py");
                var window = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);

                AddSmartTagTest(doc, 1, 19, _NoSmartTags);
                AddSmartTagTest(doc, 1, 30, getreclimit);

                AddSmartTagTest(doc, 4, 18, _NoSmartTags);
                AddSmartTagTest(doc, 7, 18, _NoSmartTags);
                AddSmartTagTest(doc, 10, 20, _NoSmartTags);
                AddSmartTagTest(doc, 13, 22, _NoSmartTags);
                AddSmartTagTest(doc, 16, 22, _NoSmartTags);
                AddSmartTagTest(doc, 19, 22, _NoSmartTags);

                AddSmartTagTest(doc, 19, 35, getreclimit);

                AddSmartTagTest(doc, 22, 25, _NoSmartTags);
                AddSmartTagTest(doc, 22, 56, getreclimit);

                AddSmartTagTest(doc, 25, 38, _NoSmartTags);
                AddSmartTagTest(doc, 25, 38, _NoSmartTags);
                AddSmartTagTest(doc, 25, 48, getreclimit);

                AddSmartTagTest(doc, 29, 12, _NoSmartTags);
                AddSmartTagTest(doc, 29, 42, getreclimit);

                AddSmartTagTest(doc, 34, 26, _NoSmartTags);
                AddSmartTagTest(doc, 34, 31, getreclimit);

                AddSmartTagTest(doc, 42, 16, _NoSmartTags);
                AddSmartTagTest(doc, 51, 16, _NoSmartTags);
            }
        }
예제 #26
0
        private static EditorWindow OpenDjangoProjectItem(VisualStudioApp app, string startItem, out Window window, string projectName = @"TestData\DjangoEditProject.sln", bool wait = false) {
            var project = app.OpenProject(projectName, startItem);
            var pyProj = project.GetPythonProject();

            EnvDTE.ProjectItem item = null;
            if (startItem.IndexOf('\\') != -1) {
                var items = project.ProjectItems;
                foreach (var itemName in startItem.Split('\\')) {
                    Console.WriteLine(itemName);
                    item = items.Item(itemName);
                    items = item.ProjectItems;
                }
            } else {
                item = project.ProjectItems.Item(startItem);
            }

            Assert.IsNotNull(item);

            window = item.Open();
            window.Activate();
            var doc = app.GetDocument(item.Document.FullName);

            if (wait) {
                pyProj.GetAnalyzer().WaitForCompleteAnalysis(_ => true);
            }

            return doc;
        }
예제 #27
0
        /// <summary>
        /// Runs a single formatting test
        /// </summary>
        /// <param name="filename">The filename of the document to perform formatting in (lives in FormattingTests.sln)</param>
        /// <param name="selection">The selection to format, or null if formatting the entire document</param>
        /// <param name="expectedText">The expected source code after the formatting</param>
        /// <param name="changedSpans">The spans which should be marked as changed in the buffer after formatting</param>
        private static void FormattingTest(string filename, Span? selection, string expectedText, Span[] changedSpans) {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\FormattingTests\FormattingTests.sln");
                var item = project.ProjectItems.Item(filename);
                var window = item.Open();
                window.Activate();
                var doc = app.GetDocument(item.Document.FullName);

                var aggFact = app.ComponentModel.GetService<IViewTagAggregatorFactoryService>();
                var changeTags = aggFact.CreateTagAggregator<ChangeTag>(doc.TextView);

                // format the selection or document
                if (selection == null) {
                    DoFormatDocument();
                } else {
                    doc.Invoke(() => doc.TextView.Selection.Select(new SnapshotSpan(doc.TextView.TextBuffer.CurrentSnapshot, selection.Value), false));
                    DoFormatSelection();
                }

                // verify the contents are correct
                string actual = null;
                for (int i = 0; i < 100; i++) {
                    actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                    if (expectedText == actual) {
                        break;
                    }
                    System.Threading.Thread.Sleep(100);
                }
                Assert.AreEqual(expectedText, actual);

                // verify the change tags are correct
                var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                var tags = changeTags.GetTags(
                    new SnapshotSpan(
                        doc.TextView.TextBuffer.CurrentSnapshot,
                        new Span(0, doc.TextView.TextBuffer.CurrentSnapshot.Length)
                    )
                );
                List<Span> result = new List<Span>();
                foreach (var tag in tags) {
                    result.Add(
                        new Span(
                            tag.Span.Start.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position,
                            tag.Span.End.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position
                        )
                    );
                }

                // dump the spans for creating tests easier
                foreach (var span in result) {
                    Console.WriteLine(span);
                }

                Assert.AreEqual(result.Count, changedSpans.Length);
                for (int i = 0; i < result.Count; i++) {
                    Assert.AreEqual(result[i], changedSpans[i]);
                }
            }
        }