From 2956e54b1dda1647a9399211c7d09b208b85dcfa Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Thu, 9 Feb 2023 01:09:10 +0000 Subject: [PATCH] Add an extensive test for labeled (locked) narrowing * test/src/buffer-tests.el (test-labeled-narrowing): New test. --- test/src/buffer-tests.el | 106 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 9d4bbf3e040..0ae78c8d9d9 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -8539,4 +8539,110 @@ Finally, kill the buffer and its temporary file." (if f2 (delete-file f2)) ))) +(ert-deftest test-labeled-narrowing () + "Test `with-narrowing' and `without-narrowing'." + (with-current-buffer (generate-new-buffer " foo" t) + (insert (make-string 5000 ?a)) + (should (= (point-min) 1)) + (should (= (point-max) 5001)) + (with-narrowing + 100 500 :label 'foo + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (widen) + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (narrow-to-region 1 5000) + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (narrow-to-region 50 150) + (should (= (point-min) 100)) + (should (= (point-max) 150)) + (widen) + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (narrow-to-region 400 1000) + (should (= (point-min) 400)) + (should (= (point-max) 500)) + (without-narrowing + :label 'bar + (should (= (point-min) 100)) + (should (= (point-max) 500))) + (without-narrowing + :label 'foo + (should (= (point-min) 1)) + (should (= (point-max) 5001))) + (should (= (point-min) 400)) + (should (= (point-max) 500)) + (widen) + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (with-narrowing + 50 250 :label 'bar + (should (= (point-min) 100)) + (should (= (point-max) 250)) + (widen) + (should (= (point-min) 100)) + (should (= (point-max) 250)) + (without-narrowing + :label 'bar + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (without-narrowing + :label 'foo + (should (= (point-min) 1)) + (should (= (point-max) 5001))) + (should (= (point-min) 100)) + (should (= (point-max) 500))) + (should (= (point-min) 100)) + (should (= (point-max) 250))) + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (with-narrowing + 50 250 :label 'bar + (should (= (point-min) 100)) + (should (= (point-max) 250)) + (with-narrowing + 150 500 :label 'baz + (should (= (point-min) 150)) + (should (= (point-max) 250)) + (without-narrowing + :label 'bar + (should (= (point-min) 150)) + (should (= (point-max) 250))) + (without-narrowing + :label 'foo + (should (= (point-min) 150)) + (should (= (point-max) 250))) + (without-narrowing + :label 'baz + (should (= (point-min) 100)) + (should (= (point-max) 250)) + (without-narrowing + :label 'foo + (should (= (point-min) 100)) + (should (= (point-max) 250))) + (without-narrowing + :label 'bar + (should (= (point-min) 100)) + (should (= (point-max) 500)) + (without-narrowing + :label 'foobar + (should (= (point-min) 100)) + (should (= (point-max) 500))) + (without-narrowing + :label 'foo + (should (= (point-min) 1)) + (should (= (point-max) 5001))) + (should (= (point-min) 100)) + (should (= (point-max) 500))) + (should (= (point-min) 100)) + (should (= (point-max) 250))) + (should (= (point-min) 150)) + (should (= (point-max) 250))) + (should (= (point-min) 100)) + (should (= (point-max) 250)))) + (should (= (point-min) 1)) + (should (= (point-max) 5001)))) + ;;; buffer-tests.el ends here -- 2.39.2