aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-11 14:29:03 -0500
committerCraig Jennings <c@cjennings.net>2026-07-11 14:29:03 -0500
commit016f322de184b09d79cb1d7db522a0aaa6c00a9f (patch)
treef3ca3d8607244a71953fd9616e53ed7445853094 /tests
parent1ba475cb0cf7076a284b13d808029309d13ea08c (diff)
downloaddotemacs-016f322de184b09d79cb1d7db522a0aaa6c00a9f.tar.gz
dotemacs-016f322de184b09d79cb1d7db522a0aaa6c00a9f.zip
fix(custom-ordering): preserve the trailing newline in reverse and number
cj/reverse-lines and cj/number-lines split the region on newlines without accounting for a trailing one, so it became a spurious empty element. Reversing "a\nb\n" floated that empty to the top ("\nb\na"), and numbering added a phantom final numbered line. Both now strip a trailing newline before splitting and reattach it after, matching cj/--arrayify, while preserving internal blank lines. Corrected the two tests that asserted the broken output.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-custom-ordering-number-lines.el5
-rw-r--r--tests/test-custom-ordering-reverse-lines.el6
2 files changed, 7 insertions, 4 deletions
diff --git a/tests/test-custom-ordering-number-lines.el b/tests/test-custom-ordering-number-lines.el
index adda84f0..142e5561 100644
--- a/tests/test-custom-ordering-number-lines.el
+++ b/tests/test-custom-ordering-number-lines.el
@@ -122,9 +122,10 @@ Returns the transformed string."
(should (string= result "1. "))))
(ert-deftest test-number-lines-empty-lines ()
- "Should number empty lines."
+ "Should number empty lines, treating the final newline as a terminator.
+The old split counted the trailing newline as a spurious third line."
(let ((result (test-number-lines "\n\n" "N. " nil)))
- (should (string= result "1. \n2. \n3. "))))
+ (should (string= result "1. \n2. \n"))))
(ert-deftest test-number-lines-with-existing-numbers ()
"Should number lines that already have content."
diff --git a/tests/test-custom-ordering-reverse-lines.el b/tests/test-custom-ordering-reverse-lines.el
index 3c71362d..5b8c01ac 100644
--- a/tests/test-custom-ordering-reverse-lines.el
+++ b/tests/test-custom-ordering-reverse-lines.el
@@ -86,9 +86,11 @@ Returns the transformed string."
(should (string= result "b\n\na"))))
(ert-deftest test-reverse-lines-trailing-newline ()
- "Should handle trailing newline."
+ "Should reverse the lines and preserve the trailing newline.
+The old split dropped the trailing newline into a leading empty line,
+producing \"\\nline2\\nline1\"."
(let ((result (test-reverse-lines "line1\nline2\n")))
- (should (string= result "\nline2\nline1"))))
+ (should (string= result "line2\nline1\n"))))
(ert-deftest test-reverse-lines-only-newlines ()
"Should reverse lines that are only newlines."