diff options
author | Neil <nyamatongwe@gmail.com> | 2024-02-09 21:45:35 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2024-02-09 21:45:35 +1100 |
commit | bd53ffcbefe4e7a22fc493b1916939bae5f9dc1d (patch) | |
tree | bfe435d75b222d464a9cbb21e25583d33c591936 /test/simpleTests.py | |
parent | 07a7683902feb4b9944394b9378f0a1a51972497 (diff) | |
download | scintilla-mirror-bd53ffcbefe4e7a22fc493b1916939bae5f9dc1d.tar.gz |
Implement API to read and write undo history from applications.
Diffstat (limited to 'test/simpleTests.py')
-rw-r--r-- | test/simpleTests.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/simpleTests.py b/test/simpleTests.py index 4263ad036..72007f86a 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -887,6 +887,82 @@ class TestSimple(unittest.TestCase): self.assertEqual(self.ed.IsRangeWord(6, 7), 0) self.assertEqual(self.ed.IsRangeWord(6, 8), 1) +atInsertion = 0 +atDeletion = 1 +actMayCoalesce = 0x100 + +class TestUndoSaveRestore(unittest.TestCase): + + def setUp(self): + self.xite = Xite.xiteFrame + self.ed = self.xite.ed + self.ed.ClearAll() + self.ed.EmptyUndoBuffer() + self.data = b"xy" + + def testSave(self): + self.ed.InsertText(0, self.data) + self.assertEqual(self.ed.Contents(), b"xy") + self.ed.SetSavePoint() + self.ed.InsertText(0, self.data) + self.assertEqual(self.ed.Contents(), b"xyxy") + self.ed.DeleteRange(1, 2) + self.assertEqual(self.ed.Contents(), b"xy") + self.ed.DeleteRange(1, 1) + self.assertEqual(self.ed.Contents(), b"x") + + self.assertEqual(self.ed.UndoActions, 4) + self.assertEqual(self.ed.UndoCurrent, 4) + self.assertEqual(self.ed.UndoSavePoint, 1) + self.assertEqual(self.ed.UndoTentative, -1) + self.assertEqual(self.ed.GetUndoActionType(0), atInsertion) + self.assertEqual(self.ed.GetUndoActionPosition(0), 0) + self.assertEqual(bytes(self.ed.GetUndoActionText(0)), self.data) + self.assertEqual(self.ed.GetUndoActionType(1), atInsertion) + self.assertEqual(self.ed.GetUndoActionPosition(1), 0) + self.assertEqual(bytes(self.ed.GetUndoActionText(1)), self.data) + self.assertEqual(self.ed.GetUndoActionType(2), atDeletion + actMayCoalesce) + self.assertEqual(self.ed.GetUndoActionPosition(2), 1) + self.assertEqual(bytes(self.ed.GetUndoActionText(2)), b'yx') + self.assertEqual(self.ed.GetUndoActionType(3), atDeletion + actMayCoalesce) + self.assertEqual(self.ed.GetUndoActionPosition(3), 1) + self.assertEqual(bytes(self.ed.GetUndoActionText(3)), b'y') + + def testRestore(self): + self.ed.InsertText(0, self.data) + self.assertEqual(self.ed.Contents(), b"xy") + self.ed.EmptyUndoBuffer() + + self.ed.PushUndoActionType(atInsertion, 0) + self.ed.ChangeLastUndoActionText(2, b'xy') + self.ed.PushUndoActionType(atInsertion, 0) + self.ed.ChangeLastUndoActionText(2, b'xy') + self.ed.PushUndoActionType(atDeletion + actMayCoalesce, 1) + self.ed.ChangeLastUndoActionText(2, b'yx') + self.ed.PushUndoActionType(atDeletion + actMayCoalesce, 1) + self.ed.ChangeLastUndoActionText(1, b'y') + + self.assertEqual(self.ed.UndoActions, 4) + self.ed.SetUndoCurrent(1) + self.ed.SetUndoSavePoint(1) + self.ed.SetUndoTentative(-1) + + self.ed.Undo() + self.assertEqual(self.ed.UndoCurrent, 0) + self.assertEqual(self.ed.Contents(), b"") + self.ed.Redo() + self.assertEqual(self.ed.UndoCurrent, 1) + self.assertEqual(self.ed.Contents(), b"xy") + self.ed.Redo() + self.assertEqual(self.ed.UndoCurrent, 2) + self.assertEqual(self.ed.Contents(), b"xyxy") + self.ed.Redo() # Does 2 actions due to mayCoalesce + self.assertEqual(self.ed.UndoCurrent, 4) + self.assertEqual(self.ed.Contents(), b"x") + + # No more redo actions + self.assertEqual(self.ed.CanRedo(), 0) + class TestChangeHistory(unittest.TestCase): def setUp(self): |