This commit is contained in:
2026-04-27 18:46:28 -04:00
parent 8eaed029ea
commit e755d1d89c
2 changed files with 73 additions and 3 deletions

View File

@@ -1,5 +1,73 @@
main :: () {
print("\nBeginning tests...\n");
// test_handle_arrow_empty_lines();
// test_handle_arrow_one_line();
x := 1;
y := 2;
assert_test(x == y);
}
#load "edit.jai";
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.cursor_y = 0;
state.cursor_x = 0;
line: [..]u8;
line_str := "foo bar";
array_add(*line, .{data=line_str.data, count=line_str.count});
array_add(*state.lines, line);
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);
}
handle_arrow(*state, .{key_code=.ARROW_RIGHT});
assert(state.cursor_x == 1 && state.cursor_y == 0);
print("test_handle_arrow_one_line completed successfully\n");
}
assert_test :: (value: bool, $code := #caller_code) {
builder: String_Builder;
root, expressions := compiler_get_nodes(code);
loc := #location(code);
print_to_builder(*builder, "%:%: Test: ", loc.fully_pathed_filename, loc.line_number);
print_expression(*builder, root);
append(*builder, "\n");
`result := #insert code;
if !result {
for expressions {
if it == root continue;
print_expression(*builder, it);
append(*builder, "\n");
}
append(*builder, "\n");
`expression := builder_to_string(*builder);
`print("%\n", expression);
} else {
`print("Passed!\n");
}
}
#import,file "edit.jai";
#import "Basic";
#import "Compiler";
#import "Program_Print";