forked from extern/nushell
Oops, match semantics of each group/window (#967)
This commit is contained in:
parent
8a373dd554
commit
84d3620d9b
@ -2,8 +2,8 @@ use nu_engine::{eval_block_with_redirect, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
||||
Span, Spanned, SyntaxShape, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, Spanned,
|
||||
SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -73,7 +73,7 @@ impl Command for EachGroup {
|
||||
span: call.head,
|
||||
};
|
||||
|
||||
Ok(each_group_iterator.flatten().into_pipeline_data(ctrlc))
|
||||
Ok(each_group_iterator.into_pipeline_data(ctrlc))
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ struct EachGroupIterator {
|
||||
}
|
||||
|
||||
impl Iterator for EachGroupIterator {
|
||||
type Item = PipelineData;
|
||||
type Item = Value;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mut group = vec![];
|
||||
@ -129,7 +129,7 @@ pub(crate) fn run_block_on_vec(
|
||||
engine_state: EngineState,
|
||||
stack: Stack,
|
||||
span: Span,
|
||||
) -> PipelineData {
|
||||
) -> Value {
|
||||
let value = Value::List { vals: input, span };
|
||||
|
||||
let mut stack = stack.captures_to_stack(&capture_block.captures);
|
||||
@ -143,8 +143,8 @@ pub(crate) fn run_block_on_vec(
|
||||
}
|
||||
|
||||
match eval_block_with_redirect(&engine_state, &mut stack, block, PipelineData::new(span)) {
|
||||
Ok(pipeline) => pipeline,
|
||||
Err(error) => Value::Error { error }.into_pipeline_data(),
|
||||
Ok(pipeline) => pipeline.into_value(span),
|
||||
Err(error) => Value::Error { error },
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ use nu_engine::{eval_block_with_redirect, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
||||
Span, Spanned, SyntaxShape, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, Spanned,
|
||||
SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -113,7 +113,7 @@ impl Command for EachWindow {
|
||||
stride,
|
||||
};
|
||||
|
||||
Ok(each_group_iterator.flatten().into_pipeline_data(ctrlc))
|
||||
Ok(each_group_iterator.into_pipeline_data(ctrlc))
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ struct EachWindowIterator {
|
||||
}
|
||||
|
||||
impl Iterator for EachWindowIterator {
|
||||
type Item = PipelineData;
|
||||
type Item = Value;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mut group = self.previous.clone();
|
||||
@ -148,7 +148,7 @@ impl Iterator for EachWindowIterator {
|
||||
break;
|
||||
}
|
||||
}
|
||||
None => break,
|
||||
None => return None,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -166,7 +166,7 @@ impl Iterator for EachWindowIterator {
|
||||
break;
|
||||
}
|
||||
}
|
||||
None => break,
|
||||
None => return None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ pub(crate) fn run_block_on_vec(
|
||||
engine_state: EngineState,
|
||||
stack: Stack,
|
||||
span: Span,
|
||||
) -> PipelineData {
|
||||
) -> Value {
|
||||
let value = Value::List { vals: input, span };
|
||||
|
||||
let mut stack = stack.captures_to_stack(&capture_block.captures);
|
||||
@ -211,8 +211,8 @@ pub(crate) fn run_block_on_vec(
|
||||
}
|
||||
|
||||
match eval_block_with_redirect(&engine_state, &mut stack, block, PipelineData::new(span)) {
|
||||
Ok(pipeline) => pipeline,
|
||||
Err(error) => Value::Error { error }.into_pipeline_data(),
|
||||
Ok(pipeline) => pipeline.into_value(span),
|
||||
Err(error) => Value::Error { error },
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ use nu_engine::{eval_block_with_redirect, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
||||
Spanned, SyntaxShape, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Spanned,
|
||||
SyntaxShape, Value,
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
|
||||
@ -78,13 +78,12 @@ impl Command for ParEachGroup {
|
||||
block,
|
||||
PipelineData::new(span),
|
||||
) {
|
||||
Ok(v) => v,
|
||||
Err(error) => Value::Error { error }.into_pipeline_data(),
|
||||
Ok(v) => v.into_value(span),
|
||||
Err(error) => Value::Error { error },
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.into_pipeline_data(ctrlc))
|
||||
}
|
||||
}
|
||||
|
@ -12,42 +12,36 @@ fn each_works_separately() {
|
||||
assert_eq!(actual.out, "[11,12,13]");
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn each_group_works() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4 5 6] | each group 3 { $it } | to json
|
||||
echo [1 2 3 4 5 6] | each group 3 { $it } | to json --raw
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[[1,2,3],[4,5,6]]");
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn each_window() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4] | each window 3 { $it } | to json
|
||||
echo [1 2 3 4] | each window 3 { $it } | to json --raw
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[[1,2,3],[2,3,4]]");
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn each_window_stride() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4 5 6] | each window 3 -s 2 { echo $it } | to json
|
||||
echo [1 2 3 4 5 6] | each window 3 -s 2 { echo $it } | to json --raw
|
||||
"#
|
||||
));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user