Files
editor/test.jai
2026-05-10 08:47:25 -04:00

85 lines
2.3 KiB
Plaintext

main :: () {
print("\nBeginning tests...\n");
//test_get_visible_lines();
//test_handle_arrow_empty_lines();
test_handle_arrow_one_line();
print("Tests completed successfully\n");
}
test_get_visible_lines :: () {
state: State;
state.line_height = 10;
state.window_height = 100;
assert_test(get_visible_lines(state).count == 0);
line: [..]u8;
array_add(*line, array_view("foo"));
array_add(*state.lines, line);
assert_test(get_visible_lines(state).count == 1);
print("test_get_visible_lines completed successfully\n");
}
test_handle_arrow_empty_lines :: () {
state: State;
state.cursor_y = 0;
state.cursor_x = 0;
codes := Input.Key_Code.[.ARROW_DOWN, .ARROW_UP, .ARROW_LEFT, .ARROW_RIGHT];
for codes {
handle_arrow(*state, .{key_code=it});
assert(state.cursor_x == 0 && state.cursor_y == 0, "%: cursor_x % & cursor_y %", it, state.cursor_x, state.cursor_y);
}
print("test_handle_arrow_empty_lines completed successfully\n");
}
test_handle_arrow_one_line :: () {
state: State;
state.first_line = 0;
state.cursor_y = 0;
state.cursor_x = 0;
state.line_height = 10;
state.window_height = 100;
add_line(*state, "foo bar");
codes := Input.Key_Code.[.ARROW_DOWN, .ARROW_UP, .ARROW_LEFT];
for codes {
handle_arrow(*state, .{key_code=it});
assert(state.cursor_x == 0 && state.cursor_y == 0);
}
print("lines: %\n", state.lines);
print("visible_lines: %\n", get_visible_lines(state));
handle_arrow(*state, .ARROW_RIGHT);
assert_test(state.cursor_x == 1 && state.cursor_y == 0);
print("test_handle_arrow_one_line completed successfully\n");
}
assert_test :: (value: bool, $call := #caller_code, loc := #caller_location) {
if value == true return;
assert(false, "%\nValue is false.", #run get_expression(call), value, loc = loc);
}
get_expression :: (call := #caller_code) -> string {
root := compiler_get_nodes(call);
builder: String_Builder;
print_expression(*builder, root);
return builder_to_string(*builder);
};
#scope_file
add_line :: (using state: *State, line: string) {
line_dyn: [..]u8;
array_add(*line_dyn, array_view(line));
array_add(*state.lines, line_dyn);
}
#import,file "edit.jai";
#import "Basic";
#import "Compiler";
#import "Program_Print";