forked from kenkeiras/org-rw
feat: add refile heading
This commit is contained in:
parent
8280949f23
commit
8ecccb8b24
2 changed files with 226 additions and 1 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue