whitespace-tests.el 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ;;; whitespace-tests.el --- Test suite for whitespace -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
  3. ;; This file is part of GNU Emacs.
  4. ;; GNU Emacs is free software: you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; GNU Emacs is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Code:
  15. (require 'ert)
  16. (require 'whitespace)
  17. (defun whitespace-tests--cleanup-string (string)
  18. (with-temp-buffer
  19. (insert string)
  20. (whitespace-cleanup)
  21. (buffer-string)))
  22. (ert-deftest whitespace-cleanup-eob ()
  23. (let ((whitespace-style '(empty)))
  24. (should (equal (whitespace-tests--cleanup-string "a\n")
  25. "a\n"))
  26. (should (equal (whitespace-tests--cleanup-string "a\n\n")
  27. "a\n"))
  28. (should (equal (whitespace-tests--cleanup-string "a\n\t\n")
  29. "a\n"))
  30. (should (equal (whitespace-tests--cleanup-string "a\n\t \n")
  31. "a\n"))
  32. (should (equal (whitespace-tests--cleanup-string "a\n\t \n\n")
  33. "a\n"))
  34. (should (equal (whitespace-tests--cleanup-string "\n\t\n")
  35. ""))
  36. ;; Whitespace at end of non-empty line is not covered by the
  37. ;; `empty' style.
  38. (should (equal (whitespace-tests--cleanup-string "a \n\t \n\n")
  39. "a \n"))))
  40. (provide 'whitespace-tests)
  41. ;;; whitespace-tests.el ends here