Fix regression in parse_util_process_extent

Found on a two-line commandline

    for file in (path base<TAB>
    echo
This commit is contained in:
Johannes Altmanninger 2024-03-24 16:29:11 +01:00
parent 1216801474
commit 5b324f8ecb
2 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -5,7 +5,9 @@ use crate::parse_constants::{
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 @@ fn test_error_messages() {
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);
}