public void testUndo() { pbx ub = new pbx(); ub.AttachStyles(pbx.CreateStyles(1), null, 0); int lenUtest = utest.Length(); int lenXYtest = xytest.Length(); ub.InsertString(0, xytest.Data(), lenXYtest); Assert.AreEqual(ToString(ub), "xy"); ub.InsertString(0, utest.Data(), lenUtest); Assert.AreEqual(ToString(ub), "uxy"); ub.DeleteRange(1, 1); Assert.AreEqual(ToString(ub), "uy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "uxy"); ub.PerformRedoAction(); Assert.AreEqual(ToString(ub), "uy"); // Undo to beginning and redo again ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "uxy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "xy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), ""); ub.PerformRedoAction(); Assert.AreEqual(ToString(ub), "xy"); ub.PerformRedoAction(); Assert.AreEqual(ToString(ub), "uxy"); ub.PerformRedoAction(); Assert.AreEqual(ToString(ub), "uy"); // Do it again. Undo to beginning and redo again ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "uxy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "xy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), ""); ub.PerformRedoAction(); Assert.AreEqual(ToString(ub), "xy"); ub.PerformRedoAction(); Assert.AreEqual(ToString(ub), "uxy"); ub.PerformRedoAction(); Assert.AreEqual(ToString(ub), "uy"); // Add a new step in ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "uxy"); ub.DeleteRange(0, 1); Assert.AreEqual(ToString(ub), "xy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "uxy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), "xy"); ub.PerformUndoAction(); Assert.AreEqual(ToString(ub), ""); }
public void TestBadPositionException() { pbx pbuffer = new pbx(); pbuffer.AttachStyles(pbx.CreateStyles(1), null, 0); try { pbuffer.InsertString(1, test.Data(), 1); Assert.Fail("Should raise an BadPositionException"); } catch (BadPositionException) { } }
public void TestBiggerSize() { pbx pbuffer = new pbx(); pbuffer.AttachStyles(pbx.CreateStyles(1), null, 0); int lenTest = test.Length(); pbuffer.InsertString(0, test.Data(), lenTest); Assert.AreEqual(pbuffer.Length(), lenTest); for (int n = 0; n < lenTest; n++) { Assert.AreEqual(test.CharAt(n), pbuffer.CharAt(n)); } }
public void testUndoBatching() { pbx ub = new pbx(); ub.AttachStyles(pbx.CreateStyles(1), null, 0); int lenUtest = utest.Length(); // Checking for batching // Typing one character then another after should be one step ub.InsertString(0, utest.Data(), lenUtest); Assert.AreEqual(ub.StartUndo(), 1); Assert.AreEqual(ToString(ub), "u"); ub.InsertString(1, utest.Data(), lenUtest); Assert.AreEqual(ub.StartUndo(), 2); Assert.AreEqual(ToString(ub), "uu"); ub.PerformUndoStep(); Assert.AreEqual(ToString(ub), ""); ub.PerformRedoStep(); Assert.AreEqual(ToString(ub), "uu"); // This one should not merge as it is after a redo ub.InsertString(2, utest.Data(), lenUtest); Assert.AreEqual(ub.StartUndo(), 1); Assert.AreEqual(ToString(ub), "uuu"); // This one should not merge as it is a delete and previous was insert ub.DeleteRange(0, 1); Assert.AreEqual(ub.StartUndo(), 1); Assert.AreEqual(ToString(ub), "uu"); // This one should merge as it is a delete and next to previous ub.DeleteRange(0, 1); Assert.AreEqual(ub.StartUndo(), 2); Assert.AreEqual(ToString(ub), "u"); ub.PerformUndoStep(); Assert.AreEqual(ToString(ub), "uuu"); // This one should not merge as it is after an undo ub.DeleteRange(2, 1); Assert.AreEqual(ub.StartUndo(), 1); Assert.AreEqual(ToString(ub), "uu"); // This one should merge as it is a delete and next to previous ub.DeleteRange(1, 1); Assert.AreEqual(ub.StartUndo(), 2); Assert.AreEqual(ToString(ub), "u"); }
public void testLineInsertionDeletion() { // The complexity in the line vector is caused by treating any // of \r, \n, and \r\n as line ends so test a variety of these. pbx pbuffer = new pbx(); pbuffer.AttachStyles(pbx.CreateStyles(1), null, 0); //Assert.AreEqual(pbuffer.Lines(), 1); //Assert.AreEqual(pbuffer.PositionFromLine(0), 0); //Assert.AreEqual(pbuffer.LineEndPositionFromLine(0), 0); InsertString(pbuffer, 0, shortInsert.Data()); // bc //Assert.AreEqual(pbuffer.Lines(), 1); //Assert.AreEqual(pbuffer.PositionFromLine(0), 0); //Assert.AreEqual(pbuffer.LineEndPositionFromLine(0), 2); InsertString(pbuffer, 0, CR.Data()); // \rbc Assert.AreEqual(pbuffer.Lines(), 2); Assert.AreEqual(pbuffer.PositionFromLine(0), 0); Assert.AreEqual(pbuffer.PositionFromLine(1), 1); Assert.AreEqual(pbuffer.PositionFromLine(2), 3); InsertString(pbuffer, 0, LF.Data()); // \n\rbc Assert.AreEqual(pbuffer.Lines(), 3); Assert.AreEqual(pbuffer.PositionFromLine(0), 0); Assert.AreEqual(pbuffer.PositionFromLine(1), 1); Assert.AreEqual(pbuffer.PositionFromLine(2), 2); Assert.AreEqual(pbuffer.PositionFromLine(3), 4); // This \r is merged into the previous line end InsertString(pbuffer, 0, CR.Data()); // \r\n\rbc Assert.AreEqual(pbuffer.Lines(), 3); Assert.AreEqual(pbuffer.PositionFromLine(0), 0); Assert.AreEqual(pbuffer.PositionFromLine(1), 2); Assert.AreEqual(pbuffer.PositionFromLine(2), 3); Assert.AreEqual(pbuffer.PositionFromLine(3), 5); // As is this \n InsertString(pbuffer, 3, LF.Data()); // \r\n\r\nbc Assert.AreEqual(pbuffer.Lines(), 3); Assert.AreEqual(pbuffer.PositionFromLine(0), 0); Assert.AreEqual(pbuffer.PositionFromLine(1), 2); Assert.AreEqual(pbuffer.PositionFromLine(2), 4); Assert.AreEqual(pbuffer.PositionFromLine(3), 6); // Separate a \r\n pair InsertString(pbuffer, 3, X.Data()); // \r\n\rx\nbc Assert.AreEqual(pbuffer.Lines(), 4); // Check all the line starts are correct Assert.AreEqual(pbuffer.PositionFromLine(0), 0); Assert.AreEqual(pbuffer.PositionFromLine(1), 2); Assert.AreEqual(pbuffer.PositionFromLine(2), 3); Assert.AreEqual(pbuffer.PositionFromLine(3), 5); Assert.AreEqual(pbuffer.PositionFromLine(4), 7); // Destroy and recreate the lines data to ensure it is recreated correctly pbuffer.DiscardLines(); Assert.AreEqual(pbuffer.Lines(), 4); // Check all the line starts are correct Assert.AreEqual(pbuffer.PositionFromLine(0), 0); Assert.AreEqual(pbuffer.PositionFromLine(1), 2); Assert.AreEqual(pbuffer.PositionFromLine(2), 3); Assert.AreEqual(pbuffer.PositionFromLine(3), 5); Assert.AreEqual(pbuffer.PositionFromLine(4), 7); // Put them back together pbuffer.DeleteRange(3, 1); // \r\n\r\nbc Assert.AreEqual(pbuffer.Lines(), 3); pbuffer.DeleteRange(0, 1); // \n\r\nbc Assert.AreEqual(pbuffer.Lines(), 3); pbuffer.DeleteRange(0, 1); // \r\nbc Assert.AreEqual(pbuffer.Lines(), 2); pbuffer.DeleteRange(0, 2); // bc Assert.AreEqual(pbuffer.Lines(), 1); }