mirror of
https://github.com/nushell/nushell
synced 2024-11-10 23:24:14 +00:00
Fix 'range' range exclusive (#5334)
This commit is contained in:
parent
fb8f7b114e
commit
be3f0edc97
2 changed files with 11 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue