Something went wrong. Try again.
minimal agent cli memoria.tools
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153package input
import "../theme"import "core:fmt"import "core:strings"import "core:testing"
@(test)resize_cursor_climb_tracks_old_painted_rows :: proc(t: ^testing.T) { state := State{width = 9} // Seven content cells; ten terminal columns. defer destroy(&state) testing.expect(t, replace(&state, transmute([]byte)string("abcdefgHI"))) sb := strings.builder_make() defer strings.builder_destroy(&sb) draw(&sb, &state, 0, 0, false, false, "") testing.expect_value(t, state.cursor_row, 1) testing.expect_value(t, reflow_cursor_climb(&state, state.cursor_row, int(state.cursor) + 2, 5), 2) // Even an empty prompt cursor stays on the first row after shrinking. testing.expect(t, replace(&state, nil)) strings.builder_reset(&sb) draw(&sb, &state, 0, 0, false, false, "") testing.expect_value(t, reflow_cursor_climb(&state, state.cursor_row, int(state.cursor) + 2, 5), 0)}
@(test)ascii_exact_wrap_has_empty_final_row :: proc(t: ^testing.T) { state := State{width = 6} // Four content columns. defer destroy(&state) testing.expect(t, replace(&state, transmute([]byte)string("abcd"))) testing.expect_value(t, row_count(&state), 2) sb := strings.builder_make() defer strings.builder_destroy(&sb) draw(&sb, &state, 0, 0, false, false, "") marker := theme.DEFAULT.marker + "┃ " + theme.DEFAULT.text testing.expect_value(t, strings.count(strings.to_string(sb), marker), 2) testing.expect_value(t, state.cursor_row, 1) testing.expect_value(t, state.cursor, uint(0))
// Shrinking the prompt removes the stale row below the status line. delete_before_cursor(&state) testing.expect_value(t, row_count(&state), 1) strings.builder_reset(&sb) draw(&sb, &state, 2, 0, false, false, "") testing.expect(t, strings.contains(strings.to_string(sb), "\x1b[1B\r\x1b[1M\x1b[1A\r")) testing.expect_value(t, state.cursor_row, 0) testing.expect_value(t, state.cursor, uint(3))
// Growing across the boundary restores the extra row. insert_byte(&state, 'd') testing.expect_value(t, row_count(&state), 2) strings.builder_reset(&sb) draw(&sb, &state, 1, 0, false, false, "") testing.expect_value(t, strings.count(strings.to_string(sb), marker), 2) testing.expect_value(t, state.cursor_row, 1)
// An explicit newline immediately after an exact wrap creates another row. insert_byte(&state, '\n') testing.expect_value(t, row_count(&state), 3) strings.builder_reset(&sb) draw(&sb, &state, 2, 0, false, false, "") testing.expect_value(t, strings.count(strings.to_string(sb), marker), 3) testing.expect_value(t, state.cursor_row, 2)}
@(test)wide_rune_wraps_by_display_cells_not_utf8_bytes :: proc(t: ^testing.T) { state := State{width = 6} defer destroy(&state) testing.expect(t, replace(&state, transmute([]byte)string("ab界c"))) testing.expect_value(t, row_count(&state), 2) sb := strings.builder_make() defer strings.builder_destroy(&sb) draw(&sb, &state, 0, 0, false, false, "") marker := theme.DEFAULT.marker + "┃ " + theme.DEFAULT.text expected := fmt.aprintf("%sab界\n\x1b[2K%sc\n", marker, marker) defer delete(expected) testing.expect(t, strings.contains(strings.to_string(sb), expected)) testing.expect_value(t, state.cursor_row, 1) testing.expect_value(t, state.cursor, uint(1))
// A wide rune that cannot fit at the end moves to the next row. testing.expect(t, replace(&state, transmute([]byte)string("abc界"))) testing.expect_value(t, row_count(&state), 2) strings.builder_reset(&sb) draw(&sb, &state, 0, 0, false, false, "") expected_second := fmt.aprintf("%sabc\n\x1b[2K%s界\n", marker, marker) defer delete(expected_second) testing.expect(t, strings.contains(strings.to_string(sb), expected_second)) testing.expect_value(t, state.cursor_row, 1) testing.expect_value(t, state.cursor, uint(2))}
@(test)tabs_and_newlines_follow_the_same_layout_as_draw :: proc(t: ^testing.T) { state := State{width = 6} defer destroy(&state) testing.expect(t, replace(&state, transmute([]byte)string("x\ty\nz"))) testing.expect_value(t, row_count(&state), 4) sb := strings.builder_make() defer strings.builder_destroy(&sb) draw(&sb, &state, 0, 0, false, false, "") marker := theme.DEFAULT.marker + "┃ " + theme.DEFAULT.text output := strings.to_string(sb) // The tab is four cells: after 'x' it wraps and fills the second row. expected := fmt.aprintf("%sx\n\x1b[2K%s \n\x1b[2K%sy\n\x1b[2K%sz\n", marker, marker, marker, marker) defer delete(expected) testing.expect(t, strings.contains(output, expected)) testing.expect_value(t, state.cursor_row, 3) testing.expect_value(t, state.cursor, uint(1))}
@(test)queued_banner_is_one_row_and_safe_for_multiline_and_resize :: proc(t: ^testing.T) { state := State{width = 12} defer destroy(&state) sb := strings.builder_make() defer strings.builder_destroy(&sb) draw(&sb, &state, 0, 0, false, false, "", "a\nb\x1b[31m") output := strings.to_string(sb) testing.expect(t, strings.contains(output, theme.DEFAULT.text + "Queued")) testing.expect(t, !strings.contains(output, theme.DEFAULT.muted + "Queued")) // The cursor must return to the input row, not the queued banner. Otherwise // each loading tick repaints the banner as input and pushes status down. testing.expect(t, strings.has_suffix(output, "\x1b[1A\x1b[3G")) testing.expect(t, !strings.contains(output, "a\nb")) testing.expect_value(t, queued_painted_width("a\nb", 12), 11) testing.expect_value(t, queued_painted_width("a\nb", 50), len("Queued: ") + 3)}
@(test)slash_completion_draws_skills_after_builtins_with_selection :: proc(t: ^testing.T) { state := State{width = 80} defer destroy(&state) add_skill_command(&state, "mitos") add_skill_command(&state, "models") testing.expect(t, replace(&state, transmute([]byte)string("/"))) testing.expect_value(t, autocomplete_rows(&state), len(COMMANDS) + 1) select_previous(&state) sb := strings.builder_make() defer strings.builder_destroy(&sb) draw(&sb, &state, 0, 0, false, false, "") output := strings.to_string(sb) testing.expect_value(t, strings.count(output, COMMAND_MODELS), 1) testing.expect(t, strings.contains(output, "\r\n\x1b[2K" + theme.DEFAULT.selection + "/mitos" + theme.DEFAULT.reset)) testing.expect(t, strings.index(output, COMMAND_VARIANTS) < strings.index(output, "/mitos")) testing.expect(t, replace(&state, transmute([]byte)string("/mit"))) strings.builder_reset(&sb) draw(&sb, &state, 0, 0, false, false, "") output = strings.to_string(sb) testing.expect(t, strings.contains(output, theme.DEFAULT.selection + "/mitos")) testing.expect(t, !strings.contains(output, COMMAND_MODELS))}