-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcolors.c
172 lines (135 loc) · 3.72 KB
/
colors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "libvim.h"
#include "minunit.h"
static int colorSchemeChangedCount = 0;
static char_u *lastColorScheme = NULL;
int onColorSchemeChanged(char_u *colorScheme)
{
colorSchemeChangedCount++;
if (lastColorScheme != NULL)
{
vim_free(lastColorScheme);
}
lastColorScheme = NULL;
if (colorScheme != NULL)
{
lastColorScheme = vim_strsave(colorScheme);
}
return OK;
};
char_u *acopy(char_u *str)
{
char_u *sz = malloc(sizeof(char_u) * (strlen(str) + 1));
strcpy(sz, str);
sz[strlen(str)] = 0;
return sz;
};
int onColorSchemeCompletion(char_u *pat, int *numSchemes, char_u ***schemes)
{
*numSchemes = 3;
*schemes = ALLOC_MULT(char_u *, 3);
(*schemes)[0] = acopy("scheme1");
(*schemes)[1] = acopy("scheme2");
(*schemes)[2] = acopy("scheme3");
return OK;
}
void test_setup(void)
{
vimColorSchemeSetChangedCallback(&onColorSchemeChanged);
vimColorSchemeSetCompletionCallback(&onColorSchemeCompletion);
if (lastColorScheme != NULL)
{
vim_free(lastColorScheme);
lastColorScheme = NULL;
}
lastColorScheme = NULL;
colorSchemeChangedCount = 0;
// Reset formatexpr, formatprg, and equalprg to defaults
vimKey("<esc>");
vimKey("<esc>");
vimExecute("e!");
vimInput("g");
vimInput("g");
vimInput("0");
}
void test_teardown(void)
{
if (lastColorScheme != NULL)
{
vim_free(lastColorScheme);
lastColorScheme = NULL;
}
}
MU_TEST(test_colorscheme_changed)
{
vimExecute("colorscheme test");
mu_check(colorSchemeChangedCount == 1);
mu_check(strcmp(lastColorScheme, "test") == 0);
vimExecute("colorscheme Multi Word Scheme");
mu_check(colorSchemeChangedCount == 2);
mu_check(strcmp(lastColorScheme, "Multi Word Scheme") == 0);
vimExecute("colorscheme");
mu_check(colorSchemeChangedCount == 3);
mu_check(lastColorScheme == NULL);
}
MU_TEST(test_colorscheme_changed_no_callback)
{
vimColorSchemeSetChangedCallback(NULL);
vimExecute("colorscheme test");
mu_check(colorSchemeChangedCount == 0);
vimExecute("colorscheme");
mu_check(colorSchemeChangedCount == 0);
}
MU_TEST(test_colorscheme_get_completions)
{
char_u *pat;
expand_T xpc;
ExpandInit(&xpc);
xpc.xp_pattern = "";
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
xpc.xp_context = EXPAND_COLORS;
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
mu_check(pat != NULL);
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH | WILD_NO_BEEP;
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
mu_check(xpc.xp_numfiles == 3);
mu_check(strcmp(xpc.xp_files[0], "scheme1") == 0);
mu_check(strcmp(xpc.xp_files[1], "scheme2") == 0);
mu_check(strcmp(xpc.xp_files[2], "scheme3") == 0);
vim_free(pat);
ExpandCleanup(&xpc);
}
MU_TEST(test_colorscheme_get_completions_no_provider)
{
vimColorSchemeSetCompletionCallback(NULL);
char_u *pat;
expand_T xpc;
ExpandInit(&xpc);
xpc.xp_pattern = "";
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
xpc.xp_context = EXPAND_COLORS;
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
mu_check(pat != NULL);
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH | WILD_NO_BEEP;
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
mu_check(xpc.xp_numfiles == 0);
vim_free(pat);
ExpandCleanup(&xpc);
}
MU_TEST_SUITE(test_suite)
{
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
MU_RUN_TEST(test_colorscheme_changed);
MU_RUN_TEST(test_colorscheme_changed_no_callback);
MU_RUN_TEST(test_colorscheme_get_completions);
MU_RUN_TEST(test_colorscheme_get_completions_no_provider);
}
int main(int argc, char **argv)
{
vimInit(argc, argv);
win_setwidth(5);
win_setheight(100);
vimBufferOpen("collateral/testfile.txt", 1, 0);
MU_RUN_SUITE(test_suite);
MU_REPORT();
MU_RETURN();
}