summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLele Gaifax <lele@metapensiero.it>2022-01-28 08:41:51 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2022-01-28 15:23:05 +0100
commit70c3437ae1f20c050ecb96a642c9a568fd656105 (patch)
tree7643bc6c4c10209eb0589e5421b733ad24b1be2b
parent7ba197a163ddf4002253d7b9a26fb28076e1cef7 (diff)
downloademacs-70c3437ae1f20c050ecb96a642c9a568fd656105.tar.gz
Fix copyright-fix-years, use a dash to separate years in a range
Commit 7a46fa9c751f7c3147cd9b27fe84c1ce25419d3b, allowing en-dash as years separator, changed the way the years range is composed taking the separator from the `sep' variable instead of always using an hardwired hyphen. Since the code explicitly avoid to touch (that is, extend) existing ranges, that `sep' variable is almost always a space, or whatever character precedes the last parsed year, thus generating a range like "2020 2022" instead of "2020-2022". * lisp/emacs-lisp/copyright.el (copyright-fix-years): Always use an dash to separate years in a range. * test/lisp/emacs-lisp/copyright-tests.el (with-copyright-fix-years-test): (copyright-fix-years-tests--data): (text-copyright-fix-years): New test cases (bug#53597).
-rw-r--r--lisp/emacs-lisp/copyright.el2
-rw-r--r--test/lisp/emacs-lisp/copyright-tests.el20
2 files changed, 21 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el
index 6b600977823..e5087672ae7 100644
--- a/lisp/emacs-lisp/copyright.el
+++ b/lisp/emacs-lisp/copyright.el
@@ -313,7 +313,7 @@ independently replaces consecutive years with a range."
(> prev-year first-year))
(goto-char range-end)
(delete-region range-start range-end)
- (insert (format "%c%d" sep prev-year))
+ (insert (format "-%d" prev-year))
(goto-char p))
(setq first-year year
range-start (point)))))
diff --git a/test/lisp/emacs-lisp/copyright-tests.el b/test/lisp/emacs-lisp/copyright-tests.el
index abb0913a0d7..b00d697aa64 100644
--- a/test/lisp/emacs-lisp/copyright-tests.el
+++ b/test/lisp/emacs-lisp/copyright-tests.el
@@ -72,5 +72,25 @@
(buffer-string))
"Copyright 2021 FSF\nCopyright 2021, 2022 FSF\n")))
+(defmacro with-copyright-fix-years-test (orig result)
+ `(let ((copyright-year-ranges t))
+ (with-temp-buffer
+ (insert ,orig)
+ (copyright-fix-years)
+ (should (equal (buffer-string) ,result)))))
+
+(defvar copyright-fix-years-tests--data
+ '((";; Copyright (C) 2008, 2010, 2012"
+ . ";; Copyright (C) 2008, 2010, 2012")
+ (";; Copyright (C) 2008, 2009, 2010, 2013, 2014, 2015, 2016, 2018"
+ . ";; Copyright (C) 2008-2010, 2013-2016, 2018")
+ (";; Copyright (C) 2008-2010, 2011, 2015, 2016, 2017"
+ . ";; Copyright (C) 2008-2010, 2011, 2015-2017")))
+
+(ert-deftest text-copyright-fix-years ()
+ "Test basics of \\[copyright-fix-years]."
+ (dolist (test copyright-fix-years-tests--data)
+ (with-copyright-fix-years-test (car test) (cdr test))))
+
(provide 'copyright-tests)
;;; copyright-tests.el ends here