mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
Bug fix in substring when using negative end index only
This commit is contained in:
parent
c039360eaa
commit
28e6e6f7da
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue