wip
This commit is contained in:
4
edit.jai
4
edit.jai
@@ -245,7 +245,7 @@ handle_arrow :: (state: *State, key_code: Input.Key_Code) {
|
|||||||
|
|
||||||
handle_arrow :: (using state: *State, using event: Input.Event) {
|
handle_arrow :: (using state: *State, using event: Input.Event) {
|
||||||
visible_lines := get_visible_lines(state);
|
visible_lines := get_visible_lines(state);
|
||||||
|
if visible_lines.count == 0 return;
|
||||||
|
|
||||||
if key_code == {
|
if key_code == {
|
||||||
case .ARROW_UP;
|
case .ARROW_UP;
|
||||||
@@ -259,6 +259,7 @@ handle_arrow :: (using state: *State, using event: Input.Event) {
|
|||||||
case .ARROW_DOWN;
|
case .ARROW_DOWN;
|
||||||
if cursor_y == visible_lines.count - 1 {
|
if cursor_y == visible_lines.count - 1 {
|
||||||
first_line = min(first_line + 1, lines.count);
|
first_line = min(first_line + 1, lines.count);
|
||||||
|
} else if cursor_y + first_line + visible_lines.count >= lines.count {
|
||||||
} else {
|
} else {
|
||||||
cursor_y += 1;
|
cursor_y += 1;
|
||||||
}
|
}
|
||||||
@@ -287,6 +288,7 @@ handle_arrow :: (using state: *State, using event: Input.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_visible_lines :: (using state: State) -> [][..]u8 {
|
get_visible_lines :: (using state: State) -> [][..]u8 {
|
||||||
|
if line_height <= 1 || window_height == 0 return .[];
|
||||||
num_lines_in_screen := window_height / line_height - 1;
|
num_lines_in_screen := window_height / line_height - 1;
|
||||||
return array_view(lines, first_line, num_lines_in_screen);
|
return array_view(lines, first_line, num_lines_in_screen);
|
||||||
}
|
}
|
||||||
|
|||||||
70
test.jai
70
test.jai
@@ -1,5 +1,73 @@
|
|||||||
main :: () {
|
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 "Basic";
|
||||||
|
#import "Compiler";
|
||||||
|
#import "Program_Print";
|
||||||
|
|||||||
Reference in New Issue
Block a user