Esempio n. 1
0
 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);
 }
Esempio n. 2
0
		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!");
			}
		}
Esempio n. 3
0
			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);
			}
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 public void WhenCommandIsNotDone_Fail()
 {
     var doc = new TextDocument("hello world!");
     var cmd = doc.MakeReplaceCommand(0, 1, "H");
     Assert.Throws<InvalidOperationException>(() => cmd.Undo());
 }
Esempio n. 6
0
 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);
 }