]> code.delx.au - gnu-emacs-elpa/blob - gnome-c-tests.el
Squashed 'packages/gnome-c-style/' content from commit e84487c
[gnu-emacs-elpa] / gnome-c-tests.el
1 (require 'gnome-c-align)
2
3 (defconst gnome-c-test-program-1 "\
4 GGpgCtx *g_gpg_ctx_new (GError **error);
5
6 typedef void (*GGpgProgressCallback) (gpointer user_data,
7 const gchar *what,
8 gint type,
9 gint current,
10 gint total);
11
12 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
13 GGpgProgressCallback callback,
14 gpointer user_data,
15 GDestroyNotify destroy_data);
16 void g_gpg_ctx_add_signer (GGpgCtx *ctx, GGpgKey *key);
17 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
18 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx, guint index);
19 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
20 ")
21
22 (defconst gnome-c-test-program-1-aligned "\
23 GGpgCtx *g_gpg_ctx_new (GError **error);
24
25 typedef void (*GGpgProgressCallback) (gpointer user_data,
26 const gchar *what,
27 gint type,
28 gint current,
29 gint total);
30
31 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
32 GGpgProgressCallback callback,
33 gpointer user_data,
34 GDestroyNotify destroy_data);
35 void g_gpg_ctx_add_signer (GGpgCtx *ctx,
36 GGpgKey *key);
37 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
38 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx,
39 guint index);
40 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
41 ")
42
43 (defconst gnome-c-test-program-2 "\
44 GDK_AVAILABLE_IN_3_16
45 const gchar ** gtk_widget_list_action_prefixes (GtkWidget *widget);
46 ")
47
48 (defconst gnome-c-test-program-3 "\
49 /* overridable methods */
50 void (*set_property) (GObject *object,
51 guint property_id,
52 const GValue *value,
53 GParamSpec *pspec);
54 void (*get_property) (GObject *object,
55 guint property_id,
56 GValue *value,
57 GParamSpec *pspec);
58 ")
59
60 (defconst gnome-c-test-program-4 "\
61 FOO_AVAILABLE_IN_ALL
62 int foo (struct foo ***a, int b, ...) G_GNUC_CONST;
63 ")
64
65 (defconst gnome-c-test-program-4-aligned "\
66 FOO_AVAILABLE_IN_ALL
67 int foo (struct foo ***a,
68 int b,
69 ...) G_GNUC_CONST;
70 ")
71
72 (defconst gnome-c-test-program-5 "\
73 int * bar (const char * const * * a, int b);
74 ")
75
76 (defconst gnome-c-test-program-5-aligned "\
77 int *bar (const char * const **a,
78 int b);
79 ")
80
81 (defconst gnome-c-test-program-6 "\
82 int foo (char **a, int b);
83 type_1234567890 bar (char a, int b);
84 int identifier_1234567890 (double a, double b);
85 ")
86
87 (defconst gnome-c-test-program-6-aligned-1 "\
88 int foo
89 (char **a,
90 int b);
91 type_1234567890 bar
92 (char a,
93 int b);
94 int identifier_1234567890
95 (double a,
96 double b);
97 ")
98
99 (defconst gnome-c-test-program-6-aligned-2 "\
100 int foo (char **a,
101 int b);
102 type_1234567890 bar (char a,
103 int b);
104 int identifier_1234567890
105 (double a,
106 double b);
107 ")
108
109 (ert-deftest gnome-c-test-align--guess-optimal-columns ()
110 "Tests the `gnome-c-align--guess-optimal-columns'."
111 (with-temp-buffer
112 (insert gnome-c-test-program-1)
113 (c-mode)
114 (let* (gnome-c-align-max-column
115 (columns
116 (gnome-c-align--guess-optimal-columns (point-min) (point-max))))
117 (should (= (cdr (assq 'identifier-start-column columns)) 9))
118 (should (= (cdr (assq 'arglist-start-column columns)) 41))
119 (should (= (cdr (assq 'arglist-identifier-start-column columns)) 64)))))
120
121 (ert-deftest gnome-c-test-align-region ()
122 "Tests the `gnome-c-align-decls-region'."
123 (with-temp-buffer
124 (insert gnome-c-test-program-1)
125 (c-mode)
126 (let (gnome-c-align-max-column)
127 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
128 (gnome-c-align-decls-region (point-min) (point-max)))
129 (should (equal (buffer-string) gnome-c-test-program-1-aligned))))
130
131 (ert-deftest gnome-c-test-align-region-2 ()
132 "Tests the `gnome-c-align-decls-region'."
133 (with-temp-buffer
134 (insert gnome-c-test-program-4)
135 (c-mode)
136 (let (gnome-c-align-max-column)
137 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
138 (gnome-c-align-decls-region (point-min) (point-max)))
139 (should (equal (buffer-string) gnome-c-test-program-4-aligned))))
140
141 (ert-deftest gnome-c-test-align-region-3 ()
142 "Tests the `gnome-c-align-decls-region'."
143 (with-temp-buffer
144 (insert gnome-c-test-program-5)
145 (c-mode)
146 (let (gnome-c-align-max-column)
147 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
148 (gnome-c-align-decls-region (point-min) (point-max)))
149 (should (equal (buffer-string) gnome-c-test-program-5-aligned))))
150
151 (ert-deftest gnome-c-test-align-region-4 ()
152 "Tests the `gnome-c-align-decls-region', with max columns set."
153 (with-temp-buffer
154 (insert gnome-c-test-program-6)
155 (c-mode)
156 (let ((gnome-c-align-max-column 20))
157 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
158 (gnome-c-align-decls-region (point-min) (point-max)))
159 (should (equal (buffer-string) gnome-c-test-program-6-aligned-1))))
160
161 (ert-deftest gnome-c-test-align-region-5 ()
162 "Tests the `gnome-c-align-decls-region', with max columns set."
163 (with-temp-buffer
164 (insert gnome-c-test-program-6)
165 (c-mode)
166 (let ((gnome-c-align-max-column 30))
167 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
168 (gnome-c-align-decls-region (point-min) (point-max)))
169 (should (equal (buffer-string) gnome-c-test-program-6-aligned-2))))
170
171 (ert-deftest gnome-c-test-align-guess-columns-1 ()
172 "Tests the `gnome-c-align-guess-columns'."
173 (with-temp-buffer
174 (insert gnome-c-test-program-2)
175 (c-mode)
176 (let (gnome-c-align-max-column)
177 (gnome-c-align-guess-columns (point-min) (point-max)))
178 (should (= gnome-c-align-identifier-start-column 24))
179 (should (= gnome-c-align-arglist-start-column 56))
180 (should (= gnome-c-align-arglist-identifier-start-column 80))))
181
182 (ert-deftest gnome-c-test-align-guess-columns-2 ()
183 "Tests the `gnome-c-align-guess-columns'."
184 (with-temp-buffer
185 (insert gnome-c-test-program-3)
186 (c-mode)
187 (let (gnome-c-align-max-column)
188 (gnome-c-align-guess-columns (point-min) (point-max)))
189 (should (= gnome-c-align-identifier-start-column 13))
190 (should (= gnome-c-align-arglist-start-column 40))
191 (should (= gnome-c-align-arglist-identifier-start-column 57))))