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 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 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)); } }
void InsertString(pbx p, int pos, byte [] s) { p.InsertString(pos, s, s.Length); }