public void Sections() { string content = @"# NAME1 ----- x <- 1 # NAME2 ----- "; TextBufferMock textBuffer = null; int calls = 0; OutlineRegionsChangedEventArgs args = null; textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); using (var tree = new EditorTree(textBuffer, _shell)) { tree.Build(); using (var editorDocument = new EditorDocumentMock(tree)) { using (var ob = new ROutlineRegionBuilder(editorDocument, _shell)) { var rc1 = new OutlineRegionCollection(0); ob.BuildRegions(rc1); rc1.Should().HaveCount(2); rc1[0].DisplayText.Should().Be("# NAME1"); rc1[1].DisplayText.Should().Be("# NAME2"); rc1[0].Length.Should().Be(21); rc1[1].Length.Should().Be(13); ob.RegionsChanged += (s, e) => { calls++; args = e; }; textBuffer.Insert(2, "A"); editorDocument.EditorTree.EnsureTreeReady(); // Wait for background/idle tasks to complete var start = DateTime.Now; while (calls == 0 && (DateTime.Now - start).TotalMilliseconds < 2000) { ((IIdleTimeSource)_shell).DoIdle(); } calls.Should().Be(1); args.Should().NotBeNull(); args.ChangedRange.Start.Should().Be(0); args.ChangedRange.End.Should().Be(textBuffer.CurrentSnapshot.Length); args.Regions.Should().HaveCount(2); args.Regions[0].DisplayText.Should().Be("# ANAME1"); args.Regions[1].DisplayText.Should().Be("# NAME2"); args.Regions[0].Length.Should().Be(22); args.Regions[1].Length.Should().Be(13); } } } }
public static OutlineRegionCollection BuildOutlineRegions(string content) { TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); using (EditorTree tree = new EditorTree(textBuffer)) { tree.Build(); EditorDocumentMock editorDocument = new EditorDocumentMock(tree); ROutlineRegionBuilder ob = new ROutlineRegionBuilder(editorDocument); OutlineRegionCollection rc = new OutlineRegionCollection(0); ob.BuildRegions(rc); return(rc); } }
public static OutlineRegionCollection BuildOutlineRegions(IEditorShell editorShell, string content) { TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); using (var tree = new EditorTree(textBuffer, editorShell)) { tree.Build(); using (var editorDocument = new EditorDocumentMock(tree)) { using (var ob = new ROutlineRegionBuilder(editorDocument, editorShell)) { OutlineRegionCollection rc = new OutlineRegionCollection(0); ob.BuildRegions(rc); return(rc); } } } }
public static OutlineRegionCollection BuildOutlineRegions(IServiceContainer services, string content) { var textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); var eb = textBuffer.ToEditorBuffer(); using (var tree = new EditorTree(eb, services)) { tree.Build(); using (var editorDocument = new EditorDocumentMock(tree)) { using (var ob = new ROutlineRegionBuilder(editorDocument, services)) { var rc = new OutlineRegionCollection(0); ob.BuildRegions(rc); return(rc); } } } }
public void RRegionBuilder_ConstructionTest() { TextBufferMock textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); EditorTree tree = new EditorTree(textBuffer); EditorDocumentMock editorDocument = new EditorDocumentMock(tree); ROutlineRegionBuilder ob = new ROutlineRegionBuilder(editorDocument); ob.EditorDocument.Should().NotBeNull(); ob.EditorTree.Should().NotBeNull(); editorDocument.DocumentClosing.GetInvocationList().Should().ContainSingle(); FieldInfo treeUpdateField = tree.GetType().GetField("UpdateCompleted", BindingFlags.Instance | BindingFlags.NonPublic); var d = (MulticastDelegate)treeUpdateField.GetValue(tree); d.GetInvocationList().Should().ContainSingle(); ob.Dispose(); editorDocument.DocumentClosing.Should().BeNull(); treeUpdateField.GetValue(tree).Should().BeNull(); }
public void ConstructionTest() { var textBuffer = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType); var eb = textBuffer.ToEditorBuffer(); var tree = new EditorTree(eb, _services); using (var editorDocument = new EditorDocumentMock(tree)) { using (var ob = new ROutlineRegionBuilder(editorDocument, _services)) { ob.EditorDocument.Should().NotBeNull(); ob.EditorTree.Should().NotBeNull(); editorDocument.Closing.GetInvocationList().Should().ContainSingle(); var treeUpdateField = tree.GetType().GetField("UpdateCompleted", BindingFlags.Instance | BindingFlags.NonPublic); var d = (MulticastDelegate)treeUpdateField.GetValue(tree); d.GetInvocationList().Should().ContainSingle(); tree.Dispose(); editorDocument.Closing.Should().BeNull(); treeUpdateField.GetValue(tree).Should().BeNull(); } } }