subword-tests.el 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ;;; subword-tests.el --- Testing the subword rules
  2. ;; Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
  4. ;; Keywords:
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (require 'ert)
  19. (require 'subword)
  20. (defconst subword-tests-strings
  21. '("ABC^" ;;Bug#13758
  22. "ABC^ ABC^Foo^ ABC^-Foo^ toto^ ABC^"))
  23. (ert-deftest subword-tests ()
  24. "Test the `subword-mode' rules."
  25. (with-temp-buffer
  26. (dolist (str subword-tests-strings)
  27. (erase-buffer)
  28. (insert str)
  29. (goto-char (point-min))
  30. (while (search-forward "^" nil t)
  31. (replace-match ""))
  32. (goto-char (point-min))
  33. (while (not (eobp))
  34. (subword-forward 1)
  35. (insert "^"))
  36. (should (equal (buffer-string) str)))))
  37. (ert-deftest subword-tests2 ()
  38. "Test that motion in subword-mode stops at the right places."
  39. (let* ((line "fooBarBAZ quXD g_TESTThingAbc word BLAH test")
  40. (fwrd "* * * * * * * * * * * * *")
  41. (bkwd "* * * * * * * * * * * * *"))
  42. (with-temp-buffer
  43. (subword-mode 1)
  44. (insert line)
  45. ;; Test forward motion.
  46. (goto-char (point-min))
  47. (let ((stops (make-string (length fwrd) ?\ )))
  48. (while (progn
  49. (aset stops (1- (point)) ?\*)
  50. (not (eobp)))
  51. (forward-word))
  52. (should (equal stops fwrd)))
  53. ;; Test backward motion.
  54. (goto-char (point-max))
  55. (let ((stops (make-string (length bkwd) ?\ )))
  56. (while (progn
  57. (aset stops (1- (point)) ?\*)
  58. (not (bobp)))
  59. (backward-word))
  60. (should (equal stops bkwd))))))
  61. (provide 'subword-tests)
  62. ;;; subword-tests.el ends here