]> code.delx.au - gnu-emacs-elpa/blob - packages/gnome-c-style/gnome-c-tests.el
multishell - still 1.0.6, clarify conditions for tramp homedir bug
[gnu-emacs-elpa] / packages / gnome-c-style / gnome-c-tests.el
1 ;;; gnome-c-tests.el --- tests for gnome-c-style -*- lexical-binding: t; -*-
2 ;; Copyright (C) 2016 Free Software Foundation, Inc.
3
4 ;; Author: Daiki Ueno <ueno@gnu.org>
5 ;; Keywords: GNOME, C, coding style
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Code:
23
24 (require 'gnome-c-align)
25
26 (defconst gnome-c-test-program-1 "\
27 GGpgCtx *g_gpg_ctx_new (GError **error);
28
29 typedef void (*GGpgProgressCallback) (gpointer user_data,
30 const gchar *what,
31 gint type,
32 gint current,
33 gint total);
34
35 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
36 GGpgProgressCallback callback,
37 gpointer user_data,
38 GDestroyNotify destroy_data);
39 void g_gpg_ctx_add_signer (GGpgCtx *ctx, GGpgKey *key);
40 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
41 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx, guint index);
42 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
43 ")
44
45 (defconst gnome-c-test-program-1-aligned "\
46 GGpgCtx *g_gpg_ctx_new (GError **error);
47
48 typedef void (*GGpgProgressCallback) (gpointer user_data,
49 const gchar *what,
50 gint type,
51 gint current,
52 gint total);
53
54 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
55 GGpgProgressCallback callback,
56 gpointer user_data,
57 GDestroyNotify destroy_data);
58 void g_gpg_ctx_add_signer (GGpgCtx *ctx,
59 GGpgKey *key);
60 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
61 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx,
62 guint index);
63 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
64 ")
65
66 (defconst gnome-c-test-program-2 "\
67 GDK_AVAILABLE_IN_3_16
68 const gchar ** gtk_widget_list_action_prefixes (GtkWidget *widget);
69 ")
70
71 (defconst gnome-c-test-program-3 "\
72 /* overridable methods */
73 void (*set_property) (GObject *object,
74 guint property_id,
75 const GValue *value,
76 GParamSpec *pspec);
77 void (*get_property) (GObject *object,
78 guint property_id,
79 GValue *value,
80 GParamSpec *pspec);
81 ")
82
83 (defconst gnome-c-test-program-4 "\
84 FOO_AVAILABLE_IN_ALL
85 int foo (struct foo ***a, int b, ...) G_GNUC_CONST;
86 ")
87
88 (defconst gnome-c-test-program-4-aligned "\
89 FOO_AVAILABLE_IN_ALL
90 int foo (struct foo ***a,
91 int b,
92 ...) G_GNUC_CONST;
93 ")
94
95 (defconst gnome-c-test-program-5 "\
96 int * bar (const char * const * * a, int b);
97 ")
98
99 (defconst gnome-c-test-program-5-aligned "\
100 int *bar (const char * const **a,
101 int b);
102 ")
103
104 (defconst gnome-c-test-program-6 "\
105 int foo (char **a, int b);
106 type_1234567890 bar (char a, int b);
107 int identifier_1234567890 (double a, double b);
108 ")
109
110 (defconst gnome-c-test-program-6-aligned-1 "\
111 int foo
112 (char **a,
113 int b);
114 type_1234567890 bar
115 (char a,
116 int b);
117 int identifier_1234567890
118 (double a,
119 double b);
120 ")
121
122 (defconst gnome-c-test-program-6-aligned-2 "\
123 int foo (char **a,
124 int b);
125 type_1234567890 bar (char a,
126 int b);
127 int identifier_1234567890
128 (double a,
129 double b);
130 ")
131
132 (ert-deftest gnome-c-test-align--guess-optimal-columns ()
133 "Tests the `gnome-c-align--guess-optimal-columns'."
134 (with-temp-buffer
135 (insert gnome-c-test-program-1)
136 (c-mode)
137 (let* (gnome-c-align-max-column
138 (columns
139 (gnome-c-align--guess-optimal-columns (point-min) (point-max))))
140 (should (= (cdr (assq 'identifier-start-column columns)) 9))
141 (should (= (cdr (assq 'arglist-start-column columns)) 41))
142 (should (= (cdr (assq 'arglist-identifier-start-column columns)) 64)))))
143
144 (ert-deftest gnome-c-test-align-region ()
145 "Tests the `gnome-c-align-decls-region'."
146 (with-temp-buffer
147 (insert gnome-c-test-program-1)
148 (c-mode)
149 (let (gnome-c-align-max-column)
150 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
151 (gnome-c-align-decls-region (point-min) (point-max)))
152 (should (equal (buffer-string) gnome-c-test-program-1-aligned))))
153
154 (ert-deftest gnome-c-test-align-region-2 ()
155 "Tests the `gnome-c-align-decls-region'."
156 (with-temp-buffer
157 (insert gnome-c-test-program-4)
158 (c-mode)
159 (let (gnome-c-align-max-column)
160 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
161 (gnome-c-align-decls-region (point-min) (point-max)))
162 (should (equal (buffer-string) gnome-c-test-program-4-aligned))))
163
164 (ert-deftest gnome-c-test-align-region-3 ()
165 "Tests the `gnome-c-align-decls-region'."
166 (with-temp-buffer
167 (insert gnome-c-test-program-5)
168 (c-mode)
169 (let (gnome-c-align-max-column)
170 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
171 (gnome-c-align-decls-region (point-min) (point-max)))
172 (should (equal (buffer-string) gnome-c-test-program-5-aligned))))
173
174 (ert-deftest gnome-c-test-align-region-4 ()
175 "Tests the `gnome-c-align-decls-region', with max columns set."
176 (with-temp-buffer
177 (insert gnome-c-test-program-6)
178 (c-mode)
179 (let ((gnome-c-align-max-column 20))
180 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
181 (gnome-c-align-decls-region (point-min) (point-max)))
182 (should (equal (buffer-string) gnome-c-test-program-6-aligned-1))))
183
184 (ert-deftest gnome-c-test-align-region-5 ()
185 "Tests the `gnome-c-align-decls-region', with max columns set."
186 (with-temp-buffer
187 (insert gnome-c-test-program-6)
188 (c-mode)
189 (let ((gnome-c-align-max-column 30))
190 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
191 (gnome-c-align-decls-region (point-min) (point-max)))
192 (should (equal (buffer-string) gnome-c-test-program-6-aligned-2))))
193
194 (ert-deftest gnome-c-test-align-guess-columns-1 ()
195 "Tests the `gnome-c-align-guess-columns'."
196 (with-temp-buffer
197 (insert gnome-c-test-program-2)
198 (c-mode)
199 (let (gnome-c-align-max-column)
200 (gnome-c-align-guess-columns (point-min) (point-max)))
201 (should (= gnome-c-align-identifier-start-column 24))
202 (should (= gnome-c-align-arglist-start-column 56))
203 (should (= gnome-c-align-arglist-identifier-start-column 80))))
204
205 (ert-deftest gnome-c-test-align-guess-columns-2 ()
206 "Tests the `gnome-c-align-guess-columns'."
207 (with-temp-buffer
208 (insert gnome-c-test-program-3)
209 (c-mode)
210 (let (gnome-c-align-max-column)
211 (gnome-c-align-guess-columns (point-min) (point-max)))
212 (should (= gnome-c-align-identifier-start-column 13))
213 (should (= gnome-c-align-arglist-start-column 40))
214 (should (= gnome-c-align-arglist-identifier-start-column 57))))