]> code.delx.au - gnu-emacs/blob - test/lisp/progmodes/cc-mode.el
Automatically detect whether .h file is C or C++
[gnu-emacs] / test / lisp / progmodes / cc-mode.el
1 ;;; cc-mode-tests.el --- Test suite for cc-mode. -*- lexical-binning: t -*-
2
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5 ;; Author: Michal Nazarewicz <mina86@mina86.com>
6 ;; Keywords: internal
7 ;; Human-Keywords: internal
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Code:
25
26 (require 'ert)
27 (require 'ert-x)
28 (require 'cc-mode)
29
30 (ert-deftest c-or-c++-mode ()
31 "Test c-or-c++-mode language detection."
32 (cl-letf* ((mode nil)
33 (do-test (lambda (content expected)
34 (delete-region (point-min) (point-max))
35 (insert content)
36 (setq mode nil)
37 (c-or-c++-mode)
38 (unless(eq expected mode)
39 (ert-fail
40 (format "expected %s but got %s when testing '%s'"
41 expected mode content)))))
42 ((symbol-function 'c-mode) (lambda () (setq mode 'c-mode)))
43 ((symbol-function 'c++-mode) (lambda () (setq mode 'c++-mode))))
44 (with-temp-buffer
45 (mapc (lambda (content)
46 (funcall do-test content 'c++-mode)
47 (funcall do-test (concat "// " content) 'c-mode)
48 (funcall do-test (concat " * " content) 'c-mode))
49 '("using \t namespace \t std;"
50 "using \t std::string;"
51 "namespace \t {"
52 "namespace \t foo \t {"
53 "class \t Blah_42 \t {"
54 "class \t Blah_42 \t \n"
55 "class \t _42_Blah:public Foo {"
56 "template \t < class T >"
57 "template< class T >"
58 "#include <string>"
59 "#include<iostream>"
60 "#include \t <map>"))
61
62 (mapc (lambda (content) (funcall do-test content 'c-mode))
63 '("struct \t Blah_42 \t {"
64 "struct template {"
65 "#include <string.h>")))))