From 123f5c911541928c3d40f26afb1feeb5f20dcc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Wed, 16 Apr 2025 00:05:24 +0200 Subject: [PATCH] test: Propose tests for title parsing changes. --- tests/14-titles.org | 12 ++++++++++++ tests/test_org.py | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/14-titles.org diff --git a/tests/14-titles.org b/tests/14-titles.org new file mode 100644 index 0000000..75b88a7 --- /dev/null +++ b/tests/14-titles.org @@ -0,0 +1,12 @@ +#+TITLE: 14-Simple +#+DESCRIPTION: Org file to evaluate titles +#+TODO: TODO(t) PAUSED(p) | DONE(d) + + +* Simple title + +* Simple title with tags :tag: + +* Simple title with trailing space + +* Simple title with leading space diff --git a/tests/test_org.py b/tests/test_org.py index a1fdff1..d6b4351 100644 --- a/tests/test_org.py +++ b/tests/test_org.py @@ -955,6 +955,24 @@ class TestSerde(unittest.TestCase): h1_2_h2 = h1_2.children[0] self.assertEqual(sorted(h1_2_h2.tags), ["otherh2tag"]) + def test_titles_file(self): + with open(os.path.join(DIR, "14-titles.org")) as f: + doc = load(f) + + h1, h2, h3, h4 = doc.getTopHeadlines() + self.assertEqual(h1.title.get_text(), "Simple title") + self.assertEqual(h2.title.get_text(), "Simple title with tags") + self.assertEqual(h3.title.get_text(), "Simple title with trailing space") + self.assertEqual(h4.title.get_text(), "Simple title with leading space") + + def test_mimic_write_file_14(self): + """A goal of this library is to be able to update a file without changing parts not directly modified.""" + with open(os.path.join(DIR, "14-titles.org")) as f: + orig = f.read() + doc = loads(orig) + + self.assertEqual(dumps(doc), orig) + def test_update_headline_from_none_to_todo(self): orig = "* First entry" doc = loads(orig)