Bug fix in substring when using negative end index only

This commit is contained in:
sagie gur ari 2020-07-31 10:46:09 +00:00
parent c039360eaa
commit 28e6e6f7da
4 changed files with 11 additions and 7 deletions

View file

@ -1,5 +1,9 @@
## CHANGELOG
### v0.6.5 (2020-07-31)
* Bug fix in substring when using end index only.
### v0.6.4 (2020-07-31)
* New json_encode command #124

View file

@ -57,15 +57,15 @@ impl Command for CommandImpl {
(value, string_len)
}
} else {
let start_index = value + string_len;
let end_index = string_len + value;
if start_index < 0 {
if end_index < 0 {
return CommandResult::Error(
"Index from end cannot be bigger than total text size."
.to_string(),
);
} else {
(start_index, string_len)
(0, end_index)
}
}
}

View file

@ -43,8 +43,8 @@ fn run_text_only_start() {
fn run_text_only_end() {
test::run_script_and_validate(
vec![create("")],
"out = substring text -1",
CommandValidation::Match("out".to_string(), "t".to_string()),
"out = substring abcd -1",
CommandValidation::Match("out".to_string(), "abc".to_string()),
);
}

View file

@ -26,7 +26,7 @@ end
fn test_text_with_end
output = substring "test" -2
assert_eq ${output} "st"
assert_eq ${output} "te"
end
fn test_text_with_range_and_start_too_big
@ -45,4 +45,4 @@ fn test_text_with_range_and_end_too_big
output = substring "test" 0 8
assert_eq ${output} "false"
end
end