diff options
| author | Michal Nazarewicz | 2016-06-07 14:05:36 +0200 |
|---|---|---|
| committer | Michal Nazarewicz | 2016-06-15 18:26:12 +0200 |
| commit | 40e0ef481160d0a0b2290d47c012cc50021a8a82 (patch) | |
| tree | 4e728d3bdec813b592efa7834f8863d37d4f68b2 /test | |
| parent | 3be326e8e50e296ebd6ed116b5e5b7b54267b087 (diff) | |
| download | emacs-40e0ef481160d0a0b2290d47c012cc50021a8a82.tar.gz emacs-40e0ef481160d0a0b2290d47c012cc50021a8a82.zip | |
Automatically detect whether .h file is C or C++
* lisp/progmodes/cc-mode.el (c-or-c++-mode): A new function which
analyses contents of the buffer to determine whether it looks like C++
source code and based on that enables c-mode or c++-mode.
(c-or-c++-mode--regexp): Regular expression which, when matches
a buffer, signals file is C++.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/progmodes/cc-mode.el | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/lisp/progmodes/cc-mode.el b/test/lisp/progmodes/cc-mode.el new file mode 100644 index 00000000000..6cd9fa4bad5 --- /dev/null +++ b/test/lisp/progmodes/cc-mode.el | |||
| @@ -0,0 +1,65 @@ | |||
| 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>"))))) | ||