private void SetOrLoadContent(string content) { if (ModuleState < ModuleState.Loading) { try { content = content ?? LoadContent(); _buffer.SetContent(content); ModuleState = ModuleState.Loaded; } catch (IOException) { } catch (UnauthorizedAccessException) { } } }
public void NewLines(string s, NewLineLocation[] expected) { var doc = new DocumentBuffer(); doc.SetContent(s); var nls = doc.GetNewLineLocations().ToArray(); for (var i = 0; i < nls.Length; i++) { Assert.AreEqual(nls[i].Kind, expected[i].Kind); Assert.AreEqual(nls[i].EndIndex, expected[i].EndIndex); } }
public void ResetDocumentBuffer() { var doc = new DocumentBuffer(); doc.SetContent(string.Empty); Assert.AreEqual(string.Empty, doc.Text); doc.Update(new[] { DocumentChange.Insert("text", SourceLocation.MinValue) }); Assert.AreEqual("text", doc.Text); Assert.AreEqual(1, doc.Version); }
public void InsertTopToBottom() { var doc = new DocumentBuffer(); doc.SetContent(@"linelinelineline"); doc.Update(new[] { DocumentChange.Insert("\n", new SourceLocation(1, 1)), DocumentChange.Insert("1\n", new SourceLocation(2, 5)), DocumentChange.Insert("2\r", new SourceLocation(3, 5)), DocumentChange.Insert("3\r\n", new SourceLocation(4, 5)), DocumentChange.Insert("4\r\n", new SourceLocation(5, 5)), }); Assert.AreEqual("\nline1\nline2\rline3\r\nline4\r\n", doc.Text); }
public void BasicDocumentBuffer() { var doc = new DocumentBuffer(); doc.SetContent(@"def f(x): return def g(y): return y * 2 "); doc.Update(new List <DocumentChange> { // We *should* batch adjacent insertions, but we should also // work fine even if we don't. Note that the insertion point // tracks backwards with previous insertions in the same version. // If each of these were in its own array, the location would // have to change for each. DocumentChange.Insert(")", new SourceLocation(2, 11)), DocumentChange.Insert("x", new SourceLocation(2, 11)), DocumentChange.Insert("(", new SourceLocation(2, 11)), DocumentChange.Insert("g", new SourceLocation(2, 11)), DocumentChange.Insert(" ", new SourceLocation(2, 11)) }); doc.Text.Should().Contain("return g(x)"); Assert.AreEqual(1, doc.Version); doc.Update(new[] { DocumentChange.Delete(new SourceLocation(2, 14), new SourceLocation(2, 15)), DocumentChange.Insert("x * 2", new SourceLocation(2, 14)) }); doc.Text.Should().Contain("return g(x * 2)"); doc.Update(new[] { DocumentChange.Replace(new SourceLocation(2, 18), new SourceLocation(2, 19), "300") }); doc.Text.Should().Contain("return g(x * 300)"); doc.Update(new[] { // Changes are out of order, but we should fix that automatically DocumentChange.Delete(new SourceLocation(2, 13), new SourceLocation(2, 22)), DocumentChange.Insert("#", new SourceLocation(2, 7)) }); doc.Text.Should().Contain("re#turn g"); }
private void SetOrLoadContent(string content) { if (ContentState < State.Loading) { try { if (IsPersistent) { content = string.Empty; } else { content = content ?? LoadContent(); } _buffer.SetContent(content); ContentState = State.Loaded; } catch (IOException) { } catch (UnauthorizedAccessException) { } } }
public void SequentialChanges() { var doc = new DocumentBuffer(); doc.SetContent(@" line1 line2 line3 line4 "); doc.Update(new[] { DocumentChange.Delete(new SourceSpan(2, 5, 3, 5)), DocumentChange.Delete(new SourceSpan(3, 5, 4, 5)) }); Assert.AreEqual(@" line2 line4 ", doc.Text); }
public void InsertMultipleDisjoint() { var doc = new DocumentBuffer(); doc.SetContent(@" line line line line "); doc.Update(new[] { DocumentChange.Insert("4", new SourceLocation(5, 5)), DocumentChange.Insert("3", new SourceLocation(4, 5)), DocumentChange.Insert("2", new SourceLocation(3, 5)), DocumentChange.Insert("1", new SourceLocation(2, 5)), }); Assert.AreEqual(@" line1 line2 line3 line4 ", doc.Text); }
public void DeleteMultipleDisjoint() { var doc = new DocumentBuffer(); doc.SetContent(@" line1 line2 line3 line4 "); doc.Update(new[] { DocumentChange.Delete(new SourceSpan(5, 5, 5, 6)), DocumentChange.Delete(new SourceSpan(4, 5, 4, 6)), DocumentChange.Delete(new SourceSpan(3, 5, 3, 6)), DocumentChange.Delete(new SourceSpan(2, 5, 2, 6)) }); Assert.AreEqual(@" line line line line ", doc.Text); }
public void ReplaceAllDocumentBuffer() { var doc = new DocumentBuffer(); doc.SetContent(string.Empty); Assert.AreEqual(string.Empty, doc.Text); doc.Update(new[] { DocumentChange.ReplaceAll("text") }); Assert.AreEqual("text", doc.Text); Assert.AreEqual(1, doc.Version); doc.Update(new[] { DocumentChange.ReplaceAll("abcdef") }); Assert.AreEqual(@"abcdef", doc.Text); Assert.AreEqual(2, doc.Version); doc.Update(new[] { DocumentChange.Insert("text", SourceLocation.MinValue), DocumentChange.ReplaceAll("1234") }); Assert.AreEqual(@"1234", doc.Text); Assert.AreEqual(3, doc.Version); doc.Update(new[] { DocumentChange.ReplaceAll("1234"), DocumentChange.Insert("text", SourceLocation.MinValue) }); Assert.AreEqual(@"text1234", doc.Text); Assert.AreEqual(4, doc.Version); }