Ejemplo n.º 1
0
        private void TestMultilineCommenting(string startingText, string expectedEndingText, bool containsMultilineComment = true)
        {
            const string insertionPointString = "<enter>";

            // Find insertion point and fake enter key by putting \r\n before the insertion point.
            startingText = startingText.Replace(insertionPointString, string.Format("\r\n{0}", insertionPointString));

            // Take input text and find index of the enter.
            int insertionPosition = startingText.IndexOf(insertionPointString);

            startingText = startingText.Remove(insertionPosition, insertionPointString.Length);

            // create the view and request a multiline comment format
            var view = new MockTextView(
                new MockTextBuffer(startingText, "C:\\app.js", NodejsConstants.Nodejs));
            var insertionPoint = new SnapshotPoint(view.TextSnapshot, insertionPosition);

            // Setup mock registry service and classification provider for the IsMultilineComment method.
            var classifierProvider = new NodejsClassifierProvider(new MockContentTypeRegistryService());

            classifierProvider._classificationRegistry = new MockClassificationTypeRegistryService();
            var classifier = classifierProvider.GetClassifier(view.TextBuffer);

            SnapshotSpan commentSpan;

            if (insertionPoint.IsMultilineComment(out commentSpan))
            {
                view.FormatMultilineComment(commentSpan.Start, insertionPoint);
            }
            else if (containsMultilineComment)
            {
                Assert.Fail("This was not seen as a comment.  Something went wrong");
            }

            Assert.AreEqual(expectedEndingText, view.TextBuffer.CurrentSnapshot.GetText());
        }
        private void TestMultilineCommenting(string startingText, string expectedEndingText, bool containsMultilineComment = true) {
            const string insertionPointString = "<enter>";

            // Find insertion point and fake enter key by putting \r\n before the insertion point.
            startingText = startingText.Replace(insertionPointString, string.Format("\r\n{0}", insertionPointString));

            // Take input text and find index of the enter.
            int insertionPosition = startingText.IndexOf(insertionPointString);
            startingText = startingText.Remove(insertionPosition, insertionPointString.Length);

            // create the view and request a multiline comment format
            var view = new MockTextView(
                new MockTextBuffer(content: startingText, contentType: NodejsConstants.Nodejs, filename: "C:\\app.js"));
            var insertionPoint = new SnapshotPoint(view.TextSnapshot, insertionPosition);

            // Setup mock registry service and classification provider for the IsMultilineComment method.
            var classifierProvider = new NodejsClassifierProvider(new MockContentTypeRegistryService(NodejsConstants.Nodejs));
            classifierProvider._classificationRegistry = new MockClassificationTypeRegistryService();
            var classifier = classifierProvider.GetClassifier(view.TextBuffer);

            SnapshotSpan commentSpan;
            if (insertionPoint.IsMultilineComment(out commentSpan)) {
                view.FormatMultilineComment(commentSpan.Start, insertionPoint);
            } else if (containsMultilineComment) {
                Assert.Fail("This was not seen as a comment.  Something went wrong");
            }

            Assert.AreEqual(expectedEndingText, view.TextBuffer.CurrentSnapshot.GetText());
        }