use super::super::*;
#[test]
fn test_create_move_event_left() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let event = ConditionalEditMode::<Emacs>::create_move_event(5, 2, false);
match event {
ReedlineEvent::Edit(commands) => {
assert_eq!(commands.len(), 3);
for cmd in commands {
assert!(matches!(cmd, EditCommand::MoveLeft { select: false }));
}
}
_ => panic!("Expected Edit event with MoveLeft commands"),
}
}
#[test]
fn test_create_move_event_right() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let event = ConditionalEditMode::<Emacs>::create_move_event(2, 5, false);
match event {
ReedlineEvent::Edit(commands) => {
assert_eq!(commands.len(), 3);
for cmd in commands {
assert!(matches!(cmd, EditCommand::MoveRight { select: false }));
}
}
_ => panic!("Expected Edit event with MoveRight commands"),
}
}
#[test]
fn test_create_move_event_with_selection() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let event = ConditionalEditMode::<Emacs>::create_move_event(2, 5, true);
match event {
ReedlineEvent::Edit(commands) => {
assert_eq!(commands.len(), 3);
for cmd in commands {
assert!(matches!(cmd, EditCommand::MoveRight { select: true }));
}
}
_ => panic!("Expected Edit event with MoveRight commands"),
}
}
#[test]
fn test_create_move_event_same_position() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let event = ConditionalEditMode::<Emacs>::create_move_event(5, 5, false);
assert!(matches!(event, ReedlineEvent::None));
}
#[test]
fn test_tree_sitter_word_nav_pipe_operator() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let state_ref = new_editor_state_ref();
{
let mut state = state_ref.lock().unwrap();
state.buffer = "x |> filter()".to_string();
state.buffer_len = 13;
state.cursor_pos = 2;
state.uncertain = false;
}
let conditional = ConditionalEditMode::new(Emacs::default(), state_ref.clone())
.with_tree_sitter_word_nav(true);
let event = ReedlineEvent::Edit(vec![EditCommand::MoveWordRight { select: false }]);
let result = conditional.handle_tree_sitter_word_nav(&event);
assert!(result.is_some());
let result_event = result.unwrap();
match result_event {
ReedlineEvent::Edit(commands) => {
assert_eq!(commands.len(), 2); for cmd in commands {
assert!(matches!(cmd, EditCommand::MoveRight { select: false }));
}
}
_ => panic!("Expected Edit event"),
}
}
#[test]
fn test_tree_sitter_word_nav_assignment_left() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let state_ref = new_editor_state_ref();
{
let mut state = state_ref.lock().unwrap();
state.buffer = "x <- 42".to_string();
state.buffer_len = 7;
state.cursor_pos = 4;
state.uncertain = false;
}
let conditional = ConditionalEditMode::new(Emacs::default(), state_ref.clone())
.with_tree_sitter_word_nav(true);
let event = ReedlineEvent::Edit(vec![EditCommand::MoveWordLeft { select: false }]);
let result = conditional.handle_tree_sitter_word_nav(&event);
assert!(result.is_some());
let result_event = result.unwrap();
match result_event {
ReedlineEvent::Edit(commands) => {
assert_eq!(commands.len(), 2); for cmd in commands {
assert!(matches!(cmd, EditCommand::MoveLeft { select: false }));
}
}
_ => panic!("Expected Edit event"),
}
}
#[test]
fn test_tree_sitter_word_nav_disabled() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let state_ref = new_editor_state_ref();
{
let mut state = state_ref.lock().unwrap();
state.buffer = "x |> filter()".to_string();
state.buffer_len = 13;
state.cursor_pos = 2;
state.uncertain = false;
}
let conditional = ConditionalEditMode::new(Emacs::default(), state_ref.clone());
let event = ReedlineEvent::Edit(vec![EditCommand::MoveWordRight { select: false }]);
let result = conditional.handle_tree_sitter_word_nav(&event);
assert!(result.is_none());
}
#[test]
fn test_tree_sitter_word_nav_uncertain_state() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let state_ref = new_editor_state_ref();
{
let mut state = state_ref.lock().unwrap();
state.buffer = "x |> filter()".to_string();
state.buffer_len = 13;
state.cursor_pos = 2;
state.uncertain = true; }
let conditional = ConditionalEditMode::new(Emacs::default(), state_ref.clone())
.with_tree_sitter_word_nav(true);
let event = ReedlineEvent::Edit(vec![EditCommand::MoveWordRight { select: false }]);
let result = conditional.handle_tree_sitter_word_nav(&event);
assert!(result.is_none());
}
#[test]
fn test_tree_sitter_word_nav_until_found() {
use super::super::ConditionalEditMode;
use reedline::Emacs;
let state_ref = new_editor_state_ref();
{
let mut state = state_ref.lock().unwrap();
state.buffer = "x |> filter()".to_string();
state.buffer_len = 13;
state.cursor_pos = 2;
state.uncertain = false;
}
let conditional = ConditionalEditMode::new(Emacs::default(), state_ref.clone())
.with_tree_sitter_word_nav(true);
let event = ReedlineEvent::UntilFound(vec![
ReedlineEvent::HistoryHintWordComplete,
ReedlineEvent::Edit(vec![EditCommand::MoveWordRight { select: false }]),
]);
let result = conditional.handle_tree_sitter_word_nav(&event);
assert!(result.is_some());
let result_event = result.unwrap();
match result_event {
ReedlineEvent::UntilFound(events) => {
assert_eq!(events.len(), 2);
assert!(matches!(events[0], ReedlineEvent::HistoryHintWordComplete));
match &events[1] {
ReedlineEvent::Edit(commands) => {
assert_eq!(commands.len(), 2);
}
_ => panic!("Expected Edit event"),
}
}
_ => panic!("Expected UntilFound event"),
}
}