]> code.delx.au - gnu-emacs-elpa/blob - gnome-c-tests.el
59ae8ee7a7d46fa591cd634eded7941437c595a9
[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 (ert-deftest gnome-c-test-align--guess-optimal-columns ()
82 "Tests the `gnome-c-align--guess-optimal-columns'."
83 (with-temp-buffer
84 (insert gnome-c-test-program-1)
85 (c-mode)
86 (let* (gnome-c-align-max-column
87 (columns
88 (gnome-c-align--guess-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)))))
92
93 (ert-deftest gnome-c-test-align-region ()
94 "Tests the `gnome-c-align-decls-region'."
95 (with-temp-buffer
96 (insert gnome-c-test-program-1)
97 (c-mode)
98 (let (gnome-c-align-max-column)
99 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
100 (gnome-c-align-decls-region (point-min) (point-max)))
101 (should (equal (buffer-string) gnome-c-test-program-1-aligned))))
102
103 (ert-deftest gnome-c-test-align-region-2 ()
104 "Tests the `gnome-c-align-decls-region'."
105 (with-temp-buffer
106 (insert gnome-c-test-program-4)
107 (c-mode)
108 (let (gnome-c-align-max-column)
109 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
110 (gnome-c-align-decls-region (point-min) (point-max)))
111 (should (equal (buffer-string) gnome-c-test-program-4-aligned))))
112
113 (ert-deftest gnome-c-test-align-region-3 ()
114 "Tests the `gnome-c-align-decls-region'."
115 (with-temp-buffer
116 (insert gnome-c-test-program-5)
117 (c-mode)
118 (let (gnome-c-align-max-column)
119 (gnome-c-align-guess-optimal-columns (point-min) (point-max))
120 (gnome-c-align-decls-region (point-min) (point-max)))
121 (should (equal (buffer-string) gnome-c-test-program-5-aligned))))
122
123 (ert-deftest gnome-c-test-align-guess-columns-1 ()
124 "Tests the `gnome-c-align-guess-columns'."
125 (with-temp-buffer
126 (insert gnome-c-test-program-2)
127 (c-mode)
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))))
133
134 (ert-deftest gnome-c-test-align-guess-columns-2 ()
135 "Tests the `gnome-c-align-guess-columns'."
136 (with-temp-buffer
137 (insert gnome-c-test-program-3)
138 (c-mode)
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))))