-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathbuflist.c
83 lines (64 loc) · 1.93 KB
/
buflist.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
#include "libvim.h"
#include "minunit.h"
void test_setup(void)
{
vimExecute("e!");
vimInput("g");
vimInput("g");
}
void test_teardown(void) {}
MU_TEST(buflist_get_id)
{
buf_T *current = vimBufferGetCurrent();
int currentId = vimBufferGetId(current);
mu_check(vimBufferGetById(currentId) == current);
}
MU_TEST(buffer_open)
{
buf_T *buf = vimBufferOpen("collateral/curswant.txt", 1, 0);
long lines = vimBufferGetLineCount(buf);
mu_check(lines == 4);
}
MU_TEST(buffer_load_nonexistent_file)
{
buf_T *buf = vimBufferLoad("a-non-existent-file.txt", 1, 0);
long lines = vimBufferGetLineCount(buf);
mu_check(lines == 1);
}
MU_TEST(buffer_load_does_not_change_current)
{
buf_T *bufOpen = vimBufferOpen("collateral/curswant.txt", 1, 0);
buf_T *bufLoaded = vimBufferLoad("a-non-existent-file.txt", 1, 0);
long loadedLines = vimBufferGetLineCount(bufLoaded);
mu_check(loadedLines == 1);
long openLines = vimBufferGetLineCount(bufOpen);
mu_check(openLines == 4);
buf_T *currentBuf = vimBufferGetCurrent();
mu_check(currentBuf == bufOpen);
}
MU_TEST(buffer_load_read_lines)
{
buf_T *bufLoaded = vimBufferLoad("collateral/testfile.txt", 1, 0);
mu_check(strcmp(vimBufferGetLine(bufLoaded, 1), "This is the first line of a test file") == 0);
mu_check(strcmp(vimBufferGetLine(bufLoaded, 2), "This is the second line of a test file") == 0);
mu_check(strcmp(vimBufferGetLine(bufLoaded, 3), "This is the third line of a test file") == 0);
}
MU_TEST_SUITE(test_suite)
{
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
MU_RUN_TEST(buflist_get_id);
MU_RUN_TEST(buffer_open);
MU_RUN_TEST(buffer_load_nonexistent_file);
MU_RUN_TEST(buffer_load_does_not_change_current);
MU_RUN_TEST(buffer_load_read_lines);
}
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();
}