Correctly handle undo with multiple tasks

The `std::stringstream::clear` method does not, in fact, clear the
string -- it just resets some internal flags. Assigning a new
stringstream to the variable is not the most efficient way to do this,
but it's the clearest.
This commit is contained in:
Dustin J. Mitchell 2025-05-25 17:36:14 -04:00
parent 89d84f0bdd
commit 85a1508a01
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View file

@ -102,7 +102,7 @@ bool CmdUndo::confirm_revert(const std::vector<Operation>& undo_ops) {
view.set(row, 1, mods.str());
}
last_uuid = op.get_uuid();
mods.clear();
mods = std::stringstream();
}
if (op.is_create()) {

View file

@ -27,6 +27,7 @@
import sys
import os
import re
import unittest
# Ensure python finds the local simpletap module
@ -61,6 +62,19 @@ class TestUndo(TestCase):
code, out, err = self.t("_get 1.status")
self.assertEqual(out.strip(), "pending")
def test_modify_multiple_tasks(self):
"""'add' then 'done' then 'undo'"""
self.t("add one")
self.t("add two")
self.t("add three")
self.t("rc.bulk=0 1,2,3 modify +sometag")
code, out, err = self.t("undo", input="y\n")
# This undo output should show one tag modification for each task, possibly with some
# modification-time updates if the modifications spanned a second boundary.
self.assertRegex(
out,
'\s+'.join([r"""[0-9a-f-]{36} (Update property 'modified' from\s+'[0-9]+' to '[0-9]+'\s+)?Add tag 'sometag'\s+Add property 'tags' with value 'sometag'"""] * 3))
def test_undo_en_passant(self):
"""Verify that en-passant changes during undo are an error"""
self.t("add one")