public void IncreementEditsCount() { var doc = new TextDocument("hello world"); doc.MakeReplaceCommand(0, 1, "H").Do(); doc.MakeReplaceCommand(0, 1, "H").Do(); Assert.AreEqual(2, doc.EditsCount); }
public void Test() { var doc = new TextDocument("hello world"); var cmd = doc.MakeReplaceCommand(0, 1, "H"); cmd.Do(); Assert.AreEqual("Hello world", doc.Text); var cmd2 = doc.MakeReplaceCommand(6, 5, "all!"); cmd2.Do(); Assert.AreEqual("Hello all!", doc.Text); Assert.AreEqual(2, doc.EditsCount); cmd2.Undo(); Assert.AreEqual(1, doc.EditsCount); cmd.Undo(); Assert.AreEqual(0, doc.EditsCount); Assert.AreEqual("hello world", doc.Text); try { cmd2.Undo(); Assert.Fail("Should not be able to undo command which was not executed before"); } catch (InvalidOperationException) { Console.WriteLine("Exception was thrown!"); } }
public ReplaceCommand(TextDocument textDocument, int startIndex, int len, string newText) { this.textDocument = textDocument; this.startIndex = startIndex; this.len = len; this.newText = newText; this.oldText = textDocument.Text.Substring(startIndex, len); }
public void RestoreDocumentToPreviousState(string input) { var doc = new TextDocument(input); var cmd = doc.MakeReplaceCommand(0, 1, "H"); cmd.Do(); cmd.Undo(); Assert.AreEqual(0, doc.EditsCount); Assert.AreEqual(input, doc.Text); }
public void WhenCommandIsNotDone_Fail() { var doc = new TextDocument("hello world!"); var cmd = doc.MakeReplaceCommand(0, 1, "H"); Assert.Throws<InvalidOperationException>(() => cmd.Undo()); }
public string Change(string input, int index, int count, string replacement) { var doc = new TextDocument(input); doc.MakeReplaceCommand(index, count, replacement).Do(); return doc.Text; }
public void SetUp() { doc = new TextDocument(DefaultText); }