X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/236f345afddf3146b81bad2b0502e2c390be38a6..1abce8eb7d46cfcbb571784260b6882b16b7f9f1:/packages/gnome-c-style/gnome-c-tests.el diff --git a/packages/gnome-c-style/gnome-c-tests.el b/packages/gnome-c-style/gnome-c-tests.el index 3b484633c..17dbfe1f7 100644 --- a/packages/gnome-c-style/gnome-c-tests.el +++ b/packages/gnome-c-style/gnome-c-tests.el @@ -1,4 +1,28 @@ +;;; gnome-c-tests.el --- tests for gnome-c-style -*- lexical-binding: t; -*- +;; Copyright (C) 2016 Free Software Foundation, Inc. + +;; Author: Daiki Ueno +;; Keywords: GNOME, C, coding style + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + (require 'gnome-c-align) +(require 'gnome-c-snippet) (defconst gnome-c-test-program-1 "\ GGpgCtx *g_gpg_ctx_new (GError **error); @@ -106,6 +130,11 @@ int identifier_1234567890 double b); ") +(defconst gnome-c-test-program-7 "\ +G_DECLARE_FINAL_TYPE (GGpgEngineInfo, g_gpg_engine_info, G_GPG, ENGINE_INFO, + GObject) +") + (ert-deftest gnome-c-test-align--guess-optimal-columns () "Tests the `gnome-c-align--guess-optimal-columns'." (with-temp-buffer @@ -189,3 +218,67 @@ int identifier_1234567890 (should (= gnome-c-align-identifier-start-column 13)) (should (= gnome-c-align-arglist-start-column 40)) (should (= gnome-c-align-arglist-identifier-start-column 57)))) + +(ert-deftest gnome-c-test-snippet-guess-name-from-declaration () + "Tests the `gnome-c-snippet--guess-name-from-declaration'." + (with-temp-buffer + (insert gnome-c-test-program-7) + (c-mode) + (setq buffer-file-name "gpgme-glib.h") + (let ((package (gnome-c-snippet--guess-name-from-declaration 'package)) + (class (gnome-c-snippet--guess-name-from-declaration 'class)) + (parent-package + (gnome-c-snippet--guess-name-from-declaration 'parent-package)) + (parent-class + (gnome-c-snippet--guess-name-from-declaration 'parent-class))) + (should (equal package '("G" "Gpg"))) + (should (equal class '("Engine" "Info"))) + (should (equal parent-package '("G"))) + (should (equal parent-class '("Object")))))) + +(ert-deftest gnome-c-test-snippet-guess-name-from-declaration-2 () + "Tests the `gnome-c-snippet--guess-name-from-declaration'." + (let (buffer) + (unwind-protect + (progn + (setq buffer (generate-new-buffer "header")) + (with-current-buffer buffer + (insert gnome-c-test-program-7) + (c-mode) + (setq buffer-file-name "gpgme-glib.h")) + (with-temp-buffer + (c-mode) + (setq buffer-file-name "gpgme-glib.c") + (let ((package + (gnome-c-snippet--guess-name-from-declaration 'package)) + (class + (gnome-c-snippet--guess-name-from-declaration 'class)) + (parent-package + (gnome-c-snippet--guess-name-from-declaration + 'parent-package)) + (parent-class + (gnome-c-snippet--guess-name-from-declaration + 'parent-class))) + (should (equal package '("G" "Gpg"))) + (should (equal class '("Engine" "Info"))) + (should (equal parent-package '("G"))) + (should (equal parent-class '("Object")))))) + (kill-buffer buffer)))) + +(ert-deftest gnome-c-test-snippet-guess-name-from-file-name () + "Tests the `gnome-c-snippet--guess-name-from-file-name'" + (with-temp-buffer + (c-mode) + (setq buffer-file-name "g-gpg-engine-info.c") + (let ((package + (gnome-c-snippet--guess-name-from-file-name 'package)) + (class + (gnome-c-snippet--guess-name-from-file-name 'class)) + (parent-package + (gnome-c-snippet--guess-name-from-file-name 'parent-package)) + (parent-class + (gnome-c-snippet--guess-name-from-file-name 'parent-class))) + (should (equal package '("G"))) + (should (equal class '("Gpg" "Engine" "Info"))) + (should (equal parent-package nil)) + (should (equal parent-class nil)))))