Test stuff
This commit is contained in:
118
src/test/tests.cpp
Normal file
118
src/test/tests.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
String TestDir;
|
||||
|
||||
void AddCtrlPress(SDL_Keycode key) {
|
||||
Event event = {};
|
||||
event.key = key;
|
||||
event.ctrl = 1;
|
||||
event.xwindow = 1280;
|
||||
event.ywindow = 720;
|
||||
Add(&EventPlayback, event);
|
||||
}
|
||||
|
||||
void AddText(String string) {
|
||||
Event event = {};
|
||||
event.kind = EVENT_TEXT_INPUT;
|
||||
event.xwindow = 1280;
|
||||
event.ywindow = 720;
|
||||
event.text = Copy(Perm, string).data;
|
||||
Add(&EventPlayback, event);
|
||||
}
|
||||
|
||||
void Wait(mco_coro *co) {
|
||||
Add(&EventPlayback, {111});
|
||||
for (Event *event = Yield(co); event->kind != 111; event = Yield(co)) {
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTestOpen(mco_coro *co) {
|
||||
// Open file, move a little, then open again and verify the caret didn't move
|
||||
String basic_env_cpp = Format(Perm, "%.*s/basic_env/basic_env.cpp", FmtString(TestDir));
|
||||
|
||||
AddCtrlPress(SDLK_P);
|
||||
Add(&EventPlayback, {EVENT_KEY_PRESS, SDLK_UP, 1280, 720});
|
||||
AddCtrlPress(SDLK_Q);
|
||||
Wait(co);
|
||||
|
||||
{
|
||||
BSet main = GetActiveMainSet();
|
||||
Assert(main.buffer->name == basic_env_cpp);
|
||||
Assert(main.view->carets[0].range.min == 0);
|
||||
Assert(main.view->carets[0].range.max == 0);
|
||||
Int line = PosToLine(main.buffer, main.view->carets[0].range.min);
|
||||
Assert(line == 0);
|
||||
}
|
||||
|
||||
AddCtrlPress(SDLK_DOWN);
|
||||
AddCtrlPress(SDLK_DOWN);
|
||||
AddCtrlPress(SDLK_DOWN);
|
||||
Wait(co);
|
||||
|
||||
Range range = {};
|
||||
{
|
||||
BSet main = GetActiveMainSet();
|
||||
Assert(main.view->carets[0].range.min > 0);
|
||||
Assert(main.view->carets[0].range.max > 0);
|
||||
range = main.view->carets[0].range;
|
||||
}
|
||||
|
||||
AddCtrlPress(SDLK_P);
|
||||
Add(&EventPlayback, {EVENT_KEY_PRESS, SDLK_UP, 1280, 720});
|
||||
AddCtrlPress(SDLK_Q);
|
||||
Wait(co);
|
||||
|
||||
Int buffer_len = 0;
|
||||
{
|
||||
BSet main = GetActiveMainSet();
|
||||
Assert(main.buffer->name == basic_env_cpp);
|
||||
Assert(main.view->carets[0].range.min == range.min);
|
||||
Assert(main.view->carets[0].range.max == range.max);
|
||||
buffer_len = main.buffer->len;
|
||||
}
|
||||
|
||||
AddText(Format(Perm, "%.*s:20", FmtString(basic_env_cpp)));
|
||||
AddCtrlPress(SDLK_Q);
|
||||
Wait(co);
|
||||
|
||||
{
|
||||
BSet main = GetActiveMainSet();
|
||||
Int pos = main.view->carets[0].range.min;
|
||||
Int line = PosToLine(main.buffer, pos);
|
||||
Assert(line == 19);
|
||||
Assert(main.buffer->name == basic_env_cpp);
|
||||
Assert(main.buffer->len != buffer_len);
|
||||
Assert(main.buffer->dirty);
|
||||
}
|
||||
|
||||
AddCtrlPress(SDLK_Z);
|
||||
AddCtrlPress(SDLK_PAGEUP);
|
||||
Wait(co);
|
||||
|
||||
{
|
||||
BSet main = GetActiveMainSet();
|
||||
Assert(main.buffer->len == buffer_len);
|
||||
Assert(main.view->carets[0].range.min == 0);
|
||||
Assert(main.view->carets[0].range.max == 0);
|
||||
}
|
||||
ReportConsolef(__FUNCTION__ " DONE");
|
||||
|
||||
}
|
||||
|
||||
void Test(mco_coro *co) {
|
||||
WorkDir = Format(Perm, "%.*s/basic_env", FmtString(TestDir));
|
||||
PlayTestOpen(co);
|
||||
|
||||
|
||||
|
||||
// Add(&EventPlayback, {EVENT_QUIT});
|
||||
}
|
||||
|
||||
void InitTests() {
|
||||
StyleWaitForEvents = false;
|
||||
{
|
||||
String file = __FILE__;
|
||||
file = NormalizePath(Perm, file);
|
||||
file = ChopLastSlash(file);
|
||||
TestDir = file;
|
||||
}
|
||||
AddCo(Test);
|
||||
}
|
||||
Reference in New Issue
Block a user