internal static void TestIndentation(int point, int?expectedIndentation, ITextView textView, TestHostDocument subjectDocument) { var textUndoHistory = new Mock <ITextUndoHistoryRegistry>(); var editorOperationsFactory = new Mock <IEditorOperationsFactoryService>(); var editorOperations = new Mock <IEditorOperations>(); editorOperationsFactory.Setup(x => x.GetEditorOperations(textView)).Returns(editorOperations.Object); var snapshot = subjectDocument.TextBuffer.CurrentSnapshot; var indentationLineFromBuffer = snapshot.GetLineFromPosition(point); var commandHandler = new SmartTokenFormatterCommandHandler(textUndoHistory.Object, editorOperationsFactory.Object); commandHandler.ExecuteCommand(new ReturnKeyCommandArgs(textView, subjectDocument.TextBuffer), () => { }); var newSnapshot = subjectDocument.TextBuffer.CurrentSnapshot; int?actualIndentation; if (newSnapshot.Version.VersionNumber > snapshot.Version.VersionNumber) { actualIndentation = newSnapshot.GetLineFromLineNumber(indentationLineFromBuffer.LineNumber).GetFirstNonWhitespaceOffset(); } else { var provider = new SmartIndent(textView); actualIndentation = provider.GetDesiredIndentation(indentationLineFromBuffer); } Assert.Equal(expectedIndentation, actualIndentation.Value); }
private static void T(string codeWithCaret) { int caret = codeWithCaret.IndexOf('|'); int expectedIndent = 0; while (caret - expectedIndent > 1 && codeWithCaret[caret - expectedIndent - 1] == ' ') { expectedIndent++; } var code = codeWithCaret.Remove(caret, 1); var syntaxTree = SyntaxFactory.ParseSyntaxTree(SourceText.From(code)); var actualIndent = SmartIndent.FindTotalParentChainIndent(syntaxTree.Root, caret, 0); Assert.Equal(expectedIndent, actualIndent); }
private void T(string xmlWithCaret) { int caret = xmlWithCaret.IndexOf('|'); int expectedIndent = 0; while (caret - expectedIndent > 1 && xmlWithCaret[caret - expectedIndent - 1] == ' ') { expectedIndent++; } var xml = xmlWithCaret.Remove(caret, 1); var root = Parser.ParseText(xml); var actualIndent = SmartIndent.FindTotalParentChainIndent(root, caret, 0, 0); Assert.AreEqual(expectedIndent, actualIndent); }
protected void TestIndentation( int point, int?expectedIndentation, ITextView textView, TestHostDocument subjectDocument) { var textUndoHistory = new Mock <ITextUndoHistoryRegistry>(); var editorOperationsFactory = new Mock <IEditorOperationsFactoryService>(); var editorOperations = new Mock <IEditorOperations>(); editorOperationsFactory.Setup(x => x.GetEditorOperations(textView)).Returns(editorOperations.Object); var snapshot = subjectDocument.GetTextBuffer().CurrentSnapshot; var indentationLineFromBuffer = snapshot.GetLineFromPosition(point); var provider = new SmartIndent(textView); var actualIndentation = provider.GetDesiredIndentation(indentationLineFromBuffer); Assert.Equal(expectedIndentation, actualIndentation.Value); }
protected void TestIndentation( TestWorkspace workspace, int indentationLine, int?expectedIndentation, int?expectedBlankLineIndentation) { var snapshot = workspace.Documents.First().TextBuffer.CurrentSnapshot; var bufferGraph = new Mock <IBufferGraph>(MockBehavior.Strict); bufferGraph.Setup(x => x.MapUpToSnapshot(It.IsAny <SnapshotPoint>(), It.IsAny <PointTrackingMode>(), It.IsAny <PositionAffinity>(), It.IsAny <ITextSnapshot>())) .Returns <SnapshotPoint, PointTrackingMode, PositionAffinity, ITextSnapshot>((p, m, a, s) => { if (workspace.Services.GetService <IHostDependentFormattingRuleFactoryService>() is TestFormattingRuleFactoryServiceFactory.Factory factory && factory.BaseIndentation != 0 && factory.TextSpan.Contains(p.Position)) { var line = p.GetContainingLine(); var projectedOffset = line.GetFirstNonWhitespaceOffset().Value - factory.BaseIndentation; return(new SnapshotPoint(p.Snapshot, p.Position - projectedOffset)); } return(p); }); var projectionBuffer = new Mock <ITextBuffer>(MockBehavior.Strict); projectionBuffer.Setup(x => x.ContentType.DisplayName).Returns("None"); var textView = new Mock <ITextView>(MockBehavior.Strict); textView.Setup(x => x.Options).Returns(TestEditorOptions.Instance); textView.Setup(x => x.BufferGraph).Returns(bufferGraph.Object); textView.SetupGet(x => x.TextSnapshot.TextBuffer).Returns(projectionBuffer.Object); var provider = new SmartIndent(textView.Object); var indentationLineFromBuffer = snapshot.GetLineFromLineNumber(indentationLine); var actualIndentation = provider.GetDesiredIndentation(indentationLineFromBuffer); Assert.Equal(expectedIndentation, actualIndentation); TestBlankLineIndentationService( workspace, textView.Object, indentationLine, expectedBlankLineIndentation ?? expectedIndentation.Value); }
private void ResetSmartIndentType() { _smartIndentType = SmartIndent.None; }