Remove Span::unknown (#525)

This commit is contained in:
JT 2021-12-19 18:46:13 +11:00 committed by GitHub
parent b54e9b6bfd
commit 2883d6cd1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
183 changed files with 1291 additions and 1124 deletions

View File

@ -47,7 +47,7 @@ impl Command for SubCommand {
.to_string()
.as_bytes()
.to_vec(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -55,7 +55,7 @@ impl Command for SubCommand {
example: "1 | into binary",
result: Some(Value::Binary {
val: i64::from(1).to_le_bytes().to_vec(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -63,7 +63,7 @@ impl Command for SubCommand {
example: "$true | into binary",
result: Some(Value::Binary {
val: i64::from(1).to_le_bytes().to_vec(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -81,7 +81,7 @@ impl Command for SubCommand {
example: "1.234 | into binary",
result: Some(Value::Binary {
val: 1.234f64.to_le_bytes().to_vec(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -316,11 +316,11 @@ mod tests {
fn takes_a_date_format() {
let date_str = Value::test_string("16.11.1984 8:00 am +0000");
let fmt_options = Some(DatetimeFormat("%d.%m.%Y %H:%M %P %z".to_string()));
let actual = action(&date_str, &None, &fmt_options, Span::unknown());
let actual = action(&date_str, &None, &fmt_options, Span::test_data());
let expected = Value::Date {
val: DateTime::parse_from_str("16.11.1984 8:00 am +0000", "%d.%m.%Y %H:%M %P %z")
.unwrap(),
span: Span::unknown(),
span: Span::test_data(),
};
assert_eq!(actual, expected)
}
@ -328,11 +328,11 @@ mod tests {
#[test]
fn takes_iso8601_date_format() {
let date_str = Value::test_string("2020-08-04T16:39:18+00:00");
let actual = action(&date_str, &None, &None, Span::unknown());
let actual = action(&date_str, &None, &None, Span::test_data());
let expected = Value::Date {
val: DateTime::parse_from_str("2020-08-04T16:39:18+00:00", "%Y-%m-%dT%H:%M:%S%z")
.unwrap(),
span: Span::unknown(),
span: Span::test_data(),
};
assert_eq!(actual, expected)
}
@ -342,13 +342,13 @@ mod tests {
let date_str = Value::test_string("1614434140");
let timezone_option = Some(Spanned {
item: Zone::East(8),
span: Span::unknown(),
span: Span::test_data(),
});
let actual = action(&date_str, &timezone_option, &None, Span::unknown());
let actual = action(&date_str, &timezone_option, &None, Span::test_data());
let expected = Value::Date {
val: DateTime::parse_from_str("2021-02-27 21:55:40 +08:00", "%Y-%m-%d %H:%M:%S %z")
.unwrap(),
span: Span::unknown(),
span: Span::test_data(),
};
assert_eq!(actual, expected)
@ -359,12 +359,12 @@ mod tests {
let date_str = Value::test_string("1614434140");
let timezone_option = Some(Spanned {
item: Zone::Local,
span: Span::unknown(),
span: Span::test_data(),
});
let actual = action(&date_str, &timezone_option, &None, Span::unknown());
let actual = action(&date_str, &timezone_option, &None, Span::test_data());
let expected = Value::Date {
val: Local.timestamp(1614434140, 0).into(),
span: Span::unknown(),
span: Span::test_data(),
};
assert_eq!(actual, expected)
@ -375,9 +375,9 @@ mod tests {
let date_str = Value::test_string("10440970000000");
let timezone_option = Some(Spanned {
item: Zone::Utc,
span: Span::unknown(),
span: Span::test_data(),
});
let actual = action(&date_str, &timezone_option, &None, Span::unknown());
let actual = action(&date_str, &timezone_option, &None, Span::test_data());
assert_eq!(actual.get_type(), Error);
}
@ -386,7 +386,7 @@ mod tests {
fn communicates_parsing_error_given_an_invalid_datetimelike_string() {
let date_str = Value::test_string("16.11.1984 8:00 am Oops0000");
let fmt_options = Some(DatetimeFormat("%d.%m.%Y %H:%M %P %z".to_string()));
let actual = action(&date_str, &None, &fmt_options, Span::unknown());
let actual = action(&date_str, &None, &fmt_options, Span::test_data());
assert_eq!(actual.get_type(), Error);
}

View File

@ -44,9 +44,9 @@ impl Command for SubCommand {
vals: vec![Value::Record {
cols: vec!["num".to_string()],
vals: vec![Value::test_float(5.01)],
span: Span::unknown(),
span: Span::test_data(),
}],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -142,7 +142,7 @@ mod tests {
let word = Value::test_string("3.1415");
let expected = Value::test_float(3.1415);
let actual = action(&word, Span::unknown());
let actual = action(&word, Span::test_data());
assert_eq!(actual, expected);
}
@ -150,7 +150,7 @@ mod tests {
fn communicates_parsing_error_given_an_invalid_decimallike_string() {
let decimal_str = Value::test_string("11.6anra");
let actual = action(&decimal_str, Span::unknown());
let actual = action(&decimal_str, Span::test_data());
assert_eq!(actual.get_type(), Error);
}
@ -159,7 +159,7 @@ mod tests {
fn int_to_decimal() {
let decimal_str = Value::test_int(10);
let expected = Value::test_float(10.0);
let actual = action(&decimal_str, Span::unknown());
let actual = action(&decimal_str, Span::test_data());
assert_eq!(actual, expected);
}

View File

@ -49,7 +49,7 @@ impl Command for SubCommand {
example: "'2' | into filesize",
result: Some(Value::Filesize {
val: 2,
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -57,7 +57,7 @@ impl Command for SubCommand {
example: "8.3 | into filesize",
result: Some(Value::Filesize {
val: 8,
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -65,7 +65,7 @@ impl Command for SubCommand {
example: "5 | into filesize",
result: Some(Value::Filesize {
val: 5,
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -73,7 +73,7 @@ impl Command for SubCommand {
example: "4KB | into filesize",
result: Some(Value::Filesize {
val: 4000,
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -70,7 +70,7 @@ impl Command for SubCommand {
example: "4KB | into int",
result: Some(Value::Int {
val: 4000,
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -78,7 +78,7 @@ impl Command for SubCommand {
example: "[$false, $true] | into int",
result: Some(Value::List {
vals: vec![Value::test_int(0), Value::test_int(1)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -273,21 +273,21 @@ mod test {
let word = Value::test_string("10");
let expected = Value::test_int(10);
let actual = action(&word, Span::unknown(), 10);
let actual = action(&word, Span::test_data(), 10);
assert_eq!(actual, expected);
}
#[test]
fn turns_binary_to_integer() {
let s = Value::test_string("0b101");
let actual = action(&s, Span::unknown(), 10);
let actual = action(&s, Span::test_data(), 10);
assert_eq!(actual, Value::test_int(5));
}
#[test]
fn turns_hex_to_integer() {
let s = Value::test_string("0xFF");
let actual = action(&s, Span::unknown(), 16);
let actual = action(&s, Span::test_data(), 16);
assert_eq!(actual, Value::test_int(255));
}
@ -295,7 +295,7 @@ mod test {
fn communicates_parsing_error_given_an_invalid_integerlike_string() {
let integer_str = Value::test_string("36anra");
let actual = action(&integer_str, Span::unknown(), 10);
let actual = action(&integer_str, Span::test_data(), 10);
assert_eq!(actual.get_type(), Error)
}

View File

@ -53,7 +53,7 @@ impl Command for SubCommand {
example: "1.7 | into string -d 0",
result: Some(Value::String {
val: "2".to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -61,7 +61,7 @@ impl Command for SubCommand {
example: "1.7 | into string -d 1",
result: Some(Value::String {
val: "1.7".to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -69,7 +69,7 @@ impl Command for SubCommand {
example: "1.734 | into string -d 2",
result: Some(Value::String {
val: "1.73".to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -80,7 +80,7 @@ impl Command for SubCommand {
// result: Some(Value::Error {
// error: ShellError::UnsupportedInput(
// String::from("Cannot accept negative integers for decimals arguments"),
// Span::unknown(),
// Span::test_data(),
// ),
// }),
},
@ -89,7 +89,7 @@ impl Command for SubCommand {
example: "4.3 | into string",
result: Some(Value::String {
val: "4.3".to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -97,7 +97,7 @@ impl Command for SubCommand {
example: "'1234' | into string",
result: Some(Value::String {
val: "1234".to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -105,7 +105,7 @@ impl Command for SubCommand {
example: "$true | into string",
result: Some(Value::String {
val: "true".to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {

View File

@ -99,7 +99,7 @@ impl Command for For {
}
fn examples(&self) -> Vec<Example> {
let span = Span::unknown();
let span = Span::test_data();
vec![
Example {
description: "Echo the square of each integer",
@ -110,7 +110,7 @@ impl Command for For {
Value::Int { val: 4, span },
Value::Int { val: 9, span },
],
span: Span::unknown(),
span,
}),
},
Example {
@ -122,7 +122,7 @@ impl Command for For {
Value::Int { val: 2, span },
Value::Int { val: 3, span },
],
span: Span::unknown(),
span,
}),
},
// FIXME? Numbered `for` is kinda strange, but was supported in previous nushell
@ -140,7 +140,7 @@ impl Command for For {
// span,
// },
// ],
// span: Span::unknown(),
// span,
// }),
// },
]

View File

@ -1,7 +1,7 @@
use nu_engine::eval_block;
use nu_protocol::ast::{Call, Expr, Expression, ImportPatternMember};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, ShellError, Signature, Span, SyntaxShape};
use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Use;
@ -89,7 +89,7 @@ impl Command for Use {
// TODO: Add string conversions (e.g. int to string)
// TODO: Later expand env to take all Values
let val = eval_block(engine_state, stack, block, PipelineData::new(call.head))?
.into_value(Span::unknown());
.into_value(call.head);
stack.add_env_var(name, val);
}

View File

@ -1,7 +1,7 @@
use indexmap::IndexMap;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value};
use nu_protocol::{Example, IntoPipelineData, PipelineData, ShellError, Signature, Value};
pub mod shadow {
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
@ -66,7 +66,7 @@ pub fn version(
"branch".to_string(),
Value::String {
val: branch.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -77,7 +77,7 @@ pub fn version(
"short_commit".to_string(),
Value::String {
val: short_commit.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -87,7 +87,7 @@ pub fn version(
"commit_hash".to_string(),
Value::String {
val: commit_hash.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -97,7 +97,7 @@ pub fn version(
"commit_date".to_string(),
Value::String {
val: commit_date.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -108,7 +108,7 @@ pub fn version(
"build_os".to_string(),
Value::String {
val: build_os.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -119,7 +119,7 @@ pub fn version(
"rust_version".to_string(),
Value::String {
val: rust_version.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -130,7 +130,7 @@ pub fn version(
"rust_channel".to_string(),
Value::String {
val: rust_channel.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -141,7 +141,7 @@ pub fn version(
"cargo_version".to_string(),
Value::String {
val: cargo_version.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -152,7 +152,7 @@ pub fn version(
"pkg_version".to_string(),
Value::String {
val: pkg_version.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -163,7 +163,7 @@ pub fn version(
"build_time".to_string(),
Value::String {
val: build_time.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -175,7 +175,7 @@ pub fn version(
"build_rust_channel".to_string(),
Value::String {
val: build_rust_channel.to_string(),
span: Span::unknown(),
span: call.head,
},
);
}
@ -184,7 +184,7 @@ pub fn version(
"features".to_string(),
Value::String {
val: features_enabled().join(", "),
span: Span::unknown(),
span: call.head,
},
);
@ -200,7 +200,7 @@ pub fn version(
"installed_plugins".to_string(),
Value::String {
val: installed_plugins.join(", "),
span: Span::unknown(),
span: call.head,
},
);
@ -211,9 +211,9 @@ pub fn version(
// vals: vec![Value::Record {
// cols,
// vals,
// span: Span::unknown(),
// span: call.head,
// }],
// span: Span::unknown(),
// span: call.head,
// }
// .into_pipeline_data())
@ -221,7 +221,7 @@ pub fn version(
Ok(Value::Record {
cols,
vals,
span: Span::unknown(),
span: call.head,
}
.into_pipeline_data())
}

View File

@ -34,13 +34,25 @@ impl Command for AppendDF {
$a | dfr append $a"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![1.into(), 3.into()]),
Column::new("b".to_string(), vec![2.into(), 4.into()]),
Column::new("a_x".to_string(), vec![1.into(), 3.into()]),
Column::new("b_x".to_string(), vec![2.into(), 4.into()]),
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(3)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(4)],
),
Column::new(
"a_x".to_string(),
vec![Value::test_int(1), Value::test_int(3)],
),
Column::new(
"b_x".to_string(),
vec![Value::test_int(2), Value::test_int(4)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -51,15 +63,25 @@ impl Command for AppendDF {
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![1.into(), 3.into(), 1.into(), 3.into()],
vec![
Value::test_int(1),
Value::test_int(3),
Value::test_int(1),
Value::test_int(3),
],
),
Column::new(
"b".to_string(),
vec![2.into(), 4.into(), 2.into(), 4.into()],
vec![
Value::test_int(2),
Value::test_int(4),
Value::test_int(2),
Value::test_int(4),
],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
]

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
};
use super::values::{Column, NuDataFrame};
@ -32,10 +32,10 @@ impl Command for ColumnDF {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"a".to_string(),
vec![1.into(), 3.into()],
vec![Value::test_int(1), Value::test_int(3)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::{
chunked_array::ChunkedArray,
@ -37,51 +37,51 @@ impl Command for DescribeDF {
Column::new(
"descriptor".to_string(),
vec![
"count".to_string().into(),
"sum".to_string().into(),
"mean".to_string().into(),
"median".to_string().into(),
"std".to_string().into(),
"min".to_string().into(),
"25%".to_string().into(),
"50%".to_string().into(),
"75%".to_string().into(),
"max".to_string().into(),
Value::test_string("count"),
Value::test_string("sum"),
Value::test_string("mean"),
Value::test_string("median"),
Value::test_string("std"),
Value::test_string("min"),
Value::test_string("25%"),
Value::test_string("50%"),
Value::test_string("75%"),
Value::test_string("max"),
],
),
Column::new(
"a (i64)".to_string(),
vec![
2.0.into(),
2.0.into(),
1.0.into(),
1.0.into(),
0.0.into(),
1.0.into(),
1.0.into(),
1.0.into(),
1.0.into(),
1.0.into(),
Value::test_float(2.0),
Value::test_float(2.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(0.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(1.0),
],
),
Column::new(
"b (i64)".to_string(),
vec![
2.0.into(),
2.0.into(),
1.0.into(),
1.0.into(),
0.0.into(),
1.0.into(),
1.0.into(),
1.0.into(),
1.0.into(),
1.0.into(),
Value::test_float(2.0),
Value::test_float(2.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(0.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(1.0),
Value::test_float(1.0),
],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -33,10 +33,10 @@ impl Command for DropDF {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"b".to_string(),
vec![2.into(), 4.into()],
vec![Value::test_int(2), Value::test_int(4)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -40,12 +40,21 @@ impl Command for DropNulls {
$a | dfr drop-nulls"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![1.into(), 1.into()]),
Column::new("b".to_string(), vec![2.into(), 2.into()]),
Column::new("res".to_string(), vec![1.into(), 1.into()]),
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(1)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2)],
),
Column::new(
"res".to_string(),
vec![Value::test_int(1), Value::test_int(1)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -55,10 +64,15 @@ impl Command for DropNulls {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"div_0_0".to_string(),
vec![1.into(), 1.into(), 1.into(), 1.into()],
vec![
Value::test_int(1),
Value::test_int(1),
Value::test_int(1),
Value::test_int(1),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
]
@ -94,7 +108,7 @@ fn command(
.collect::<Vec<String>>();
(Some(agg_string), col_span)
}
None => (None, Span::unknown()),
None => (None, call.head),
};
let subset_slice = subset.as_ref().map(|cols| &cols[..]);

View File

@ -29,15 +29,15 @@ impl Command for DataTypes {
NuDataFrame::try_from_columns(vec![
Column::new(
"column".to_string(),
vec!["a".to_string().into(), "b".to_string().into()],
vec![Value::test_string("a"), Value::test_string("b")],
),
Column::new(
"dtype".to_string(),
vec!["i64".to_string().into(), "i64".to_string().into()],
vec![Value::test_string("i64"), Value::test_string("i64")],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -30,10 +30,10 @@ impl Command for AllFalse {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"all_false".to_string(),
vec![true.into()],
vec![Value::test_bool(true)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -44,10 +44,10 @@ impl Command for AllFalse {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"all_false".to_string(),
vec![false.into()],
vec![Value::test_bool(false)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
]

View File

@ -30,10 +30,10 @@ impl Command for AllTrue {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"all_true".to_string(),
vec![true.into()],
vec![Value::test_bool(true)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -44,10 +44,10 @@ impl Command for AllTrue {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"all_true".to_string(),
vec![false.into()],
vec![Value::test_bool(false)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
]

View File

@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
@ -30,10 +30,10 @@ impl Command for ArgMax {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"arg_max".to_string(),
vec![1.into()],
vec![Value::test_int(1)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
@ -30,10 +30,10 @@ impl Command for ArgMin {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"arg_min".to_string(),
vec![0.into()],
vec![Value::test_int(0)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
};
use polars::prelude::{DataType, IntoSeries};
@ -64,10 +64,16 @@ impl Command for Cumulative {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0_cum_sum".to_string(),
vec![1.into(), 3.into(), 6.into(), 10.into(), 15.into()],
vec![
Value::test_int(1),
Value::test_int(3),
Value::test_int(6),
Value::test_int(10),
Value::test_int(15),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetDay {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![4.into(), 4.into()],
vec![Value::test_int(4), Value::test_int(4)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetHour {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![16.into(), 16.into()],
vec![Value::test_int(16), Value::test_int(16)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetMinute {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![39.into(), 39.into()],
vec![Value::test_int(39), Value::test_int(39)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetMonth {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![8.into(), 8.into()],
vec![Value::test_int(8), Value::test_int(8)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetNanosecond {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![0.into(), 0.into()],
vec![Value::test_int(0), Value::test_int(0)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetOrdinal {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![217.into(), 217.into()],
vec![Value::test_int(217), Value::test_int(217)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetSecond {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![18.into(), 18.into()],
vec![Value::test_int(18), Value::test_int(18)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetWeek {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![32.into(), 32.into()],
vec![Value::test_int(32), Value::test_int(32)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetWeekDay {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![1.into(), 1.into()],
vec![Value::test_int(1), Value::test_int(1)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,10 @@ impl Command for GetYear {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![2020.into(), 2020.into()],
vec![Value::test_int(2020), Value::test_int(2020)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -33,10 +33,16 @@ impl Command for ArgSort {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"arg_sort".to_string(),
vec![0.into(), 1.into(), 2.into(), 3.into(), 4.into()],
vec![
Value::test_int(0),
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
Value::test_int(4),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -45,10 +51,16 @@ impl Command for ArgSort {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"arg_sort".to_string(),
vec![3.into(), 4.into(), 1.into(), 2.into(), 0.into()],
vec![
Value::test_int(3),
Value::test_int(4),
Value::test_int(1),
Value::test_int(2),
Value::test_int(0),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
]

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -30,10 +30,10 @@ impl Command for ArgTrue {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"arg_true".to_string(),
vec![1.into()],
vec![Value::test_int(1)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -30,10 +30,10 @@ impl Command for ArgUnique {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"arg_unique".to_string(),
vec![0.into(), 1.into(), 3.into()],
vec![Value::test_int(0), Value::test_int(1), Value::test_int(3)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -41,10 +41,17 @@ impl Command for SetWithIndex {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![6.into(), 1.into(), 6.into(), 2.into(), 4.into(), 3.into()],
vec![
Value::test_int(6),
Value::test_int(1),
Value::test_int(6),
Value::test_int(2),
Value::test_int(4),
Value::test_int(3),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -31,17 +31,17 @@ impl Command for IsDuplicated {
NuDataFrame::try_from_columns(vec![Column::new(
"is_duplicated".to_string(),
vec![
false.into(),
true.into(),
true.into(),
true.into(),
true.into(),
true.into(),
true.into(),
Value::test_bool(false),
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(true),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -35,17 +35,17 @@ impl Command for IsIn {
NuDataFrame::try_from_columns(vec![Column::new(
"is_in".to_string(),
vec![
false.into(),
true.into(),
true.into(),
true.into(),
false.into(),
false.into(),
false.into(),
Value::test_bool(false),
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(false),
Value::test_bool(false),
Value::test_bool(false),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,15 @@ impl Command for IsNotNull {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"is_not_null".to_string(),
vec![true.into(), true.into(), false.into(), true.into()],
vec![
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(false),
Value::test_bool(true),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,15 @@ impl Command for IsNull {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"is_null".to_string(),
vec![false.into(), false.into(), true.into(), false.into()],
vec![
Value::test_bool(false),
Value::test_bool(false),
Value::test_bool(true),
Value::test_bool(false),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -31,17 +31,17 @@ impl Command for IsUnique {
NuDataFrame::try_from_columns(vec![Column::new(
"is_unique".to_string(),
vec![
true.into(),
false.into(),
false.into(),
false.into(),
false.into(),
false.into(),
false.into(),
Value::test_bool(true),
Value::test_bool(false),
Value::test_bool(false),
Value::test_bool(false),
Value::test_bool(false),
Value::test_bool(false),
Value::test_bool(false),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -32,10 +32,14 @@ impl Command for NotSeries {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![false.into(), true.into(), false.into()],
vec![
Value::test_bool(false),
Value::test_bool(true),
Value::test_bool(false),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -41,10 +41,16 @@ impl Command for SetSeries {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![0.into(), 0.into(), 1.into(), 2.into(), 2.into()],
vec![
Value::test_int(0),
Value::test_int(0),
Value::test_int(1),
Value::test_int(2),
Value::test_int(2),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -30,10 +30,10 @@ impl Command for NNull {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"count_null".to_string(),
vec![2.into()],
vec![Value::test_int(2)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -29,10 +29,10 @@ impl Command for NUnique {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"count_unique".to_string(),
vec![4.into()],
vec![Value::test_int(4)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
#[derive(Clone)]
@ -32,10 +32,15 @@ impl Command for Rename {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"new_name".to_string(),
vec![5.into(), 6.into(), 7.into(), 8.into()],
vec![
Value::test_int(5),
Value::test_int(6),
Value::test_int(7),
Value::test_int(8),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
};
use polars::prelude::{DataType, IntoSeries, RollingOptions};
@ -68,10 +68,15 @@ impl Command for Rolling {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0_rolling_sum".to_string(),
vec![3.into(), 5.into(), 7.into(), 9.into()],
vec![
Value::test_int(3),
Value::test_int(5),
Value::test_int(7),
Value::test_int(9),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -80,10 +85,15 @@ impl Command for Rolling {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0_rolling_max".to_string(),
vec![2.into(), 3.into(), 4.into(), 5.into()],
vec![
Value::test_int(2),
Value::test_int(3),
Value::test_int(4),
Value::test_int(5),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
]

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
#[derive(Clone)]
@ -32,10 +32,10 @@ impl Command for Shift {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![1.into(), 2.into(), 2.into()],
vec![Value::test_int(1), Value::test_int(2), Value::test_int(2)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -39,13 +39,13 @@ impl Command for Concatenate {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"abcza".to_string().into(),
"abcxs".to_string().into(),
"abccd".to_string().into(),
Value::test_string("abcza"),
Value::test_string("abcxs"),
Value::test_string("abccd"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use polars::prelude::IntoSeries;
@ -37,10 +37,14 @@ impl Command for Contains {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![true.into(), false.into(), false.into()],
vec![
Value::test_bool(true),
Value::test_bool(false),
Value::test_bool(false),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use polars::prelude::IntoSeries;
@ -45,13 +45,13 @@ impl Command for Replace {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"ABc".to_string().into(),
"ABc".to_string().into(),
"ABc".to_string().into(),
Value::test_string("ABc"),
Value::test_string("ABc"),
Value::test_string("ABc"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use polars::prelude::IntoSeries;
@ -45,13 +45,13 @@ impl Command for ReplaceAll {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"AbAc".to_string().into(),
"AbAc".to_string().into(),
"AbAc".to_string().into(),
Value::test_string("AbAc"),
Value::test_string("AbAc"),
Value::test_string("AbAc"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -30,10 +30,10 @@ impl Command for StrLengths {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![1.into(), 2.into(), 3.into()],
vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use polars::prelude::IntoSeries;
@ -35,13 +35,13 @@ impl Command for StrSlice {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"bc".to_string().into(),
"bc".to_string().into(),
"bc".to_string().into(),
Value::test_string("bc"),
Value::test_string("bc"),
Value::test_string("bc"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -4,7 +4,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use polars::prelude::IntoSeries;
@ -36,12 +36,12 @@ impl Command for StrFTime {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"2020/08/04".to_string().into(),
"2020/08/04".to_string().into(),
Value::test_string("2020/08/04"),
Value::test_string("2020/08/04"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -31,13 +31,13 @@ impl Command for ToLowerCase {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"abc".to_string().into(),
"abc".to_string().into(),
"abc".to_string().into(),
Value::test_string("abc"),
Value::test_string("abc"),
Value::test_string("abc"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -31,13 +31,13 @@ impl Command for ToUpperCase {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"ABC".to_string().into(),
"ABC".to_string().into(),
"ABC".to_string().into(),
Value::test_string("ABC"),
Value::test_string("ABC"),
Value::test_string("ABC"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
use polars::prelude::IntoSeries;
@ -28,9 +28,12 @@ impl Command for Unique {
description: "Returns unique values from a series",
example: "[2 2 2 2 2] | dfr to-df | dfr unique",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new("0".to_string(), vec![2.into()])])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![Value::test_int(2)],
)])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
}]
}

View File

@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
#[derive(Clone)]
@ -28,11 +28,17 @@ impl Command for ValueCount {
example: "[5 5 5 5 6 6] | dfr to-df | dfr value-counts",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("0".to_string(), vec![5.into(), 6.into()]),
Column::new("counts".to_string(), vec![4.into(), 2.into()]),
Column::new(
"0".to_string(),
vec![Value::test_int(5), Value::test_int(6)],
),
Column::new(
"counts".to_string(),
vec![Value::test_int(4), Value::test_int(2)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -62,7 +62,7 @@ pub fn test_dataframe(cmds: Vec<Box<dyn Command + 'static>>) {
Value::Record {
cols: vec![],
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
);
@ -70,11 +70,11 @@ pub fn test_dataframe(cmds: Vec<Box<dyn Command + 'static>>) {
&engine_state,
&mut stack,
&block,
PipelineData::new(Span::unknown()),
PipelineData::new(Span::test_data()),
) {
Err(err) => panic!("test eval error in `{}`: {:?}", example.example, err),
Ok(result) => {
let result = result.into_value(Span::unknown());
let result = result.into_value(Span::test_data());
println!("input: {}", example.example);
println!("result: {:?}", result);
println!("done: {:?}", start.elapsed());

View File

@ -3,7 +3,7 @@ use super::values::{Column, NuDataFrame};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span,
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
#[derive(Clone)]
@ -29,11 +29,17 @@ impl Command for ToDataFrame {
example: "[[a b];[1 2] [3 4]] | dfr to-df",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![1.into(), 3.into()]),
Column::new("b".to_string(), vec![2.into(), 4.into()]),
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(3)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(4)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -41,19 +47,25 @@ impl Command for ToDataFrame {
example: "[[1 2 a] [3 4 b] [5 6 c]] | dfr to-df",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("0".to_string(), vec![1.into(), 3.into(), 5.into()]),
Column::new("1".to_string(), vec![2.into(), 4.into(), 6.into()]),
Column::new(
"0".to_string(),
vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
),
Column::new(
"1".to_string(),
vec![Value::test_int(2), Value::test_int(4), Value::test_int(6)],
),
Column::new(
"2".to_string(),
vec![
"a".to_string().into(),
"b".to_string().into(),
"c".to_string().into(),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -63,13 +75,13 @@ impl Command for ToDataFrame {
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![
"a".to_string().into(),
"b".to_string().into(),
"c".to_string().into(),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
Example {
@ -78,10 +90,14 @@ impl Command for ToDataFrame {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![true.into(), true.into(), false.into()],
vec![
Value::test_bool(true),
Value::test_bool(true),
Value::test_bool(false),
],
)])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
},
]

View File

@ -7,7 +7,7 @@ use polars::chunked_array::object::builder::ObjectChunkedBuilder;
use polars::chunked_array::ChunkedArray;
use polars::prelude::{
DataFrame, DataType, DatetimeChunked, Int64Type, IntoSeries, NamedFrom, NewChunkedArray,
ObjectType, PolarsNumericType, Series,
ObjectType, Series,
};
use std::ops::{Deref, DerefMut};
@ -109,15 +109,14 @@ pub fn create_column(
series: &Series,
from_row: usize,
to_row: usize,
span: Span,
) -> Result<Column, ShellError> {
let size = to_row - from_row;
match series.dtype() {
DataType::Null => {
let values = std::iter::repeat(Value::Nothing {
span: Span::unknown(),
})
.take(size)
.collect::<Vec<Value>>();
let values = std::iter::repeat(Value::Nothing { span })
.take(size)
.collect::<Vec<Value>>();
Ok(Column::new(series.name().into(), values))
}
@ -125,61 +124,188 @@ pub fn create_column(
let casted = series.u8().map_err(|e| {
ShellError::LabeledError("Error casting column to u8".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::UInt16 => {
let casted = series.u16().map_err(|e| {
ShellError::LabeledError("Error casting column to u16".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::UInt32 => {
let casted = series.u32().map_err(|e| {
ShellError::LabeledError("Error casting column to u32".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::UInt64 => {
let casted = series.u64().map_err(|e| {
ShellError::LabeledError("Error casting column to u64".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::Int8 => {
let casted = series.i8().map_err(|e| {
ShellError::LabeledError("Error casting column to i8".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::Int16 => {
let casted = series.i16().map_err(|e| {
ShellError::LabeledError("Error casting column to i16".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::Int32 => {
let casted = series.i32().map_err(|e| {
ShellError::LabeledError("Error casting column to i32".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::Int64 => {
let casted = series.i64().map_err(|e| {
ShellError::LabeledError("Error casting column to i64".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Int {
val: a as i64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::Float32 => {
let casted = series.f32().map_err(|e| {
ShellError::LabeledError("Error casting column to f32".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Float {
val: a as f64,
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::Float64 => {
let casted = series.f64().map_err(|e| {
ShellError::LabeledError("Error casting column to f64".into(), e.to_string())
})?;
Ok(column_from_casted(casted, from_row, size))
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Float { val: a, span },
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
Ok(Column::new(casted.name().into(), values))
}
DataType::Boolean => {
let casted = series.bool().map_err(|e| {
@ -191,13 +317,8 @@ pub fn create_column(
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => Value::Bool {
val: a,
span: Span::unknown(),
},
None => Value::Nothing {
span: Span::unknown(),
},
Some(a) => Value::Bool { val: a, span },
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
@ -215,11 +336,9 @@ pub fn create_column(
.map(|v| match v {
Some(a) => Value::String {
val: a.into(),
span: Span::unknown(),
},
None => Value::Nothing {
span: Span::unknown(),
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
@ -242,9 +361,7 @@ pub fn create_column(
.take(size)
.map(|v| match v {
Some(a) => a.get_value(),
None => Value::Nothing {
span: Span::unknown(),
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
@ -273,12 +390,10 @@ pub fn create_column(
Value::Date {
val: datetime,
span: Span::unknown(),
span,
}
}
None => Value::Nothing {
span: Span::unknown(),
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
@ -305,12 +420,10 @@ pub fn create_column(
Value::Date {
val: datetime,
span: Span::unknown(),
span,
}
}
None => Value::Nothing {
span: Span::unknown(),
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
@ -328,11 +441,9 @@ pub fn create_column(
.map(|v| match v {
Some(nanoseconds) => Value::Duration {
val: nanoseconds,
span: Span::unknown(),
},
None => Value::Nothing {
span: Span::unknown(),
span,
},
None => Value::Nothing { span },
})
.collect::<Vec<Value>>();
@ -345,29 +456,9 @@ pub fn create_column(
}
}
fn column_from_casted<T>(casted: &ChunkedArray<T>, from_row: usize, size: usize) -> Column
where
T: PolarsNumericType,
T::Native: Into<Value>,
{
let values = casted
.into_iter()
.skip(from_row)
.take(size)
.map(|v| match v {
Some(a) => a.into(),
None => Value::Nothing {
span: Span::unknown(),
},
})
.collect::<Vec<Value>>();
Column::new(casted.name().into(), values)
}
// Adds a separator to the vector of values using the column names from the
// dataframe to create the Values Row
pub fn add_separator(values: &mut Vec<Value>, df: &DataFrame) {
pub fn add_separator(values: &mut Vec<Value>, df: &DataFrame, span: Span) {
let mut cols = vec![];
let mut vals = vec![];
@ -375,15 +466,11 @@ pub fn add_separator(values: &mut Vec<Value>, df: &DataFrame) {
cols.push(name.to_string());
vals.push(Value::String {
val: "...".into(),
span: Span::unknown(),
span,
})
}
let extra_record = Value::Record {
cols,
vals,
span: Span::unknown(),
};
let extra_record = Value::Record { cols, vals, span };
values.push(extra_record);
}

View File

@ -29,7 +29,7 @@ impl CustomValue for NuDataFrame {
}
fn to_base_value(&self, span: Span) -> Result<Value, ShellError> {
let vals = self.print()?;
let vals = self.print(span)?;
Ok(Value::List { vals, span })
}

View File

@ -37,7 +37,7 @@ impl Display for DataFrameValue {
impl Default for DataFrameValue {
fn default() -> Self {
Self(Value::Nothing {
span: Span::unknown(),
span: Span { start: 0, end: 0 },
})
}
}
@ -178,15 +178,15 @@ impl NuDataFrame {
Value::CustomValue { val, span } => match val.as_any().downcast_ref::<NuDataFrame>() {
Some(df) => Ok(NuDataFrame(df.0.clone())),
None => Err(ShellError::CantConvert(
"Dataframe not found".into(),
"value is not a dataframe".into(),
"dataframe".into(),
"non-dataframe".into(),
span,
)),
},
_ => Err(ShellError::CantConvert(
"Dataframe not found".into(),
"value is not a dataframe".into(),
value.span()?,
x => Err(ShellError::CantConvert(
"dataframe".into(),
x.get_type().to_string(),
x.span()?,
)),
}
}
@ -239,8 +239,8 @@ impl NuDataFrame {
}
pub fn get_value(&self, row: usize, span: Span) -> Result<Value, ShellError> {
let series = self.as_series(Span::unknown())?;
let column = conversion::create_column(&series, row, row + 1)?;
let series = self.as_series(span)?;
let column = conversion::create_column(&series, row, row + 1, span)?;
if column.len() == 0 {
Err(ShellError::AccessBeyondEnd(series.len(), span))
@ -254,44 +254,49 @@ impl NuDataFrame {
}
// Print is made out a head and if the dataframe is too large, then a tail
pub fn print(&self) -> Result<Vec<Value>, ShellError> {
pub fn print(&self, span: Span) -> Result<Vec<Value>, ShellError> {
let df = &self.0;
let size: usize = 20;
if df.height() > size {
let sample_size = size / 2;
let mut values = self.head(Some(sample_size))?;
conversion::add_separator(&mut values, df);
let mut values = self.head(Some(sample_size), span)?;
conversion::add_separator(&mut values, df, span);
let remaining = df.height() - sample_size;
let tail_size = remaining.min(sample_size);
let mut tail_values = self.tail(Some(tail_size))?;
let mut tail_values = self.tail(Some(tail_size), span)?;
values.append(&mut tail_values);
Ok(values)
} else {
Ok(self.head(Some(size))?)
Ok(self.head(Some(size), span)?)
}
}
pub fn head(&self, rows: Option<usize>) -> Result<Vec<Value>, ShellError> {
pub fn head(&self, rows: Option<usize>, span: Span) -> Result<Vec<Value>, ShellError> {
let to_row = rows.unwrap_or(5);
let values = self.to_rows(0, to_row)?;
let values = self.to_rows(0, to_row, span)?;
Ok(values)
}
pub fn tail(&self, rows: Option<usize>) -> Result<Vec<Value>, ShellError> {
pub fn tail(&self, rows: Option<usize>, span: Span) -> Result<Vec<Value>, ShellError> {
let df = &self.0;
let to_row = df.height();
let size = rows.unwrap_or(5);
let from_row = to_row.saturating_sub(size);
let values = self.to_rows(from_row, to_row)?;
let values = self.to_rows(from_row, to_row, span)?;
Ok(values)
}
pub fn to_rows(&self, from_row: usize, to_row: usize) -> Result<Vec<Value>, ShellError> {
pub fn to_rows(
&self,
from_row: usize,
to_row: usize,
span: Span,
) -> Result<Vec<Value>, ShellError> {
let df = &self.0;
let upper_row = to_row.min(df.height());
@ -301,7 +306,7 @@ impl NuDataFrame {
.get_columns()
.iter()
.map(
|col| match conversion::create_column(col, from_row, upper_row) {
|col| match conversion::create_column(col, from_row, upper_row, span) {
Ok(col) => {
size = col.len();
Ok(col)
@ -327,17 +332,11 @@ impl NuDataFrame {
match col.next() {
Some(v) => vals.push(v),
None => vals.push(Value::Nothing {
span: Span::unknown(),
}),
None => vals.push(Value::Nothing { span }),
};
}
Value::Record {
cols,
vals,
span: Span::unknown(),
}
Value::Record { cols, vals, span }
})
.collect::<Vec<Value>>();

View File

@ -33,12 +33,21 @@ impl Command for WithColumn {
"[[a b]; [1 2] [3 4]] | dfr to-df | dfr with-column ([5 6] | dfr to-df) --name c",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![1.into(), 3.into()]),
Column::new("b".to_string(), vec![2.into(), 4.into()]),
Column::new("c".to_string(), vec![5.into(), 6.into()]),
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(3)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(4)],
),
Column::new(
"c".to_string(),
vec![Value::test_int(5), Value::test_int(6)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::unknown()),
.into_value(Span::test_data()),
),
}]
}

View File

@ -52,7 +52,7 @@ impl Command for SubCommand {
example: "date format '%Y-%m-%d'",
result: Some(Value::String {
val: Local::now().format("%Y-%m-%d").to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -60,7 +60,7 @@ impl Command for SubCommand {
example: r#"date format "%Y-%m-%d %H:%M:%S""#,
result: Some(Value::String {
val: Local::now().format("%Y-%m-%d %H:%M:%S").to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -68,7 +68,7 @@ impl Command for SubCommand {
example: r#""2021-10-22 20:00:12 +01:00" | date format "%Y-%m-%d""#,
result: Some(Value::String {
val: "2021-10-22".into(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
]
@ -81,8 +81,11 @@ fn format_helper(value: Value, formatter: &Spanned<String>, span: Span) -> Value
val: val.format(formatter.item.as_str()).to_string(),
span,
},
Value::String { val, span: _ } => {
let dt = parse_date_from_string(val);
Value::String {
val,
span: val_span,
} => {
let dt = parse_date_from_string(val, val_span);
match dt {
Ok(x) => Value::String {
val: x.format(formatter.item.as_str()).to_string(),
@ -101,7 +104,7 @@ fn format_helper(value: Value, formatter: &Spanned<String>, span: Span) -> Value
span,
}
}
_ => unsupported_input_error(),
_ => unsupported_input_error(span),
}
}

View File

@ -38,7 +38,7 @@ impl Command for SubCommand {
example: "date humanize",
result: Some(Value::String {
val: "now".to_string(),
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -59,8 +59,11 @@ fn helper(value: Value, head: Span) -> Value {
span: head,
}
}
Value::String { val, span: _ } => {
let dt = parse_date_from_string(val);
Value::String {
val,
span: val_span,
} => {
let dt = parse_date_from_string(val, val_span);
match dt {
Ok(x) => Value::String {
val: humanize_date(x),
@ -76,7 +79,7 @@ fn helper(value: Value, head: Span) -> Value {
_ => Value::Error {
error: ShellError::UnsupportedInput(
String::from("Date cannot be parsed / date format is not supported"),
Span::unknown(),
head,
),
},
}

View File

@ -47,7 +47,7 @@ impl Command for SubCommand {
description: "Print the date in a structured table.",
example: " '2020-04-12 22:10:57 +0200' | date to-table",
result: {
let span = Span::unknown();
let span = Span::test_data();
let cols = vec![
"year".into(),
"month".into(),
@ -136,8 +136,11 @@ fn parse_date_into_table(date: Result<DateTime<FixedOffset>, Value>, head: Span)
fn helper(val: Value, head: Span) -> Value {
match val {
Value::String { val, span: _ } => {
let date = parse_date_from_string(val);
Value::String {
val,
span: val_span,
} => {
let date = parse_date_from_string(val, val_span);
parse_date_into_table(date, head)
}
Value::Nothing { span: _ } => {
@ -146,7 +149,7 @@ fn helper(val: Value, head: Span) -> Value {
parse_date_into_table(Ok(n), head)
}
Value::Date { val, span: _ } => parse_date_into_table(Ok(val), head),
_ => unsupported_input_error(),
_ => unsupported_input_error(head),
}
}

View File

@ -78,7 +78,7 @@ impl Command for SubCommand {
Some(Value::Date {
val: dt,
span: Span::unknown(),
span: Span::test_data(),
})
},
},
@ -89,8 +89,11 @@ impl Command for SubCommand {
fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> Value {
match value {
Value::Date { val, span: _ } => _to_timezone(val, timezone, head),
Value::String { val, span: _ } => {
let time = parse_date_from_string(val);
Value::String {
val,
span: val_span,
} => {
let time = parse_date_from_string(val, val_span);
match time {
Ok(dt) => _to_timezone(dt, timezone, head),
Err(e) => e,
@ -101,7 +104,7 @@ fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> Value {
let dt = Local::now();
_to_timezone(dt.with_timezone(dt.offset()), timezone, head)
}
_ => unsupported_input_error(),
_ => unsupported_input_error(head),
}
}

View File

@ -1,7 +1,7 @@
use chrono::{DateTime, FixedOffset};
use nu_protocol::{ShellError, Span, Value};
pub fn unsupported_input_error() -> Value {
pub fn unsupported_input_error(span: Span) -> Value {
Value::Error {
error: ShellError::UnsupportedInput(
String::from(
@ -11,12 +11,12 @@ pub fn unsupported_input_error() -> Value {
* rfc3339 -- 2020-04-12T22:10:57+02:00 \n
* rfc2822 -- Tue, 1 Jul 2003 10:52:37 +0200",
),
Span::unknown(),
span,
),
}
}
pub fn parse_date_from_string(input: String) -> Result<DateTime<FixedOffset>, Value> {
pub fn parse_date_from_string(input: String, span: Span) -> Result<DateTime<FixedOffset>, Value> {
let datetime = DateTime::parse_from_str(&input, "%Y-%m-%d %H:%M:%S %z"); // "2020-04-12 22:10:57 +02:00";
match datetime {
Ok(x) => Ok(x),
@ -32,7 +32,7 @@ pub fn parse_date_from_string(input: String) -> Result<DateTime<FixedOffset>, Va
let datetime = DateTime::parse_from_rfc2822(&input); // "Tue, 1 Jul 2003 10:52:37 +0200";
match datetime {
Ok(x) => Ok(x),
Err(_) => Err(unsupported_input_error()),
Err(_) => Err(unsupported_input_error(span)),
}
}
}

View File

@ -1,14 +1,20 @@
#[cfg(test)]
use nu_engine::eval_block;
#[cfg(test)]
use nu_parser::parse;
#[cfg(test)]
use nu_protocol::{
engine::{Command, EngineState, Stack, StateWorkingSet},
PipelineData, Span, Value, CONFIG_VARIABLE_ID,
};
#[cfg(test)]
use crate::To;
#[cfg(test)]
use super::{Ansi, Date, From, Into, Math, Path, Random, Split, Str, StrCollect, Url};
#[cfg(test)]
pub fn test_examples(cmd: impl Command + 'static) {
let examples = cmd.examples();
let mut engine_state = Box::new(EngineState::new());
@ -68,7 +74,7 @@ pub fn test_examples(cmd: impl Command + 'static) {
Value::Record {
cols: vec![],
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
);
@ -76,11 +82,11 @@ pub fn test_examples(cmd: impl Command + 'static) {
&engine_state,
&mut stack,
&block,
PipelineData::new(Span::unknown()),
PipelineData::new(Span::test_data()),
) {
Err(err) => panic!("test eval error in `{}`: {:?}", example.example, err),
Ok(result) => {
let result = result.into_value(Span::unknown());
let result = result.into_value(Span::test_data());
println!("input: {}", example.example);
println!("result: {:?}", result);
println!("done: {:?}", start.elapsed());

View File

@ -2,7 +2,7 @@ use nu_engine::eval_block;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape,
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value,
};
#[derive(Clone)]
@ -28,18 +28,16 @@ impl Command for All {
}
fn examples(&self) -> Vec<Example> {
use nu_protocol::Value;
vec![
Example {
description: "Find if services are running",
example: "echo [[status]; [UP] [UP]] | all? status == UP",
result: Some(Value::from(true)),
result: Some(Value::test_bool(true)),
},
Example {
description: "Check that all values are even",
example: "echo [2 4 6 8] | all? ($it mod 2) == 0",
result: Some(Value::from(true)),
result: Some(Value::test_bool(true)),
},
]
}
@ -65,9 +63,8 @@ impl Command for All {
let ctrlc = engine_state.ctrlc.clone();
let engine_state = engine_state.clone();
Ok(input
.into_interruptible_iter(ctrlc)
.all(move |value| {
Ok(Value::Bool {
val: input.into_interruptible_iter(ctrlc).all(move |value| {
if let Some(var_id) = var_id {
stack.add_var(var_id, value);
}
@ -76,8 +73,10 @@ impl Command for All {
.map_or(false, |pipeline_data| {
pipeline_data.into_value(span).is_true()
})
})
.into_pipeline_data())
}),
span,
}
.into_pipeline_data())
}
}

View File

@ -2,7 +2,7 @@ use nu_engine::eval_block;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape,
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value,
};
#[derive(Clone)]
@ -28,18 +28,16 @@ impl Command for Any {
}
fn examples(&self) -> Vec<Example> {
use nu_protocol::Value;
vec![
Example {
description: "Find if a service is not running",
example: "echo [[status]; [UP] [DOWN] [UP]] | any? status == DOWN",
result: Some(Value::from(true)),
result: Some(Value::test_bool(true)),
},
Example {
description: "Check if any of the values is odd",
example: "echo [2 4 1 6 8] | any? ($it mod 2) == 1",
result: Some(Value::from(true)),
result: Some(Value::test_bool(true)),
},
]
}
@ -65,9 +63,8 @@ impl Command for Any {
let ctrlc = engine_state.ctrlc.clone();
let engine_state = engine_state.clone();
Ok(input
.into_interruptible_iter(ctrlc)
.any(move |value| {
Ok(Value::Bool {
val: input.into_interruptible_iter(ctrlc).any(move |value| {
if let Some(var_id) = var_id {
stack.add_var(var_id, value);
}
@ -76,8 +73,10 @@ impl Command for Any {
.map_or(false, |pipeline_data| {
pipeline_data.into_value(span).is_true()
})
})
.into_pipeline_data())
}),
span,
}
.into_pipeline_data())
}
}

View File

@ -37,7 +37,7 @@ impl Command for Append {
Value::test_int(3),
Value::test_int(4),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -51,7 +51,7 @@ impl Command for Append {
Value::test_int(3),
Value::test_int(4),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -66,7 +66,7 @@ impl Command for Append {
Value::test_int(4),
Value::test_string("shell"),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -62,13 +62,14 @@ fn getcol(
PipelineData::Value(
Value::List {
vals: input_vals,
span: _,
span,
},
..,
) => {
let input_cols = get_input_cols(input_vals);
Ok(input_cols
.into_iter()
.map(move |x| Value::String { val: x, span })
.into_pipeline_data(engine_state.ctrlc.clone()))
}
PipelineData::Stream(stream, ..) => {
@ -77,6 +78,7 @@ fn getcol(
Ok(input_cols
.into_iter()
.map(move |x| Value::String { val: x, span })
.into_pipeline_data(engine_state.ctrlc.clone()))
}
PipelineData::Value(_v, ..) => {

View File

@ -68,7 +68,7 @@ fn dropcol(
let mut output = vec![];
let input_cols = get_input_cols(input_vals.clone());
let kc = get_keep_columns(input_cols, columns);
keep_columns = get_cellpath_columns(kc);
keep_columns = get_cellpath_columns(kc, span);
for input_val in input_vals {
let mut cols = vec![];
@ -92,7 +92,7 @@ fn dropcol(
let v: Vec<_> = stream.into_iter().collect();
let input_cols = get_input_cols(v.clone());
let kc = get_keep_columns(input_cols, columns);
keep_columns = get_cellpath_columns(kc);
keep_columns = get_cellpath_columns(kc, span);
for input_val in v {
let mut cols = vec![];
@ -134,10 +134,9 @@ fn get_input_cols(input: Vec<Value>) -> Vec<String> {
}
}
fn get_cellpath_columns(keep_cols: Vec<String>) -> Vec<CellPath> {
fn get_cellpath_columns(keep_cols: Vec<String>, span: Span) -> Vec<CellPath> {
let mut output = vec![];
for keep_col in keep_cols {
let span = Span::unknown();
let val = Value::String {
val: keep_col,
span,

View File

@ -36,7 +36,7 @@ impl Command for Drop {
description: "Remove the last item of a list/table",
result: Some(Value::List {
vals: vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -49,7 +49,7 @@ impl Command for Drop {
Value::test_int(2),
Value::test_int(3),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -57,7 +57,7 @@ impl Command for Drop {
description: "Remove the last two items of a list/table",
result: Some(Value::List {
vals: vec![Value::test_int(0), Value::test_int(1)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -31,7 +31,7 @@ impl Command for DropNth {
description: "Drop the first, second, and third row",
result: Some(Value::List {
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -39,7 +39,7 @@ impl Command for DropNth {
description: "Drop the first, second, and third row",
result: Some(Value::List {
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -47,7 +47,7 @@ impl Command for DropNth {
description: "Drop rows 0 2 4",
result: Some(Value::List {
vals: vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -55,7 +55,7 @@ impl Command for DropNth {
description: "Drop rows 2 0 4",
result: Some(Value::List {
vals: vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -33,15 +33,15 @@ impl Command for Each {
let stream_test_1 = vec![
Value::Int {
val: 2,
span: Span::unknown(),
span: Span::test_data(),
},
Value::Int {
val: 4,
span: Span::unknown(),
span: Span::test_data(),
},
Value::Int {
val: 6,
span: Span::unknown(),
span: Span::test_data(),
},
];
@ -50,7 +50,7 @@ impl Command for Each {
description: "Multiplies elements in list",
result: Some(Value::List {
vals: stream_test_1,
span: Span::unknown(),
span: Span::test_data(),
}),
}]
}

View File

@ -50,7 +50,7 @@ impl Command for First {
example: "[1 2 3] | first 2",
result: Some(Value::List {
vals: vec![Value::test_int(1), Value::test_int(2)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -35,7 +35,7 @@ impl Command for Get {
let cell_path: CellPath = call.req(engine_state, stack, 0)?;
input
.follow_cell_path(&cell_path.members)
.follow_cell_path(&cell_path.members, call.head)
.map(|x| x.into_pipeline_data())
}
}

View File

@ -35,24 +35,24 @@ impl Command for Keep {
vals: vec![
Value::Record {
cols: vec!["editions".to_owned()],
vals: vec![Value::from(2015)],
span: Span::unknown(),
vals: vec![Value::test_int(2015)],
span: Span::test_data(),
},
Value::Record {
cols: vec!["editions".to_owned()],
vals: vec![Value::from(2018)],
span: Span::unknown(),
vals: vec![Value::test_int(2018)],
span: Span::test_data(),
},
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
description: "Keep the first value",
example: "echo [2 4 6 8] | keep",
result: Some(Value::List {
vals: vec![Value::from(2)],
span: Span::unknown(),
vals: vec![Value::test_int(2)],
span: Span::test_data(),
}),
},
]

View File

@ -33,8 +33,8 @@ impl Command for KeepUntil {
description: "Keep until the element is positive",
example: "echo [-1 -2 9 1] | keep until $it > 0",
result: Some(Value::List {
vals: vec![Value::from(-1), Value::from(-2)],
span: Span::unknown(),
vals: vec![Value::test_int(-1), Value::test_int(-2)],
span: Span::test_data(),
}),
}]
}

View File

@ -33,8 +33,8 @@ impl Command for KeepWhile {
description: "Keep while the element is negative",
example: "echo [-1 -2 9 1] | keep while $it < 0",
result: Some(Value::List {
vals: vec![Value::from(-1), Value::from(-2)],
span: Span::unknown(),
vals: vec![Value::test_int(-1), Value::test_int(-2)],
span: Span::test_data(),
}),
}]
}

View File

@ -35,7 +35,7 @@ impl Command for Last {
description: "Get the last 2 items",
result: Some(Value::List {
vals: vec![Value::test_int(2), Value::test_int(3)],
span: Span::unknown(),
span: Span::test_data(),
}),
}]
}

View File

@ -36,7 +36,7 @@ impl Command for Nth {
Value::test_string("sarah"),
Value::test_int(2),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -44,7 +44,7 @@ impl Command for Nth {
description: "Get the first, second, and third row",
result: Some(Value::List {
vals: vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -52,7 +52,7 @@ impl Command for Nth {
description: "Skip the first, second, and third row",
result: Some(Value::List {
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -60,7 +60,7 @@ impl Command for Nth {
description: "Get the first, third, and fifth row",
result: Some(Value::List {
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(4)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -68,7 +68,7 @@ impl Command for Nth {
description: "Get the first, third, and fifth row",
result: Some(Value::List {
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(4)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -37,7 +37,7 @@ impl Command for Prepend {
Value::test_int(3),
Value::test_int(4),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -51,7 +51,7 @@ impl Command for Prepend {
Value::test_int(3),
Value::test_int(4),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -67,7 +67,7 @@ impl Command for Prepend {
Value::test_int(4),
Value::test_string("shell"),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -36,7 +36,7 @@ impl Command for Range {
description: "Get the last 2 items",
result: Some(Value::List {
vals: vec![Value::test_int(4), Value::test_int(5)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -44,7 +44,7 @@ impl Command for Range {
description: "Get the last 2 items",
result: Some(Value::List {
vals: vec![Value::test_int(4), Value::test_int(5)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -52,7 +52,7 @@ impl Command for Range {
description: "Get the next to last 2 items",
result: Some(Value::List {
vals: vec![Value::test_int(3), Value::test_int(4)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -64,7 +64,7 @@ fn reject(
let mut output = vec![];
let input_cols = get_input_cols(input_vals.clone());
let kc = get_keep_columns(input_cols, columns);
keep_columns = get_cellpath_columns(kc);
keep_columns = get_cellpath_columns(kc, span);
for input_val in input_vals {
let mut cols = vec![];
@ -88,7 +88,7 @@ fn reject(
let v: Vec<_> = stream.into_iter().collect();
let input_cols = get_input_cols(v.clone());
let kc = get_keep_columns(input_cols, columns);
keep_columns = get_cellpath_columns(kc);
keep_columns = get_cellpath_columns(kc, span);
for input_val in v {
let mut cols = vec![];
@ -130,10 +130,9 @@ fn get_input_cols(input: Vec<Value>) -> Vec<String> {
}
}
fn get_cellpath_columns(keep_cols: Vec<String>) -> Vec<CellPath> {
fn get_cellpath_columns(keep_cols: Vec<String>, span: Span) -> Vec<CellPath> {
let mut output = vec![];
for keep_col in keep_cols {
let span = Span::unknown();
let val = Value::String {
val: keep_col,
span,

View File

@ -32,7 +32,7 @@ impl Command for Reverse {
Value::test_int(1),
Value::test_int(0),
],
span: Span::unknown(),
span: Span::test_data(),
}),
}]
}

View File

@ -184,9 +184,9 @@ fn select(
// let actual = select(
// Tag::unknown(),
// vec![
// ColumnPath::build(&"col_none".to_string().spanned(Span::unknown())),
// ColumnPath::build(&"col_foo".to_string().spanned(Span::unknown())),
// ColumnPath::build(&"col_bar".to_string().spanned(Span::unknown())),
// ColumnPath::build(&"col_none".to_string().spanned(Span::test_data())),
// ColumnPath::build(&"col_foo".to_string().spanned(Span::test_data())),
// ColumnPath::build(&"col_bar".to_string().spanned(Span::test_data())),
// ],
// input.into(),
// );

View File

@ -34,18 +34,18 @@ impl Command for Skip {
result: Some(Value::List {
vals: vec![Value::Record {
cols: vec!["editions".to_owned()],
vals: vec![Value::from(2021)],
span: Span::unknown(),
vals: vec![Value::test_int(2021)],
span: Span::test_data(),
}],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
description: "Skip the first value",
example: "echo [2 4 6 8] | skip",
result: Some(Value::List {
vals: vec![Value::from(4), Value::from(6), Value::from(8)],
span: Span::unknown(),
vals: vec![Value::test_int(4), Value::test_int(6), Value::test_int(8)],
span: Span::test_data(),
}),
},
]

View File

@ -33,8 +33,8 @@ impl Command for SkipUntil {
description: "Skip until the element is positive",
example: "echo [-2 0 2 -1] | skip until $it > 0",
result: Some(Value::List {
vals: vec![Value::from(2), Value::from(-1)],
span: Span::unknown(),
vals: vec![Value::test_int(2), Value::test_int(-1)],
span: Span::test_data(),
}),
}]
}

View File

@ -33,8 +33,8 @@ impl Command for SkipWhile {
description: "Skip while the element is negative",
example: "echo [-2 0 2 -1] | skip while $it < 0",
result: Some(Value::List {
vals: vec![Value::from(0), Value::from(2), Value::from(-1)],
span: Span::unknown(),
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(-1)],
span: Span::test_data(),
}),
}]
}

View File

@ -52,7 +52,7 @@ impl Command for Uniq {
example: "[2 3 3 4] | uniq",
result: Some(Value::List {
vals: vec![Value::test_int(2), Value::test_int(3), Value::test_int(4)],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -70,7 +70,7 @@ impl Command for Uniq {
example: "['hello' 'goodbye' 'Hello'] | uniq -i",
result: Some(Value::List {
vals: vec![Value::test_string("hello"), Value::test_string("goodbye")],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -81,15 +81,15 @@ impl Command for Uniq {
Value::Record {
cols: vec!["value".to_string(), "count".to_string()],
vals: vec![Value::test_int(1), Value::test_int(1)],
span: Span::unknown(),
span: Span::test_data(),
},
Value::Record {
cols: vec!["value".to_string(), "count".to_string()],
vals: vec![Value::test_int(2), Value::test_int(2)],
span: Span::unknown(),
span: Span::test_data(),
},
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -47,11 +47,11 @@ impl Command for Update {
vec![Example {
description: "Update a column value",
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
result: Some(Value::Record { cols: vec!["name".into(), "stars".into()], vals: vec![Value::test_string("Nushell"), Value::test_int(5)], span: Span::unknown()}),
result: Some(Value::Record { cols: vec!["name".into(), "stars".into()], vals: vec![Value::test_string("Nushell"), Value::test_int(5)], span: Span::test_data()}),
}, Example {
description: "Use in block form for more involved updating logic",
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { get authors | str collect ',' }",
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["project".into(), "authors".into()], vals: vec![Value::test_string("nu"), Value::test_string("Andrés,JT,Yehuda")], span: Span::unknown()}], span: Span::unknown()}),
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["project".into(), "authors".into()], vals: vec![Value::test_string("nu"), Value::test_string("Andrés,JT,Yehuda")], span: Span::test_data()}], span: Span::test_data()}),
}]
}
}

View File

@ -70,22 +70,22 @@ Test' | from eml",
Value::Record {
cols: vec!["Name".to_string(), "Address".to_string()],
vals: vec![
Value::nothing(Span::unknown()),
Value::nothing(Span::test_data()),
Value::test_string("test@email.com"),
],
span: Span::unknown(),
span: Span::test_data(),
},
Value::Record {
cols: vec!["Name".to_string(), "Address".to_string()],
vals: vec![
Value::nothing(Span::unknown()),
Value::nothing(Span::test_data()),
Value::test_string("someone@somewhere.com"),
],
span: Span::unknown(),
span: Span::test_data(),
},
Value::test_string("Test"),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -107,22 +107,22 @@ Test' | from eml -b 1",
Value::Record {
cols: vec!["Name".to_string(), "Address".to_string()],
vals: vec![
Value::nothing(Span::unknown()),
Value::nothing(Span::test_data()),
Value::test_string("test@email.com"),
],
span: Span::unknown(),
span: Span::test_data(),
},
Value::Record {
cols: vec!["Name".to_string(), "Address".to_string()],
vals: vec![
Value::nothing(Span::unknown()),
Value::nothing(Span::test_data()),
Value::test_string("someone@somewhere.com"),
],
span: Span::unknown(),
span: Span::test_data(),
},
Value::test_string("T"),
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -57,36 +57,36 @@ END:VCALENDAR' | from ics",
vals: vec![
Value::List {
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
Value::List {
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
Value::List {
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
Value::List {
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
Value::List {
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
Value::List {
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
Value::List {
vals: vec![],
span: Span::unknown(),
span: Span::test_data(),
},
],
span: Span::unknown(),
span: Span::test_data(),
}],
span: Span::unknown(),
span: Span::test_data(),
}),
}]
}

View File

@ -34,16 +34,16 @@ b=2' | from ini",
vals: vec![
Value::String {
val: "1".to_string(),
span: Span::unknown(),
span: Span::test_data(),
},
Value::String {
val: "2".to_string(),
span: Span::unknown(),
span: Span::test_data(),
},
],
span: Span::unknown(),
span: Span::test_data(),
}],
span: Span::unknown(),
span: Span::test_data(),
}),
}]
}

View File

@ -32,9 +32,9 @@ impl Command for FromJson {
cols: vec!["a".to_string()],
vals: vec![Value::Int {
val: 1,
span: Span::unknown(),
span: Span::test_data(),
}],
span: Span::unknown(),
span: Span::test_data(),
}),
},
Example {
@ -45,23 +45,23 @@ impl Command for FromJson {
vals: vec![
Value::Int {
val: 1,
span: Span::unknown(),
span: Span::test_data(),
},
Value::List {
vals: vec![
Value::Int {
val: 1,
span: Span::unknown(),
span: Span::test_data(),
},
Value::Int {
val: 2,
span: Span::unknown(),
span: Span::test_data(),
},
],
span: Span::unknown(),
span: Span::test_data(),
},
],
span: Span::unknown(),
span: Span::test_data(),
}),
},
]

View File

@ -43,7 +43,7 @@ impl Command for FromOds {
let sel_sheets = if let Some(Value::List { vals: columns, .. }) =
call.get_flag(engine_state, stack, "sheets")?
{
convert_columns(columns.as_slice())?
convert_columns(columns.as_slice(), call.head)?
} else {
vec![]
};
@ -67,14 +67,14 @@ impl Command for FromOds {
}
}
fn convert_columns(columns: &[Value]) -> Result<Vec<String>, ShellError> {
fn convert_columns(columns: &[Value], span: Span) -> Result<Vec<String>, ShellError> {
let res = columns
.iter()
.map(|value| match &value {
Value::String { val: s, .. } => Ok(s.clone()),
_ => Err(ShellError::IncompatibleParametersSingle(
"Incorrect column format, Only string as column name".to_string(),
value.span().unwrap_or_else(|_| Span::unknown()),
value.span().unwrap_or(span),
)),
})
.collect::<Result<Vec<String>, _>>()?;
@ -82,7 +82,7 @@ fn convert_columns(columns: &[Value]) -> Result<Vec<String>, ShellError> {
Ok(res)
}
fn collect_binary(input: PipelineData) -> Result<Vec<u8>, ShellError> {
fn collect_binary(input: PipelineData, span: Span) -> Result<Vec<u8>, ShellError> {
let mut bytes = vec![];
let mut values = input.into_iter();
@ -94,7 +94,7 @@ fn collect_binary(input: PipelineData) -> Result<Vec<u8>, ShellError> {
Some(x) => {
return Err(ShellError::UnsupportedInput(
"Expected binary from pipeline".to_string(),
x.span().unwrap_or_else(|_| Span::unknown()),
x.span().unwrap_or(span),
))
}
None => break,
@ -109,7 +109,7 @@ fn from_ods(
head: Span,
sel_sheets: Vec<String>,
) -> Result<PipelineData, ShellError> {
let bytes = collect_binary(input)?;
let bytes = collect_binary(input, head)?;
let buf: Cursor<Vec<u8>> = Cursor::new(bytes);
let mut ods = Ods::<_>::new(buf)
.map_err(|_| ShellError::UnsupportedInput("Could not load ods file".to_string(), head))?;

View File

@ -43,13 +43,13 @@ impl Command for FromSsv {
example: r#"'FOO BAR
1 2' | from ssv"#,
description: "Converts ssv formatted string to table",
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["FOO".to_string(), "BAR".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::unknown() }, Value::String { val: "2".to_string(), span: Span::unknown() }], span: Span::unknown() }], span: Span::unknown() }),
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["FOO".to_string(), "BAR".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::test_data() }, Value::String { val: "2".to_string(), span: Span::test_data() }], span: Span::test_data() }], span: Span::test_data() }),
}, Example {
example: r#"'FOO BAR
1 2' | from ssv -n"#,
description: "Converts ssv formatted string to table but not treating the first row as column names",
result: Some(
Value::List { vals: vec![Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "FOO".to_string(), span: Span::unknown() }, Value::String { val: "BAR".to_string(), span: Span::unknown() }], span: Span::unknown() }, Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::unknown() }, Value::String { val: "2".to_string(), span: Span::unknown() }], span: Span::unknown() }], span: Span::unknown() }),
Value::List { vals: vec![Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "FOO".to_string(), span: Span::test_data() }, Value::String { val: "BAR".to_string(), span: Span::test_data() }], span: Span::test_data() }, Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::test_data() }, Value::String { val: "2".to_string(), span: Span::test_data() }], span: Span::test_data() }], span: Span::test_data() }),
}]
}

Some files were not shown because too many files have changed in this diff Show More