Something went wrong. Try again.
minimal agent cli memoria.tools
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246package input
// render tests per RENDERING.md. States are filled directly since edit.odin// (typing) is not implemented yet.
import "../term"import "../theme"import "core:strings"import "core:testing"
fill :: proc(state: ^State, content: string) { append_elems(&state.bytes, ..transmute([]u8)content)}
// The erase-line prefix each painted row carries (term.clear_line): a// repaint must clear the previous frame's content first.CL :: "\r\x1b[2K"
// The SGR span render paints the marker in — theme.DEFAULT's marker,// #7aa2f7 — and the reset that closes it before the row content.MARKER_ON :: "\x1b[38;2;122;162;247m"MARKER_OFF :: "\x1b[0m"
// expect_render renders the state and checks the output text and row count.// to_string borrows the builder buffer, so the comparisons happen before// builder_destroy runs.expect_render :: proc(t: ^testing.T, state: State, width: int, want: string, want_rows: int) { sb := strings.builder_make() defer strings.builder_destroy(&sb)
layout := render(state, &sb, width, theme.DEFAULT)
testing.expect_value(t, strings.to_string(sb), want) testing.expect_value(t, layout.rows, want_rows)}
// expect_cursor renders the state and checks the edit cursor's visual// position (Layout.cursor_row / cursor_column, both 0-based).expect_cursor :: proc(t: ^testing.T, state: State, width: int, want_row: int, want_column: int) { sb := strings.builder_make() defer strings.builder_destroy(&sb)
layout := render(state, &sb, width, theme.DEFAULT)
testing.expect_value(t, layout.cursor_row, want_row) testing.expect_value(t, layout.cursor_column, want_column)}
@(test)test_render_masks_key_entry :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "sk-abc")
sb := strings.builder_make() defer strings.builder_destroy(&sb) layout := render(state, &sb, 80, theme.DEFAULT, true)
testing.expect_value( t, strings.to_string(sb), CL + MARKER_ON + "┃ " + MARKER_OFF + "******", ) testing.expect_value(t, layout.rows, 1)}
@(test)test_render_empty_input :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state)
expect_render(t, state, 80, CL + MARKER_ON + "┃ " + MARKER_OFF, 1)}
@(test)test_render_single_line :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello")
expect_render(t, state, 80, CL + MARKER_ON + "┃ " + MARKER_OFF + "hello", 1)}
@(test)test_render_newline_starts_marker_row :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello\nworld")
expect_render(t, state, 80, CL + MARKER_ON + "┃ " + MARKER_OFF + "hello\r\n" + CL + MARKER_ON + "┃ " + MARKER_OFF + "world", 2)}
@(test)test_render_trailing_newline_adds_empty_row :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello\n")
expect_render(t, state, 80, CL + MARKER_ON + "┃ " + MARKER_OFF + "hello\r\n" + CL + MARKER_ON + "┃ " + MARKER_OFF, 2)}
@(test)test_render_wraps_with_marker_per_row :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello") // width 6 → content_width 4 → "hell" / "o"
expect_render(t, state, 6, CL + MARKER_ON + "┃ " + MARKER_OFF + "hell\r\n" + CL + MARKER_ON + "┃ " + MARKER_OFF + "o", 2)}
@(test)test_render_wide_rune_never_split :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "你好") // each rune is 2 cells; width 5 → content_width 3
expect_render(t, state, 5, CL + MARKER_ON + "┃ " + MARKER_OFF + "你\r\n" + CL + MARKER_ON + "┃ " + MARKER_OFF + "好", 2)}
@(test)test_render_tab_expands_to_spaces :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "a\tb")
expect_render(t, state, 80, CL + MARKER_ON + "┃ " + MARKER_OFF + "a b", 1)}
@(test)test_render_malformed_utf8_renders_space :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) append(&state.bytes, 0xFF) // invalid UTF-8 byte
// marker + space + replacement space expect_render(t, state, 80, CL + MARKER_ON + "┃ " + MARKER_OFF + " ", 1)}
@(test)test_render_control_bytes_paint_as_spaces :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "a\r\x1bb") // control bytes only a paste can deliver state.position = 4
// Controls paint as one space (a raw control byte would drive the // terminal) and measure one cell — the cursor column counts them. expect_render(t, state, 80, CL + MARKER_ON + "┃ " + MARKER_OFF + "a b", 1) expect_cursor(t, state, 80, 0, MARKER_WIDTH + 4)}
@(test)test_render_prefix_erases_previous_frame :: proc(t: ^testing.T) { // The bug this prefix prevents: frame paints "┃ abc", the prompt // shrinks, the next frame paints "┃ a" — without the erase-line // prefix the stale "bc" would survive and the screen would read // "┃ abc" → "┃ abc" (stale tail appended). Every row starts with // clear_line so each repaint starts from an empty row. state := state_make() defer state_destroy(&state)
sb := strings.builder_make() defer strings.builder_destroy(&sb) render(state, &sb, 80, theme.DEFAULT) testing.expect_value(t, strings.has_prefix(strings.to_string(sb), CL), true)}
@(test)test_render_cursor_empty_input :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state)
// Just after the marker. expect_cursor(t, state, 80, 0, MARKER_WIDTH)}
@(test)test_render_cursor_after_text :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello") state.position = 5
expect_cursor(t, state, 80, 0, MARKER_WIDTH + 5)}
@(test)test_render_cursor_mid_text :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello") state.position = 2
expect_cursor(t, state, 80, 0, MARKER_WIDTH + 2)}
@(test)test_render_cursor_counts_wide_runes :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "a你b") // 你 is 2 cells; position 4 = after "a你" state.position = 4
expect_cursor(t, state, 80, 0, MARKER_WIDTH + 1 + 2)}
@(test)test_render_cursor_tab_counts_tab_width :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "a\tb") state.position = 2 // after "a\t"
expect_cursor(t, state, 80, 0, MARKER_WIDTH + 1 + term.TAB_WIDTH)}
@(test)test_render_cursor_after_newline :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "ab\ncd") state.position = 3 // after the newline, before 'c'
expect_cursor(t, state, 80, 1, MARKER_WIDTH)}
@(test)test_render_cursor_on_wrapped_row :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello") // width 6 → content_width 4 → "hell" / "o" state.position = 5
expect_cursor(t, state, 6, 1, MARKER_WIDTH + 1)}
@(test)test_render_cursor_at_wrap_boundary_sits_at_row_end :: proc(t: ^testing.T) { state := state_make() defer state_destroy(&state) fill(&state, "hello") // width 6 → "hell" / "o" state.position = 4 // the wrap point: end of row 0
expect_cursor(t, state, 6, 0, MARKER_WIDTH + 4)}