Fix 'range' range exclusive (#5334)

This commit is contained in:
JT 2022-04-27 06:39:38 +12:00 committed by GitHub
parent fb8f7b114e
commit be3f0edc97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,6 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::{Call, RangeInclusion};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span,
@ -69,7 +69,11 @@ impl Command for Range {
let rows: nu_protocol::Range = call.req(engine_state, stack, 0)?;
let rows_from = get_range_val(rows.from);
let rows_to = get_range_val(rows.to);
let rows_to = if rows.inclusion == RangeInclusion::RightExclusive {
get_range_val(rows.to) - 1
} else {
get_range_val(rows.to)
};
// only collect the input if we have any negative indices
if rows_from < 0 || rows_to < 0 {

View File

@ -347,3 +347,8 @@ fn better_operator_spans() -> TestResult {
"true",
)
}
#[test]
fn range_right_exclusive() -> TestResult {
run_test(r#"[1, 4, 5, 8, 9] | range 1..<3 | math sum"#, "9")
}