rho-coding-agent 3.12.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use pretty_assertions::assert_eq;

use super::{apply_masked_key, MaskedKey};
use crate::tui::line_editor::LineEditor;

// Covers: chords never type into a secret, and only plain Enter submits it,
// so Ctrl+C or Alt+Enter cannot add a letter or send a half-typed key
// Owner: masked single-line field
#[test]
fn chords_neither_type_nor_submit() {
    let cases = [
        (
            KeyCode::Char('a'),
            KeyModifiers::NONE,
            MaskedKey::Handled,
            "a",
        ),
        (
            KeyCode::Char('A'),
            KeyModifiers::SHIFT,
            MaskedKey::Handled,
            "A",
        ),
        (
            KeyCode::Char('c'),
            KeyModifiers::CONTROL,
            MaskedKey::Handled,
            "",
        ),
        (
            KeyCode::Char('x'),
            KeyModifiers::ALT,
            MaskedKey::Handled,
            "",
        ),
        (KeyCode::Enter, KeyModifiers::NONE, MaskedKey::Submit, ""),
        (KeyCode::Enter, KeyModifiers::ALT, MaskedKey::Handled, ""),
        (KeyCode::Esc, KeyModifiers::NONE, MaskedKey::Cancel, ""),
    ];
    for (code, modifiers, outcome, typed) in cases {
        let mut editor = LineEditor::new("");
        let got = apply_masked_key(&mut editor, KeyEvent::new(code, modifiers));
        assert_eq!(
            (got, editor.value.as_str()),
            (outcome, typed),
            "{modifiers:?} {code:?}"
        );
    }
}