cc-mode-tests.el 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ;;; cc-mode-tests.el --- Test suite for cc-mode. -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
  3. ;; Author: Michal Nazarewicz <mina86@mina86.com>
  4. ;; Keywords: internal
  5. ;; Human-Keywords: internal
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Unit tests for cc-mode.el.
  19. ;;; Code:
  20. (require 'ert)
  21. (require 'ert-x)
  22. (require 'cc-mode)
  23. (ert-deftest c-or-c++-mode ()
  24. "Test c-or-c++-mode language detection."
  25. (cl-letf* ((mode nil)
  26. (do-test (lambda (content expected)
  27. (delete-region (point-min) (point-max))
  28. (insert content)
  29. (setq mode nil)
  30. (c-or-c++-mode)
  31. (unless(eq expected mode)
  32. (ert-fail
  33. (format "expected %s but got %s when testing '%s'"
  34. expected mode content)))))
  35. ((symbol-function 'c-mode) (lambda () (setq mode 'c-mode)))
  36. ((symbol-function 'c++-mode) (lambda () (setq mode 'c++-mode))))
  37. (with-temp-buffer
  38. (mapc (lambda (content)
  39. (funcall do-test content 'c++-mode)
  40. (funcall do-test (concat "// " content) 'c-mode)
  41. (funcall do-test (concat " * " content) 'c-mode))
  42. '("using \t namespace \t std;"
  43. "using \t std::string;"
  44. "namespace \t {"
  45. "namespace \t foo \t {"
  46. "class \t Blah_42 \t {"
  47. "class \t Blah_42 \t \n"
  48. "class \t _42_Blah:public Foo {"
  49. "template \t < class T >"
  50. "template< class T >"
  51. "#include <string>"
  52. "#include<iostream>"
  53. "#include \t <map>"))
  54. (mapc (lambda (content) (funcall do-test content 'c-mode))
  55. '("struct \t Blah_42 \t {"
  56. "struct template {"
  57. "#include <string.h>")))))
  58. ;;; cc-mode-tests.el ends here