public static EditorTree ApplyTextChange(string expression, int start, int oldLength, int newLength, string newText) { TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType); EditorTree tree = new EditorTree(textBuffer); tree.Build(); TextChange tc = new TextChange(); tc.OldRange = new TextRange(start, oldLength); tc.NewRange = new TextRange(start, newLength); tc.OldTextProvider = new TextProvider(textBuffer.CurrentSnapshot); if (oldLength == 0 && newText.Length > 0) { textBuffer.Insert(start, newText); } else if (oldLength > 0 && newText.Length > 0) { textBuffer.Replace(new Span(start, oldLength), newText); } else { textBuffer.Delete(new Span(start, oldLength)); } return(tree); }
public static EditorTree ApplyTextChange(IServiceContainer services, string expression, int start, int oldLength, int newLength, string newText) { var textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType).ToEditorBuffer(); var tree = new EditorTree(textBuffer, services); tree.Build(); if (oldLength == 0 && newText.Length > 0) { textBuffer.Insert(start, newText); } else if (oldLength > 0 && newText.Length > 0) { textBuffer.Replace(new TextRange(start, oldLength), newText); } else { textBuffer.Delete(new TextRange(start, oldLength)); } return(tree); }
public void ClassifyRContent() { string expected1 = @"[0:9] keyword [9:1] RD Braces [16:2] number [19:1] number [32:5] string"; string expected2 = @"[0:9] keyword [9:1] RD Braces [16:2] number [19:1] number [32:6] string"; string s1 = "\\examples{ x <- -9:9 plot(col = \""; string s2 = "red\")"; string original = s1 + s2; TextBufferMock textBuffer = new TextBufferMock(original, RdContentTypeDefinition.ContentType); ClassificationTypeRegistryServiceMock ctrs = new ClassificationTypeRegistryServiceMock(); RdClassifier cls = new RdClassifier(textBuffer, ctrs); IList <ClassificationSpan> spans = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length))); string actual = ClassificationWriter.WriteClassifications(spans); BaselineCompare.CompareStringLines(expected1, actual); textBuffer.Insert(s1.Length, "%"); spans = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length))); actual = ClassificationWriter.WriteClassifications(spans); BaselineCompare.CompareStringLines(expected2, actual); textBuffer.Delete(new Span(s1.Length, 1)); spans = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length))); actual = ClassificationWriter.WriteClassifications(spans); BaselineCompare.CompareStringLines(expected1, actual); }