Subject: bug#36009: [PATCH] Use lexical-binding in textmodes/page.el and add tests

From: Stefan Kangas <[email-masked]>
Date: Fri, 14 Jun 2019 00:02:21 +0200

Simen Heggestøyl <[email-masked]> writes:
> Oh, sorry Stefan, what a coincidence! I chose that file at random
> yesterday. I should do a Debbugs search in advance next time.

No worries -- this fruit was clearly ripe for the taking. :)

> Regarding the tests they look almost identical, except that I left out
> tests for `count-lines-page' and `what-page', because I was unsure
> whether they would be too dependent on the format of the user messages.
>
> Maybe it would be good to factor out the meat of `count-lines-page'
> and `what-page' into two internal functions returning just the raw
> numbers, test those, and turn the interactive functions into
> interfaces for them?

Thanks for your input.

I did an experiment in your suggested direction, but it didn't come
out very successful.  In particular, I felt like I had to make this
simple and straightforward code ugly and convoluted.  I could attach
the final result of that experiment here, but I don't think it's very
helpful.

Based on this, I'm instead suggesting the attached simple patch for
installation.  It depends on the message string, but this should be
easy to update in the future if the format changes.

Thanks,
Stefan Kangas
From ff0fa006cae4b6220a5e765e25f3eef1f46edef0 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Thu, 13 Jun 2019 23:46:04 +0200
Subject: [PATCH] Add tests for count-lines-page and what-page

* test/lisp/textmodes/page-tests.el (page-tests-count-lines-page)
(page-tests-what-page): New test cases. (bug#36009)
---
 test/lisp/textmodes/page-tests.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/test/lisp/textmodes/page-tests.el b/test/lisp/textmodes/page-tests.el
index 0834d65433..8d2a036022 100644
--- a/test/lisp/textmodes/page-tests.el
+++ b/test/lisp/textmodes/page-tests.el
@@ -82,5 +82,24 @@ page-tests--region-string
     (narrow-to-page -1)
     (should (equal (buffer-string) "bar\n"))))
 
+(ert-deftest page-tests-count-lines-page ()
+  (with-temp-buffer
+    (insert "foo\n\nbar\n\nbaz")
+    (goto-char (point-min))
+    (should (equal (count-lines-page) "Page has 1 line (0 + 1)"))
+    (goto-char (point-max))
+    (count-lines-page)
+    (should (equal (count-lines-page) "Page has 2 lines (2 + 0)"))))
+
+(ert-deftest page-tests-what-page ()
+  (with-temp-buffer
+    (insert "foo\n\nbar\n\nbaz")
+    (goto-char (point-min))
+    (should (equal (what-page) "Page 1, line 1"))
+    (forward-page)
+    (should (equal (what-page) "Page 2, line 2"))
+    (forward-page)
+    (should (equal (what-page) "Page 3, line 4"))))
+
 (provide 'page-tests)
 ;;; page-tests.el ends here
-- 
2.11.0