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 (ert-deftest gnome-c-test-align--compute-optimal-columns ()
82 "Tests the `gnome-c-align--compute-optimal-columns'."
84 (insert gnome-c-test-program-1)
86 (let* (gnome-c-align-max-column
88 (gnome-c-align--compute-optimal-columns (point-min) (point-max))))
89 (should (= (cdr (assq 'identifier-start-column columns)) 9))
90 (should (= (cdr (assq 'arglist-start-column columns)) 41))
91 (should (= (cdr (assq 'arglist-identifier-start-column columns)) 64)))))
93 (ert-deftest gnome-c-test-align-region ()
94 "Tests the `gnome-c-align-region'."
96 (insert gnome-c-test-program-1)
98 (let (gnome-c-align-max-column)
99 (gnome-c-align-compute-optimal-columns (point-min) (point-max))
100 (gnome-c-align-region (point-min) (point-max)))
101 (should (equal (buffer-string) gnome-c-test-program-1-aligned))))
103 (ert-deftest gnome-c-test-align-region-2 ()
104 "Tests the `gnome-c-align-region'."
106 (insert gnome-c-test-program-4)
108 (let (gnome-c-align-max-column)
109 (gnome-c-align-compute-optimal-columns (point-min) (point-max))
110 (gnome-c-align-region (point-min) (point-max)))
111 (should (equal (buffer-string) gnome-c-test-program-4-aligned))))
113 (ert-deftest gnome-c-test-align-region-3 ()
114 "Tests the `gnome-c-align-region'."
116 (insert gnome-c-test-program-5)
118 (let (gnome-c-align-max-column)
119 (gnome-c-align-compute-optimal-columns (point-min) (point-max))
120 (gnome-c-align-region (point-min) (point-max)))
121 (should (equal (buffer-string) gnome-c-test-program-5-aligned))))
123 (ert-deftest gnome-c-test-align-guess-columns-1 ()
124 "Tests the `gnome-c-align-guess-columns'."
126 (insert gnome-c-test-program-2)
128 (let (gnome-c-align-max-column)
129 (gnome-c-align-guess-columns (point-min) (point-max)))
130 (should (= gnome-c-align-identifier-start-column 24))
131 (should (= gnome-c-align-arglist-start-column 56))
132 (should (= gnome-c-align-arglist-identifier-start-column 80))))
134 (ert-deftest gnome-c-test-align-guess-columns-2 ()
135 "Tests the `gnome-c-align-guess-columns'."
137 (insert gnome-c-test-program-3)
139 (let (gnome-c-align-max-column)
140 (gnome-c-align-guess-columns (point-min) (point-max)))
141 (should (= gnome-c-align-identifier-start-column 13))
142 (should (= gnome-c-align-arglist-start-column 40))
143 (should (= gnome-c-align-arglist-identifier-start-column 57))))