1 (require 'gnome-c-align)
3 (defconst gnome-c-test-program-1 "\
4 GGpgCtx *g_gpg_ctx_new (GError **error);
6 typedef void (*GGpgProgressCallback) (gpointer user_data,
12 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
13 GGpgProgressCallback callback,
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);
22 (defconst gnome-c-test-program-1-aligned "\
23 GGpgCtx *g_gpg_ctx_new (GError **error);
25 typedef void (*GGpgProgressCallback) (gpointer user_data,
31 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
32 GGpgProgressCallback callback,
34 GDestroyNotify destroy_data);
35 void g_gpg_ctx_add_signer (GGpgCtx *ctx,
37 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
38 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx,
40 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
43 (defconst gnome-c-test-program-2 "\
45 const gchar ** gtk_widget_list_action_prefixes (GtkWidget *widget);
48 (defconst gnome-c-test-program-3 "\
49 /* overridable methods */
50 void (*set_property) (GObject *object,
54 void (*get_property) (GObject *object,
60 (defconst gnome-c-test-program-4 "\
62 int foo (struct foo ***a, int b, ...) G_GNUC_CONST;
65 (defconst gnome-c-test-program-4-aligned "\
67 int foo (struct foo ***a,
72 (defconst gnome-c-test-program-5 "\
73 int * bar (const char * const * * a, int b);
76 (defconst gnome-c-test-program-5-aligned "\
77 int *bar (const char * const **a,
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);
87 (defconst gnome-c-test-program-6-aligned-1 "\
94 int identifier_1234567890
99 (defconst gnome-c-test-program-6-aligned-2 "\
102 type_1234567890 bar (char a,
104 int identifier_1234567890
109 (ert-deftest gnome-c-test-align--guess-optimal-columns ()
110 "Tests the `gnome-c-align--guess-optimal-columns'."
112 (insert gnome-c-test-program-1)
114 (let* (gnome-c-align-max-column
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)))))
121 (ert-deftest gnome-c-test-align-region ()
122 "Tests the `gnome-c-align-decls-region'."
124 (insert gnome-c-test-program-1)
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))))
131 (ert-deftest gnome-c-test-align-region-2 ()
132 "Tests the `gnome-c-align-decls-region'."
134 (insert gnome-c-test-program-4)
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))))
141 (ert-deftest gnome-c-test-align-region-3 ()
142 "Tests the `gnome-c-align-decls-region'."
144 (insert gnome-c-test-program-5)
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))))
151 (ert-deftest gnome-c-test-align-region-4 ()
152 "Tests the `gnome-c-align-decls-region', with max columns set."
154 (insert gnome-c-test-program-6)
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))))
161 (ert-deftest gnome-c-test-align-region-5 ()
162 "Tests the `gnome-c-align-decls-region', with max columns set."
164 (insert gnome-c-test-program-6)
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))))
171 (ert-deftest gnome-c-test-align-guess-columns-1 ()
172 "Tests the `gnome-c-align-guess-columns'."
174 (insert gnome-c-test-program-2)
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))))
182 (ert-deftest gnome-c-test-align-guess-columns-2 ()
183 "Tests the `gnome-c-align-guess-columns'."
185 (insert gnome-c-test-program-3)
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))))