]> code.delx.au - gnu-emacs-elpa/blob - gnome-tests.el
align: Reimplement d6086809
[gnu-emacs-elpa] / gnome-tests.el
1 (require 'gnome-align)
2
3 (defconst gnome-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-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-test-program-2 "\
44 GDK_AVAILABLE_IN_3_16
45 const gchar ** gtk_widget_list_action_prefixes (GtkWidget *widget);
46 ")
47
48 (defconst gnome-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-test-program-4 "\
61 FOO_AVAILABLE_IN_ALL
62 int foo (struct foo ***a, int b, ...) G_GNUC_CONST;
63 ")
64
65 (defconst gnome-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 (ert-deftest gnome-test-align--compute-optimal-columns ()
73 "Tests the `gnome-align--compute-optimal-columns'."
74 (with-temp-buffer
75 (insert gnome-test-program-1)
76 (c-mode)
77 (let ((columns (gnome-align--compute-optimal-columns (point-min) (point-max))))
78 (should (= (cdr (assq 'identifier-start-column columns)) 9))
79 (should (= (cdr (assq 'arglist-start-column columns)) 41))
80 (should (= (cdr (assq 'arglist-identifier-start-column columns)) 64)))))
81
82 (ert-deftest gnome-test-align-region ()
83 "Tests the `gnome-align-region'."
84 (with-temp-buffer
85 (insert gnome-test-program-1)
86 (c-mode)
87 (gnome-align-compute-optimal-columns (point-min) (point-max))
88 (gnome-align-region (point-min) (point-max))
89 (should (equal (buffer-string) gnome-test-program-1-aligned))))
90
91 (ert-deftest gnome-test-align-region-2 ()
92 "Tests the `gnome-align-region'."
93 (with-temp-buffer
94 (insert gnome-test-program-4)
95 (c-mode)
96 (gnome-align-compute-optimal-columns (point-min) (point-max))
97 (gnome-align-region (point-min) (point-max))
98 (should (equal (buffer-string) gnome-test-program-4-aligned))))
99
100 (ert-deftest gnome-test-align-guess-columns-1 ()
101 "Tests the `gnome-align-guess-columns'."
102 (with-temp-buffer
103 (insert gnome-test-program-2)
104 (c-mode)
105 (gnome-align-guess-columns (point-min) (point-max))
106 (should (= gnome-align-identifier-start-column 24))
107 (should (= gnome-align-arglist-start-column 56))
108 (should (= gnome-align-arglist-identifier-start-column 80))))
109
110 (ert-deftest gnome-test-align-guess-columns-2 ()
111 "Tests the `gnome-align-guess-columns'."
112 (with-temp-buffer
113 (insert gnome-test-program-3)
114 (c-mode)
115 (gnome-align-guess-columns (point-min) (point-max))
116 (should (= gnome-align-identifier-start-column 13))
117 (should (= gnome-align-arglist-start-column 40))
118 (should (= gnome-align-arglist-identifier-start-column 57))))