From 5b324f8ecb70239c40612857fc27d2b5ed0f8ae2 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 24 Mar 2024 16:29:11 +0100 Subject: [PATCH] Fix regression in parse_util_process_extent Found on a two-line commandline for file in (path base echo --- src/parse_util.rs | 6 +++--- src/tests/parse_util.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/parse_util.rs b/src/parse_util.rs index 6f0a26888..c66345892 100644 --- a/src/parse_util.rs +++ b/src/parse_util.rs @@ -391,7 +391,7 @@ fn job_or_process_extent( let mut result = cmdsub_range.clone(); for token in Tokenizer::new( - &buff[cmdsub_range], + &buff[cmdsub_range.clone()], TOK_ACCEPT_UNFINISHED | TOK_SHOW_COMMENTS, ) { let tok_begin = token.offset(); @@ -408,10 +408,10 @@ fn job_or_process_extent( { if tok_begin >= pos { finished = true; - result.end = tok_begin; + result.end = cmdsub_range.start + tok_begin; } else { // Statement at cursor might start after this token. - result.start = tok_begin + token.length(); + result.start = cmdsub_range.start + tok_begin + token.length(); out_tokens.as_mut().map(|tokens| tokens.clear()); } continue; // Do not add this to tokens diff --git a/src/tests/parse_util.rs b/src/tests/parse_util.rs index 89541685b..bfb122063 100644 --- a/src/tests/parse_util.rs +++ b/src/tests/parse_util.rs @@ -5,7 +5,9 @@ ERROR_NOT_ARGV_AT, ERROR_NOT_ARGV_COUNT, ERROR_NOT_ARGV_STAR, ERROR_NOT_PID, ERROR_NOT_STATUS, ERROR_NO_VAR_NAME, }; -use crate::parse_util::{parse_util_detect_errors, BOOL_AFTER_BACKGROUND_ERROR_MSG}; +use crate::parse_util::{ + parse_util_detect_errors, parse_util_process_extent, BOOL_AFTER_BACKGROUND_ERROR_MSG, +}; use crate::tests::prelude::*; use crate::wchar::prelude::*; @@ -85,3 +87,16 @@ macro_rules! validate { BOOL_AFTER_BACKGROUND_ERROR_MSG ); } + +#[test] +fn test_parse_util_process_extent() { + macro_rules! validate { + ($commandline:literal, $cursor:expr, $expected_range:expr) => { + assert_eq!( + parse_util_process_extent(L!($commandline), $cursor, None), + $expected_range + ); + }; + } + validate!("for file in (path base\necho", 22, 13..22); +}