Lines
100 %
Functions
Branches
use super::*;
fn console() -> ConsoleState {
ConsoleState::new()
}
fn type_line(state: &mut ConsoleState, text: &str) {
for c in text.chars() {
state.input.insert_char(c);
#[test]
fn incomplete_form_buffers_and_yields_nothing() {
let mut state = console();
type_line(&mut state, "(list");
assert_eq!(state.take_complete_form(), None);
assert_eq!(state.pending, "(list");
assert!(state.input.buffer().is_empty());
assert!(state.history.is_empty());
fn balanced_form_yields_and_clears_buffer() {
type_line(&mut state, "(+ 1 2)");
let form = state.take_complete_form();
assert_eq!(form.as_deref(), Some("(+ 1 2)"));
assert!(state.pending.is_empty());
fn multiline_form_assembles_then_completes() {
type_line(&mut state, " 1 2)");
assert_eq!(form.as_deref(), Some("(list\n 1 2)"));
fn submitted_form_is_pushed_to_history() {
type_line(&mut state, "(foo)");
let _ = state.take_complete_form();
assert_eq!(state.history, vec!["(foo)".to_string()]);
assert_eq!(state.history_cursor, None);
fn incomplete_form_not_pushed_to_history() {
type_line(&mut state, "(open");
fn history_prev_loads_latest_then_older_entries() {
for form in ["(a)", "(b)", "(c)"] {
type_line(&mut state, form);
state.history_prev();
assert_eq!(state.input.buffer(), "(c)");
assert_eq!(state.input.buffer(), "(b)");
assert_eq!(state.input.buffer(), "(a)");
fn history_next_walks_forward_then_clears_to_fresh_line() {
for form in ["(a)", "(b)"] {
state.history_next();
fn history_navigation_is_noop_without_history() {
fn blank_enter_yields_nothing_and_records_no_history() {
type_line(&mut state, " ");
fn duplicate_consecutive_submissions_both_recorded() {
for _ in 0..2 {
type_line(&mut state, "(a)");
assert_eq!(state.take_complete_form().as_deref(), Some("(a)"));
assert_eq!(state.history, vec!["(a)".to_string(), "(a)".to_string()]);
fn history_next_at_bottom_is_noop() {
fn history_caps_at_max_dropping_oldest() {
for i in 0..(MAX_HISTORY_ENTRIES + 5) {
type_line(&mut state, &format!("(f{i})"));
assert_eq!(state.history.len(), MAX_HISTORY_ENTRIES);
assert_eq!(state.history.first().unwrap(), "(f5)");
assert_eq!(
state.history.last().unwrap(),
&format!("(f{})", MAX_HISTORY_ENTRIES + 4)
);
state.input.buffer(),
format!("(f{})", MAX_HISTORY_ENTRIES + 4)
fn format_result_splits_lines_verbatim() {
format_result("(:id 1 :value 2)"),
vec!["(:id 1 :value 2)".to_string()]
format_result("line one\nline two"),
vec!["line one".to_string(), "line two".to_string()]
fn push_scrollback_caps_at_max_dropping_oldest() {
for i in 0..(MAX_SCROLLBACK_LINES + 5) {
state.push_scrollback(format!("line {i}"));
assert_eq!(state.scrollback.len(), MAX_SCROLLBACK_LINES);
assert_eq!(state.scrollback.first().unwrap(), "line 5");
state.scrollback.last().unwrap(),
&format!("line {}", MAX_SCROLLBACK_LINES + 4)