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