feat: add refile heading
Some checks failed
Testing / pytest (push) Failing after 1s
Testing / mypy (push) Failing after 0s
Testing / style-formatting (push) Failing after 1s
Testing / style-sorted-imports (push) Failing after 0s
Testing / stability-extra-test (push) Failing after 0s

This commit is contained in:
Lyz 2025-01-26 12:03:47 +01:00
parent 8280949f23
commit 8ecccb8b24
No known key found for this signature in database
GPG key ID: 6C7D7C1612CDE02F
2 changed files with 226 additions and 1 deletions

View file

@ -1024,6 +1024,171 @@ class TestSerde(unittest.TestCase):
self.assertEqual(dumps(doc), "* TODO First entry")
def test_refile_headline_down_to_bottom(self) -> None:
orig = """* Source Headline
** Child of Source
* Destination Headline
** Existing Child"""
doc = loads(orig)
source_headline = doc.headlines[0]
destination_headline = doc.headlines[1]
result = source_headline.refile(destination_headline)
assert result == destination_headline
assert source_headline.parent == destination_headline
assert source_headline in destination_headline.children
assert destination_headline.children[-1] == source_headline
assert (
dumps(doc)
== """* Destination Headline
** Existing Child
** Source Headline
*** Child of Source"""
)
def test_refile_headline_down_to_top(self) -> None:
orig = """* Source Headline
** Child of Source
* Destination Headline
** Existing Child"""
doc = loads(orig)
source_headline = doc.headlines[0]
destination_headline = doc.headlines[1]
result = source_headline.refile(destination_headline, top=True)
assert result == destination_headline
assert source_headline.parent == destination_headline
assert source_headline in destination_headline.children
assert destination_headline.children[0] == source_headline
assert (
dumps(doc)
== """* Destination Headline
** Source Headline
*** Child of Source
** Existing Child"""
)
def test_refile_headline_down_to_existing_child(self) -> None:
orig = """* Source Headline
** Child of Source
* Destination Parent
** Destination Headline"""
doc = loads(orig)
source_headline = doc.headlines[0]
destination_headline = doc.headlines[1]
destination_child = destination_headline.children[0]
result = source_headline.refile(destination_child)
assert result == destination_child
assert source_headline.parent == destination_child
assert source_headline in destination_child.children
assert destination_child.children[-1] == source_headline
assert (
dumps(doc)
== """* Destination Parent
** Destination Headline
*** Source Headline
**** Child of Source"""
)
def test_refile_headline_from_child_to_parent_bottom(self) -> None:
orig = """* Destination Headline
** Existing Child
*** Source Headline
**** Source Child"""
doc = loads(orig)
source_headline = doc.headlines[0].children[0].children[0]
destination_headline = doc.headlines[0]
result = source_headline.refile(destination_headline)
assert result == destination_headline
assert source_headline.parent == destination_headline
assert source_headline in destination_headline.children
assert destination_headline.children[-1] == source_headline
assert (
dumps(doc)
== """* Destination Headline
** Existing Child
** Source Headline
*** Source Child"""
)
def test_refile_headline_from_child_to_parent_top(self) -> None:
orig = """* Destination Headline
** Existing Child
*** Source Headline
**** Source Child"""
doc = loads(orig)
source_headline = doc.headlines[0].children[0].children[0]
destination_headline = doc.headlines[0]
result = source_headline.refile(destination_headline, top=True)
assert result == destination_headline
assert source_headline.parent == destination_headline
assert source_headline in destination_headline.children
assert destination_headline.children[0] == source_headline
assert (
dumps(doc)
== """* Destination Headline
** Source Headline
*** Source Child
** Existing Child"""
)
def test_refile_headline_from_child_to_first_level_at_bottom(self) -> None:
orig = """* Destination Headline
** Existing Child
*** Source Headline
**** Source Child"""
doc = loads(orig)
source_headline = doc.headlines[0].children[0].children[0]
destination_headline = doc.headlines[0].parent
result = source_headline.refile(destination_headline)
assert result == destination_headline
assert source_headline.parent == destination_headline
assert source_headline in destination_headline.children
assert destination_headline.children[-1] == source_headline
assert (
dumps(doc)
== """* Destination Headline
** Existing Child
* Source Headline
** Source Child"""
)
def test_refile_headline_from_child_to_first_level_at_top(self) -> None:
orig = """* Destination Headline
** Existing Child
*** Source Headline
**** Source Child"""
doc = loads(orig)
source_headline = doc.headlines[0].children[0].children[0]
destination_headline = doc.headlines[0].parent
result = source_headline.refile(destination_headline, top=True)
assert result == destination_headline
assert source_headline.parent == destination_headline
assert source_headline in destination_headline.children
assert destination_headline.children[0] == source_headline
assert (
dumps(doc)
== """* Source Headline
** Source Child
* Destination Headline
** Existing Child"""
)
def print_tree(tree, indentation=0, headline=None):
for element in tree: