From 2883d6cd1e5ca8563f3d8b8fc9623c4b54541248 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sun, 19 Dec 2021 18:46:13 +1100 Subject: [PATCH] Remove Span::unknown (#525) --- .../nu-command/src/conversions/into/binary.rs | 8 +- .../src/conversions/into/datetime.rs | 26 +- .../src/conversions/into/decimal.rs | 10 +- .../src/conversions/into/filesize.rs | 8 +- crates/nu-command/src/conversions/into/int.rs | 12 +- .../nu-command/src/conversions/into/string.rs | 14 +- crates/nu-command/src/core_commands/for_.rs | 8 +- crates/nu-command/src/core_commands/use_.rs | 4 +- .../nu-command/src/core_commands/version.rs | 34 +-- crates/nu-command/src/dataframe/append.rs | 38 ++- crates/nu-command/src/dataframe/column.rs | 6 +- crates/nu-command/src/dataframe/describe.rs | 64 ++--- crates/nu-command/src/dataframe/drop.rs | 4 +- crates/nu-command/src/dataframe/drop_nulls.rs | 28 ++- crates/nu-command/src/dataframe/dtypes.rs | 6 +- .../src/dataframe/series/all_false.rs | 8 +- .../src/dataframe/series/all_true.rs | 8 +- .../src/dataframe/series/arg_max.rs | 6 +- .../src/dataframe/series/arg_min.rs | 6 +- .../src/dataframe/series/cumulative.rs | 12 +- .../src/dataframe/series/date/get_day.rs | 6 +- .../src/dataframe/series/date/get_hour.rs | 6 +- .../src/dataframe/series/date/get_minute.rs | 6 +- .../src/dataframe/series/date/get_month.rs | 6 +- .../dataframe/series/date/get_nanosecond.rs | 6 +- .../src/dataframe/series/date/get_ordinal.rs | 6 +- .../src/dataframe/series/date/get_second.rs | 6 +- .../src/dataframe/series/date/get_week.rs | 6 +- .../src/dataframe/series/date/get_weekday.rs | 6 +- .../src/dataframe/series/date/get_year.rs | 6 +- .../src/dataframe/series/indexes/arg_sort.rs | 22 +- .../src/dataframe/series/indexes/arg_true.rs | 6 +- .../dataframe/series/indexes/arg_unique.rs | 6 +- .../dataframe/series/indexes/set_with_idx.rs | 11 +- .../dataframe/series/masks/is_duplicated.rs | 18 +- .../src/dataframe/series/masks/is_in.rs | 16 +- .../src/dataframe/series/masks/is_not_null.rs | 11 +- .../src/dataframe/series/masks/is_null.rs | 11 +- .../src/dataframe/series/masks/is_unique.rs | 18 +- .../src/dataframe/series/masks/not.rs | 10 +- .../src/dataframe/series/masks/set.rs | 10 +- .../nu-command/src/dataframe/series/n_null.rs | 4 +- .../src/dataframe/series/n_unique.rs | 4 +- .../nu-command/src/dataframe/series/rename.rs | 11 +- .../src/dataframe/series/rolling.rs | 20 +- .../nu-command/src/dataframe/series/shift.rs | 6 +- .../dataframe/series/string/concatenate.rs | 8 +- .../src/dataframe/series/string/contains.rs | 10 +- .../src/dataframe/series/string/replace.rs | 10 +- .../dataframe/series/string/replace_all.rs | 10 +- .../dataframe/series/string/str_lengths.rs | 6 +- .../src/dataframe/series/string/str_slice.rs | 10 +- .../src/dataframe/series/string/strftime.rs | 8 +- .../dataframe/series/string/to_lowercase.rs | 10 +- .../dataframe/series/string/to_uppercase.rs | 10 +- .../nu-command/src/dataframe/series/unique.rs | 11 +- .../src/dataframe/series/value_counts.rs | 14 +- .../src/dataframe/test_dataframe.rs | 6 +- crates/nu-command/src/dataframe/to_df.rs | 48 ++-- .../values/nu_dataframe/conversion.rs | 225 ++++++++++++------ .../values/nu_dataframe/custom_value.rs | 2 +- .../src/dataframe/values/nu_dataframe/mod.rs | 55 +++-- .../nu-command/src/dataframe/with_column.rs | 17 +- crates/nu-command/src/date/format.rs | 15 +- crates/nu-command/src/date/humanize.rs | 11 +- crates/nu-command/src/date/to_table.rs | 11 +- crates/nu-command/src/date/to_timezone.rs | 11 +- crates/nu-command/src/date/utils.rs | 8 +- crates/nu-command/src/example_test.rs | 12 +- crates/nu-command/src/filters/all.rs | 19 +- crates/nu-command/src/filters/any.rs | 19 +- crates/nu-command/src/filters/append.rs | 6 +- crates/nu-command/src/filters/columns.rs | 4 +- crates/nu-command/src/filters/drop/column.rs | 7 +- crates/nu-command/src/filters/drop/command.rs | 6 +- crates/nu-command/src/filters/drop/nth.rs | 8 +- crates/nu-command/src/filters/each.rs | 8 +- crates/nu-command/src/filters/first.rs | 2 +- crates/nu-command/src/filters/get.rs | 2 +- crates/nu-command/src/filters/keep/command.rs | 14 +- crates/nu-command/src/filters/keep/until.rs | 4 +- crates/nu-command/src/filters/keep/while_.rs | 4 +- crates/nu-command/src/filters/last.rs | 2 +- crates/nu-command/src/filters/nth.rs | 10 +- crates/nu-command/src/filters/prepend.rs | 6 +- crates/nu-command/src/filters/range.rs | 6 +- crates/nu-command/src/filters/reject.rs | 7 +- crates/nu-command/src/filters/reverse.rs | 2 +- crates/nu-command/src/filters/select.rs | 6 +- crates/nu-command/src/filters/skip/command.rs | 10 +- crates/nu-command/src/filters/skip/until.rs | 4 +- crates/nu-command/src/filters/skip/while_.rs | 4 +- crates/nu-command/src/filters/uniq.rs | 10 +- crates/nu-command/src/filters/update.rs | 4 +- crates/nu-command/src/formats/from/eml.rs | 20 +- crates/nu-command/src/formats/from/ics.rs | 18 +- crates/nu-command/src/formats/from/ini.rs | 8 +- crates/nu-command/src/formats/from/json.rs | 14 +- crates/nu-command/src/formats/from/ods.rs | 12 +- crates/nu-command/src/formats/from/ssv.rs | 4 +- crates/nu-command/src/formats/from/toml.rs | 14 +- crates/nu-command/src/formats/from/url.rs | 2 +- crates/nu-command/src/formats/from/vcf.rs | 30 +-- crates/nu-command/src/formats/from/xlsx.rs | 12 +- crates/nu-command/src/formats/from/xml.rs | 26 +- crates/nu-command/src/formats/from/yaml.rs | 22 +- crates/nu-command/src/formats/to/delimited.rs | 18 +- crates/nu-command/src/formats/to/md.rs | 16 +- crates/nu-command/src/formats/to/toml.rs | 43 ++-- crates/nu-command/src/formats/to/url.rs | 2 +- crates/nu-command/src/hash/md5.rs | 10 +- crates/nu-command/src/hash/sha256.rs | 10 +- crates/nu-command/src/lib.rs | 1 + crates/nu-command/src/math/abs.rs | 4 +- crates/nu-command/src/math/avg.rs | 4 +- crates/nu-command/src/math/ceil.rs | 2 +- crates/nu-command/src/math/eval.rs | 11 +- crates/nu-command/src/math/floor.rs | 2 +- crates/nu-command/src/math/median.rs | 2 +- crates/nu-command/src/math/mode.rs | 2 +- crates/nu-command/src/math/reducers.rs | 6 +- crates/nu-command/src/math/round.rs | 10 +- crates/nu-command/src/math/sqrt.rs | 2 +- crates/nu-command/src/math/stddev.rs | 4 +- crates/nu-command/src/math/variance.rs | 6 +- crates/nu-command/src/network/url/host.rs | 2 +- crates/nu-command/src/network/url/path.rs | 2 +- crates/nu-command/src/network/url/query.rs | 2 +- crates/nu-command/src/network/url/scheme.rs | 2 +- crates/nu-command/src/path/basename.rs | 8 +- crates/nu-command/src/path/exists.rs | 4 +- crates/nu-command/src/path/join.rs | 4 +- crates/nu-command/src/path/split.rs | 4 +- .../nu-command/src/platform/ansi/gradient.rs | 2 +- crates/nu-command/src/platform/ansi/strip.rs | 2 +- crates/nu-command/src/strings/build_string.rs | 4 +- .../nu-command/src/strings/format/command.rs | 20 +- crates/nu-command/src/strings/parse.rs | 4 +- crates/nu-command/src/strings/size.rs | 20 +- crates/nu-command/src/strings/split/chars.rs | 2 +- .../nu-command/src/strings/str_/capitalize.rs | 12 +- .../src/strings/str_/case/camel_case.rs | 12 +- .../src/strings/str_/case/kebab_case.rs | 12 +- .../nu-command/src/strings/str_/case/mod.rs | 2 +- .../src/strings/str_/case/pascal_case.rs | 12 +- .../strings/str_/case/screaming_snake_case.rs | 12 +- .../src/strings/str_/case/snake_case.rs | 12 +- crates/nu-command/src/strings/str_/collect.rs | 4 +- .../nu-command/src/strings/str_/contains.rs | 28 +-- .../nu-command/src/strings/str_/downcase.rs | 22 +- .../nu-command/src/strings/str_/ends_with.rs | 6 +- .../src/strings/str_/find_replace.rs | 22 +- .../nu-command/src/strings/str_/index_of.rs | 38 +-- crates/nu-command/src/strings/str_/length.rs | 4 +- crates/nu-command/src/strings/str_/lpad.rs | 12 +- crates/nu-command/src/strings/str_/reverse.rs | 4 +- crates/nu-command/src/strings/str_/rpad.rs | 12 +- .../src/strings/str_/starts_with.rs | 8 +- .../nu-command/src/strings/str_/substring.rs | 6 +- .../src/strings/str_/trim/command.rs | 152 ++++++------ crates/nu-command/src/strings/str_/upcase.rs | 2 +- crates/nu-command/src/system/run_external.rs | 2 +- crates/nu-command/src/viewers/griddle.rs | 9 +- crates/nu-command/src/viewers/icons.rs | 8 +- crates/nu-command/src/viewers/table.rs | 6 +- crates/nu-engine/src/documentation.rs | 24 +- crates/nu-engine/src/eval.rs | 20 +- crates/nu-parser/src/parser.rs | 15 +- .../nu-plugin/src/serializers/capnp/call.rs | 6 +- .../src/serializers/capnp/plugin_call.rs | 15 +- .../nu-plugin/src/serializers/capnp/value.rs | 26 +- crates/nu-protocol/src/ast/call.rs | 2 +- crates/nu-protocol/src/ast/import_pattern.rs | 2 +- crates/nu-protocol/src/pipeline_data.rs | 12 +- crates/nu-protocol/src/span.rs | 5 +- crates/nu-protocol/src/value/from.rs | 110 +-------- crates/nu-protocol/src/value/mod.rs | 22 +- crates/nu-protocol/src/value/range.rs | 12 +- crates/nu_plugin_gstat/src/gstat.rs | 2 +- crates/nu_plugin_gstat/src/nu/mod.rs | 6 +- crates/nu_plugin_inc/src/inc.rs | 24 +- crates/nu_plugin_inc/src/nu/mod.rs | 6 +- src/main.rs | 12 +- 183 files changed, 1291 insertions(+), 1124 deletions(-) diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index dffed7543c..f2b310d44c 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/conversions/into/datetime.rs b/crates/nu-command/src/conversions/into/datetime.rs index d26f0d25e1..de047d4eec 100644 --- a/crates/nu-command/src/conversions/into/datetime.rs +++ b/crates/nu-command/src/conversions/into/datetime.rs @@ -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); } diff --git a/crates/nu-command/src/conversions/into/decimal.rs b/crates/nu-command/src/conversions/into/decimal.rs index e09c6a6f48..15c5ae7f88 100644 --- a/crates/nu-command/src/conversions/into/decimal.rs +++ b/crates/nu-command/src/conversions/into/decimal.rs @@ -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); } diff --git a/crates/nu-command/src/conversions/into/filesize.rs b/crates/nu-command/src/conversions/into/filesize.rs index 795dff7ee0..3ffe85edd5 100644 --- a/crates/nu-command/src/conversions/into/filesize.rs +++ b/crates/nu-command/src/conversions/into/filesize.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index 0c78d64e5b..dbffdfdc84 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -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) } diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 598f40130a..0f3a664d3a 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -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 { diff --git a/crates/nu-command/src/core_commands/for_.rs b/crates/nu-command/src/core_commands/for_.rs index 13343db25a..d95908ded8 100644 --- a/crates/nu-command/src/core_commands/for_.rs +++ b/crates/nu-command/src/core_commands/for_.rs @@ -99,7 +99,7 @@ impl Command for For { } fn examples(&self) -> Vec { - 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, // }), // }, ] diff --git a/crates/nu-command/src/core_commands/use_.rs b/crates/nu-command/src/core_commands/use_.rs index 91d4d070b0..76d2cc2268 100644 --- a/crates/nu-command/src/core_commands/use_.rs +++ b/crates/nu-command/src/core_commands/use_.rs @@ -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); } diff --git a/crates/nu-command/src/core_commands/version.rs b/crates/nu-command/src/core_commands/version.rs index 98280b740c..d7d74f90a9 100644 --- a/crates/nu-command/src/core_commands/version.rs +++ b/crates/nu-command/src/core_commands/version.rs @@ -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()) } diff --git a/crates/nu-command/src/dataframe/append.rs b/crates/nu-command/src/dataframe/append.rs index 8840ffd065..fe1f40a3a5 100644 --- a/crates/nu-command/src/dataframe/append.rs +++ b/crates/nu-command/src/dataframe/append.rs @@ -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()), ), }, ] diff --git a/crates/nu-command/src/dataframe/column.rs b/crates/nu-command/src/dataframe/column.rs index 2dc3efe7f4..76d6bff024 100644 --- a/crates/nu-command/src/dataframe/column.rs +++ b/crates/nu-command/src/dataframe/column.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/describe.rs b/crates/nu-command/src/dataframe/describe.rs index 9c3b953d4c..50d1e4b317 100644 --- a/crates/nu-command/src/dataframe/describe.rs +++ b/crates/nu-command/src/dataframe/describe.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/drop.rs b/crates/nu-command/src/dataframe/drop.rs index fd0cc1aa80..1338ad1522 100644 --- a/crates/nu-command/src/dataframe/drop.rs +++ b/crates/nu-command/src/dataframe/drop.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/drop_nulls.rs b/crates/nu-command/src/dataframe/drop_nulls.rs index f226b98f85..c85873d8e9 100644 --- a/crates/nu-command/src/dataframe/drop_nulls.rs +++ b/crates/nu-command/src/dataframe/drop_nulls.rs @@ -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::>(); (Some(agg_string), col_span) } - None => (None, Span::unknown()), + None => (None, call.head), }; let subset_slice = subset.as_ref().map(|cols| &cols[..]); diff --git a/crates/nu-command/src/dataframe/dtypes.rs b/crates/nu-command/src/dataframe/dtypes.rs index ae10f53ba2..8138dd58b2 100644 --- a/crates/nu-command/src/dataframe/dtypes.rs +++ b/crates/nu-command/src/dataframe/dtypes.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/all_false.rs b/crates/nu-command/src/dataframe/series/all_false.rs index 1320f97b52..de94fbb5b1 100644 --- a/crates/nu-command/src/dataframe/series/all_false.rs +++ b/crates/nu-command/src/dataframe/series/all_false.rs @@ -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()), ), }, ] diff --git a/crates/nu-command/src/dataframe/series/all_true.rs b/crates/nu-command/src/dataframe/series/all_true.rs index 251e5a4384..0818f42c22 100644 --- a/crates/nu-command/src/dataframe/series/all_true.rs +++ b/crates/nu-command/src/dataframe/series/all_true.rs @@ -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()), ), }, ] diff --git a/crates/nu-command/src/dataframe/series/arg_max.rs b/crates/nu-command/src/dataframe/series/arg_max.rs index 531e65c16c..774ba401aa 100644 --- a/crates/nu-command/src/dataframe/series/arg_max.rs +++ b/crates/nu-command/src/dataframe/series/arg_max.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/arg_min.rs b/crates/nu-command/src/dataframe/series/arg_min.rs index 4e49a8034c..bacdbf2768 100644 --- a/crates/nu-command/src/dataframe/series/arg_min.rs +++ b/crates/nu-command/src/dataframe/series/arg_min.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/cumulative.rs b/crates/nu-command/src/dataframe/series/cumulative.rs index b957b81e19..8e4cfd8145 100644 --- a/crates/nu-command/src/dataframe/series/cumulative.rs +++ b/crates/nu-command/src/dataframe/series/cumulative.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_day.rs b/crates/nu-command/src/dataframe/series/date/get_day.rs index 3d049edadc..fe840121a6 100644 --- a/crates/nu-command/src/dataframe/series/date/get_day.rs +++ b/crates/nu-command/src/dataframe/series/date/get_day.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_hour.rs b/crates/nu-command/src/dataframe/series/date/get_hour.rs index 0b9703c718..4b0ea98ee2 100644 --- a/crates/nu-command/src/dataframe/series/date/get_hour.rs +++ b/crates/nu-command/src/dataframe/series/date/get_hour.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_minute.rs b/crates/nu-command/src/dataframe/series/date/get_minute.rs index d5c44eba88..161a85f464 100644 --- a/crates/nu-command/src/dataframe/series/date/get_minute.rs +++ b/crates/nu-command/src/dataframe/series/date/get_minute.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_month.rs b/crates/nu-command/src/dataframe/series/date/get_month.rs index 6f4092e084..a5f9f0fc98 100644 --- a/crates/nu-command/src/dataframe/series/date/get_month.rs +++ b/crates/nu-command/src/dataframe/series/date/get_month.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_nanosecond.rs b/crates/nu-command/src/dataframe/series/date/get_nanosecond.rs index a748ae096c..445398d49e 100644 --- a/crates/nu-command/src/dataframe/series/date/get_nanosecond.rs +++ b/crates/nu-command/src/dataframe/series/date/get_nanosecond.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_ordinal.rs b/crates/nu-command/src/dataframe/series/date/get_ordinal.rs index 08d22ab910..95b46c24a0 100644 --- a/crates/nu-command/src/dataframe/series/date/get_ordinal.rs +++ b/crates/nu-command/src/dataframe/series/date/get_ordinal.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_second.rs b/crates/nu-command/src/dataframe/series/date/get_second.rs index d379488464..ba5ecf8e48 100644 --- a/crates/nu-command/src/dataframe/series/date/get_second.rs +++ b/crates/nu-command/src/dataframe/series/date/get_second.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_week.rs b/crates/nu-command/src/dataframe/series/date/get_week.rs index 117eb5bf9f..a671d3229c 100644 --- a/crates/nu-command/src/dataframe/series/date/get_week.rs +++ b/crates/nu-command/src/dataframe/series/date/get_week.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_weekday.rs b/crates/nu-command/src/dataframe/series/date/get_weekday.rs index 9a517fed81..b4e370665e 100644 --- a/crates/nu-command/src/dataframe/series/date/get_weekday.rs +++ b/crates/nu-command/src/dataframe/series/date/get_weekday.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/date/get_year.rs b/crates/nu-command/src/dataframe/series/date/get_year.rs index 0646a2ae73..ed248c2af1 100644 --- a/crates/nu-command/src/dataframe/series/date/get_year.rs +++ b/crates/nu-command/src/dataframe/series/date/get_year.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/indexes/arg_sort.rs b/crates/nu-command/src/dataframe/series/indexes/arg_sort.rs index 6f155aa00c..d1ff8f9963 100644 --- a/crates/nu-command/src/dataframe/series/indexes/arg_sort.rs +++ b/crates/nu-command/src/dataframe/series/indexes/arg_sort.rs @@ -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()), ), }, ] diff --git a/crates/nu-command/src/dataframe/series/indexes/arg_true.rs b/crates/nu-command/src/dataframe/series/indexes/arg_true.rs index 345044d0d6..12af3ed086 100644 --- a/crates/nu-command/src/dataframe/series/indexes/arg_true.rs +++ b/crates/nu-command/src/dataframe/series/indexes/arg_true.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/indexes/arg_unique.rs b/crates/nu-command/src/dataframe/series/indexes/arg_unique.rs index fe711cca2b..6ea52f0e42 100644 --- a/crates/nu-command/src/dataframe/series/indexes/arg_unique.rs +++ b/crates/nu-command/src/dataframe/series/indexes/arg_unique.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/indexes/set_with_idx.rs b/crates/nu-command/src/dataframe/series/indexes/set_with_idx.rs index 60b542f0c8..cb3abb1d88 100644 --- a/crates/nu-command/src/dataframe/series/indexes/set_with_idx.rs +++ b/crates/nu-command/src/dataframe/series/indexes/set_with_idx.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/masks/is_duplicated.rs b/crates/nu-command/src/dataframe/series/masks/is_duplicated.rs index df111c297f..b237ebe94f 100644 --- a/crates/nu-command/src/dataframe/series/masks/is_duplicated.rs +++ b/crates/nu-command/src/dataframe/series/masks/is_duplicated.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/masks/is_in.rs b/crates/nu-command/src/dataframe/series/masks/is_in.rs index 57478c72c8..dfe4cec4f8 100644 --- a/crates/nu-command/src/dataframe/series/masks/is_in.rs +++ b/crates/nu-command/src/dataframe/series/masks/is_in.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/masks/is_not_null.rs b/crates/nu-command/src/dataframe/series/masks/is_not_null.rs index 42f6101c97..c8226c13e2 100644 --- a/crates/nu-command/src/dataframe/series/masks/is_not_null.rs +++ b/crates/nu-command/src/dataframe/series/masks/is_not_null.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/masks/is_null.rs b/crates/nu-command/src/dataframe/series/masks/is_null.rs index 59f37c836e..397a87fe1d 100644 --- a/crates/nu-command/src/dataframe/series/masks/is_null.rs +++ b/crates/nu-command/src/dataframe/series/masks/is_null.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/masks/is_unique.rs b/crates/nu-command/src/dataframe/series/masks/is_unique.rs index 971f501525..d0272084a0 100644 --- a/crates/nu-command/src/dataframe/series/masks/is_unique.rs +++ b/crates/nu-command/src/dataframe/series/masks/is_unique.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/masks/not.rs b/crates/nu-command/src/dataframe/series/masks/not.rs index cad0e4d388..636ee2818f 100644 --- a/crates/nu-command/src/dataframe/series/masks/not.rs +++ b/crates/nu-command/src/dataframe/series/masks/not.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/masks/set.rs b/crates/nu-command/src/dataframe/series/masks/set.rs index 610ed55ff2..8711728655 100644 --- a/crates/nu-command/src/dataframe/series/masks/set.rs +++ b/crates/nu-command/src/dataframe/series/masks/set.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/n_null.rs b/crates/nu-command/src/dataframe/series/n_null.rs index 4c21a120d0..9bee66005c 100644 --- a/crates/nu-command/src/dataframe/series/n_null.rs +++ b/crates/nu-command/src/dataframe/series/n_null.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/n_unique.rs b/crates/nu-command/src/dataframe/series/n_unique.rs index 94910c63a2..3a5a511b66 100644 --- a/crates/nu-command/src/dataframe/series/n_unique.rs +++ b/crates/nu-command/src/dataframe/series/n_unique.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/rename.rs b/crates/nu-command/src/dataframe/series/rename.rs index 8fb9ca2588..9de4d86a3c 100644 --- a/crates/nu-command/src/dataframe/series/rename.rs +++ b/crates/nu-command/src/dataframe/series/rename.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/rolling.rs b/crates/nu-command/src/dataframe/series/rolling.rs index 4a5d7b96db..438b8ef063 100644 --- a/crates/nu-command/src/dataframe/series/rolling.rs +++ b/crates/nu-command/src/dataframe/series/rolling.rs @@ -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()), ), }, ] diff --git a/crates/nu-command/src/dataframe/series/shift.rs b/crates/nu-command/src/dataframe/series/shift.rs index f50c4ac6e1..6deca4f10b 100644 --- a/crates/nu-command/src/dataframe/series/shift.rs +++ b/crates/nu-command/src/dataframe/series/shift.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/concatenate.rs b/crates/nu-command/src/dataframe/series/string/concatenate.rs index 6abb80e363..37d5f73128 100644 --- a/crates/nu-command/src/dataframe/series/string/concatenate.rs +++ b/crates/nu-command/src/dataframe/series/string/concatenate.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/contains.rs b/crates/nu-command/src/dataframe/series/string/contains.rs index 605bd027d6..2c0fc58959 100644 --- a/crates/nu-command/src/dataframe/series/string/contains.rs +++ b/crates/nu-command/src/dataframe/series/string/contains.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/replace.rs b/crates/nu-command/src/dataframe/series/string/replace.rs index 43437503a4..ac95901031 100644 --- a/crates/nu-command/src/dataframe/series/string/replace.rs +++ b/crates/nu-command/src/dataframe/series/string/replace.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/replace_all.rs b/crates/nu-command/src/dataframe/series/string/replace_all.rs index 63abefe934..383bba4848 100644 --- a/crates/nu-command/src/dataframe/series/string/replace_all.rs +++ b/crates/nu-command/src/dataframe/series/string/replace_all.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/str_lengths.rs b/crates/nu-command/src/dataframe/series/string/str_lengths.rs index a13b03f4a6..f3afad973b 100644 --- a/crates/nu-command/src/dataframe/series/string/str_lengths.rs +++ b/crates/nu-command/src/dataframe/series/string/str_lengths.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/str_slice.rs b/crates/nu-command/src/dataframe/series/string/str_slice.rs index 8240d24f71..af69b47cdb 100644 --- a/crates/nu-command/src/dataframe/series/string/str_slice.rs +++ b/crates/nu-command/src/dataframe/series/string/str_slice.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/strftime.rs b/crates/nu-command/src/dataframe/series/string/strftime.rs index 262d78101b..e57c44a6c8 100644 --- a/crates/nu-command/src/dataframe/series/string/strftime.rs +++ b/crates/nu-command/src/dataframe/series/string/strftime.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/to_lowercase.rs b/crates/nu-command/src/dataframe/series/string/to_lowercase.rs index d396bd99a5..7ecd8e58c5 100644 --- a/crates/nu-command/src/dataframe/series/string/to_lowercase.rs +++ b/crates/nu-command/src/dataframe/series/string/to_lowercase.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/string/to_uppercase.rs b/crates/nu-command/src/dataframe/series/string/to_uppercase.rs index a7bcbf72b8..568d76378c 100644 --- a/crates/nu-command/src/dataframe/series/string/to_uppercase.rs +++ b/crates/nu-command/src/dataframe/series/string/to_uppercase.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/unique.rs b/crates/nu-command/src/dataframe/series/unique.rs index 1c23124c38..c9aad6f174 100644 --- a/crates/nu-command/src/dataframe/series/unique.rs +++ b/crates/nu-command/src/dataframe/series/unique.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/series/value_counts.rs b/crates/nu-command/src/dataframe/series/value_counts.rs index 42d5737751..714595a693 100644 --- a/crates/nu-command/src/dataframe/series/value_counts.rs +++ b/crates/nu-command/src/dataframe/series/value_counts.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/dataframe/test_dataframe.rs b/crates/nu-command/src/dataframe/test_dataframe.rs index afc8d7eb73..fa0fcdda34 100644 --- a/crates/nu-command/src/dataframe/test_dataframe.rs +++ b/crates/nu-command/src/dataframe/test_dataframe.rs @@ -62,7 +62,7 @@ pub fn test_dataframe(cmds: Vec>) { Value::Record { cols: vec![], vals: vec![], - span: Span::unknown(), + span: Span::test_data(), }, ); @@ -70,11 +70,11 @@ pub fn test_dataframe(cmds: Vec>) { &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()); diff --git a/crates/nu-command/src/dataframe/to_df.rs b/crates/nu-command/src/dataframe/to_df.rs index c8a1e683e8..8d4a8cecb8 100644 --- a/crates/nu-command/src/dataframe/to_df.rs +++ b/crates/nu-command/src/dataframe/to_df.rs @@ -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()), ), }, ] diff --git a/crates/nu-command/src/dataframe/values/nu_dataframe/conversion.rs b/crates/nu-command/src/dataframe/values/nu_dataframe/conversion.rs index a466e4651d..5d6be647b9 100644 --- a/crates/nu-command/src/dataframe/values/nu_dataframe/conversion.rs +++ b/crates/nu-command/src/dataframe/values/nu_dataframe/conversion.rs @@ -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 { let size = to_row - from_row; match series.dtype() { DataType::Null => { - let values = std::iter::repeat(Value::Nothing { - span: Span::unknown(), - }) - .take(size) - .collect::>(); + let values = std::iter::repeat(Value::Nothing { span }) + .take(size) + .collect::>(); 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); + + 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::>(); @@ -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::>(); @@ -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::>(); @@ -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::>(); @@ -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::>(); @@ -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::>(); @@ -345,29 +456,9 @@ pub fn create_column( } } -fn column_from_casted(casted: &ChunkedArray, from_row: usize, size: usize) -> Column -where - T: PolarsNumericType, - T::Native: Into, -{ - 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::>(); - - 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, df: &DataFrame) { +pub fn add_separator(values: &mut Vec, df: &DataFrame, span: Span) { let mut cols = vec![]; let mut vals = vec![]; @@ -375,15 +466,11 @@ pub fn add_separator(values: &mut Vec, 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); } diff --git a/crates/nu-command/src/dataframe/values/nu_dataframe/custom_value.rs b/crates/nu-command/src/dataframe/values/nu_dataframe/custom_value.rs index 842d0b1159..a1c2329e87 100644 --- a/crates/nu-command/src/dataframe/values/nu_dataframe/custom_value.rs +++ b/crates/nu-command/src/dataframe/values/nu_dataframe/custom_value.rs @@ -29,7 +29,7 @@ impl CustomValue for NuDataFrame { } fn to_base_value(&self, span: Span) -> Result { - let vals = self.print()?; + let vals = self.print(span)?; Ok(Value::List { vals, span }) } diff --git a/crates/nu-command/src/dataframe/values/nu_dataframe/mod.rs b/crates/nu-command/src/dataframe/values/nu_dataframe/mod.rs index 3fe42d2a96..7fc92bba41 100644 --- a/crates/nu-command/src/dataframe/values/nu_dataframe/mod.rs +++ b/crates/nu-command/src/dataframe/values/nu_dataframe/mod.rs @@ -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::() { 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 { - 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, ShellError> { + pub fn print(&self, span: Span) -> Result, 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) -> Result, ShellError> { + pub fn head(&self, rows: Option, span: Span) -> Result, 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) -> Result, ShellError> { + pub fn tail(&self, rows: Option, span: Span) -> Result, 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, ShellError> { + pub fn to_rows( + &self, + from_row: usize, + to_row: usize, + span: Span, + ) -> Result, 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::>(); diff --git a/crates/nu-command/src/dataframe/with_column.rs b/crates/nu-command/src/dataframe/with_column.rs index 1eabb9facf..f6890d1958 100644 --- a/crates/nu-command/src/dataframe/with_column.rs +++ b/crates/nu-command/src/dataframe/with_column.rs @@ -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()), ), }] } diff --git a/crates/nu-command/src/date/format.rs b/crates/nu-command/src/date/format.rs index 33e14af106..64ee287a45 100644 --- a/crates/nu-command/src/date/format.rs +++ b/crates/nu-command/src/date/format.rs @@ -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, 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, span: Span) -> Value span, } } - _ => unsupported_input_error(), + _ => unsupported_input_error(span), } } diff --git a/crates/nu-command/src/date/humanize.rs b/crates/nu-command/src/date/humanize.rs index 6f4087b832..f03d525970 100644 --- a/crates/nu-command/src/date/humanize.rs +++ b/crates/nu-command/src/date/humanize.rs @@ -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, ), }, } diff --git a/crates/nu-command/src/date/to_table.rs b/crates/nu-command/src/date/to_table.rs index f518d010dc..efdc40f22d 100644 --- a/crates/nu-command/src/date/to_table.rs +++ b/crates/nu-command/src/date/to_table.rs @@ -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, 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), } } diff --git a/crates/nu-command/src/date/to_timezone.rs b/crates/nu-command/src/date/to_timezone.rs index 593211ffd5..0a6261873d 100644 --- a/crates/nu-command/src/date/to_timezone.rs +++ b/crates/nu-command/src/date/to_timezone.rs @@ -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) -> 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) -> Value { let dt = Local::now(); _to_timezone(dt.with_timezone(dt.offset()), timezone, head) } - _ => unsupported_input_error(), + _ => unsupported_input_error(head), } } diff --git a/crates/nu-command/src/date/utils.rs b/crates/nu-command/src/date/utils.rs index d1320766fc..25a4f6a016 100644 --- a/crates/nu-command/src/date/utils.rs +++ b/crates/nu-command/src/date/utils.rs @@ -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, Value> { +pub fn parse_date_from_string(input: String, span: Span) -> Result, 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, 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)), } } } diff --git a/crates/nu-command/src/example_test.rs b/crates/nu-command/src/example_test.rs index ae6b856998..66c3a0e53c 100644 --- a/crates/nu-command/src/example_test.rs +++ b/crates/nu-command/src/example_test.rs @@ -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()); diff --git a/crates/nu-command/src/filters/all.rs b/crates/nu-command/src/filters/all.rs index ab15a4aed7..6d6321d13d 100644 --- a/crates/nu-command/src/filters/all.rs +++ b/crates/nu-command/src/filters/all.rs @@ -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 { - 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()) } } diff --git a/crates/nu-command/src/filters/any.rs b/crates/nu-command/src/filters/any.rs index 72a1b1d485..869664d203 100644 --- a/crates/nu-command/src/filters/any.rs +++ b/crates/nu-command/src/filters/any.rs @@ -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 { - 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()) } } diff --git a/crates/nu-command/src/filters/append.rs b/crates/nu-command/src/filters/append.rs index eba6b56c43..55d6dc67de 100644 --- a/crates/nu-command/src/filters/append.rs +++ b/crates/nu-command/src/filters/append.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/columns.rs b/crates/nu-command/src/filters/columns.rs index 3b6d84f6d6..d4b4a30600 100644 --- a/crates/nu-command/src/filters/columns.rs +++ b/crates/nu-command/src/filters/columns.rs @@ -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, ..) => { diff --git a/crates/nu-command/src/filters/drop/column.rs b/crates/nu-command/src/filters/drop/column.rs index ae99ad0c19..e5438314c9 100644 --- a/crates/nu-command/src/filters/drop/column.rs +++ b/crates/nu-command/src/filters/drop/column.rs @@ -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) -> Vec { } } -fn get_cellpath_columns(keep_cols: Vec) -> Vec { +fn get_cellpath_columns(keep_cols: Vec, span: Span) -> Vec { let mut output = vec![]; for keep_col in keep_cols { - let span = Span::unknown(); let val = Value::String { val: keep_col, span, diff --git a/crates/nu-command/src/filters/drop/command.rs b/crates/nu-command/src/filters/drop/command.rs index aac7efea6b..baaed91929 100644 --- a/crates/nu-command/src/filters/drop/command.rs +++ b/crates/nu-command/src/filters/drop/command.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/drop/nth.rs b/crates/nu-command/src/filters/drop/nth.rs index f772dd162f..edcb8929a2 100644 --- a/crates/nu-command/src/filters/drop/nth.rs +++ b/crates/nu-command/src/filters/drop/nth.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/each.rs b/crates/nu-command/src/filters/each.rs index b85ebfdedc..614d4d1512 100644 --- a/crates/nu-command/src/filters/each.rs +++ b/crates/nu-command/src/filters/each.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/filters/first.rs b/crates/nu-command/src/filters/first.rs index f0d69734d8..7fc2b6ecda 100644 --- a/crates/nu-command/src/filters/first.rs +++ b/crates/nu-command/src/filters/first.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/get.rs b/crates/nu-command/src/filters/get.rs index 776667b500..4c2eb6526a 100644 --- a/crates/nu-command/src/filters/get.rs +++ b/crates/nu-command/src/filters/get.rs @@ -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()) } } diff --git a/crates/nu-command/src/filters/keep/command.rs b/crates/nu-command/src/filters/keep/command.rs index fd993bd6f0..ead4c6290b 100644 --- a/crates/nu-command/src/filters/keep/command.rs +++ b/crates/nu-command/src/filters/keep/command.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/keep/until.rs b/crates/nu-command/src/filters/keep/until.rs index 7c7c37a265..513ffea2e0 100644 --- a/crates/nu-command/src/filters/keep/until.rs +++ b/crates/nu-command/src/filters/keep/until.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/filters/keep/while_.rs b/crates/nu-command/src/filters/keep/while_.rs index 67a91c3891..991eb2ebdc 100644 --- a/crates/nu-command/src/filters/keep/while_.rs +++ b/crates/nu-command/src/filters/keep/while_.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/filters/last.rs b/crates/nu-command/src/filters/last.rs index 8c1871e74a..b4485e2367 100644 --- a/crates/nu-command/src/filters/last.rs +++ b/crates/nu-command/src/filters/last.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/filters/nth.rs b/crates/nu-command/src/filters/nth.rs index 6597db922f..d49ffda0d5 100644 --- a/crates/nu-command/src/filters/nth.rs +++ b/crates/nu-command/src/filters/nth.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/prepend.rs b/crates/nu-command/src/filters/prepend.rs index c50ce2764c..b7685b3877 100644 --- a/crates/nu-command/src/filters/prepend.rs +++ b/crates/nu-command/src/filters/prepend.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/range.rs b/crates/nu-command/src/filters/range.rs index 071c91d046..9584c494a5 100644 --- a/crates/nu-command/src/filters/range.rs +++ b/crates/nu-command/src/filters/range.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/reject.rs b/crates/nu-command/src/filters/reject.rs index ccbb2915c9..f950812912 100644 --- a/crates/nu-command/src/filters/reject.rs +++ b/crates/nu-command/src/filters/reject.rs @@ -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) -> Vec { } } -fn get_cellpath_columns(keep_cols: Vec) -> Vec { +fn get_cellpath_columns(keep_cols: Vec, span: Span) -> Vec { let mut output = vec![]; for keep_col in keep_cols { - let span = Span::unknown(); let val = Value::String { val: keep_col, span, diff --git a/crates/nu-command/src/filters/reverse.rs b/crates/nu-command/src/filters/reverse.rs index 3eccf3c1a9..9995a33a56 100644 --- a/crates/nu-command/src/filters/reverse.rs +++ b/crates/nu-command/src/filters/reverse.rs @@ -32,7 +32,7 @@ impl Command for Reverse { Value::test_int(1), Value::test_int(0), ], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index 27c797aada..53367e7b4c 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -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(), // ); diff --git a/crates/nu-command/src/filters/skip/command.rs b/crates/nu-command/src/filters/skip/command.rs index 613f997acc..1fb3ba349b 100644 --- a/crates/nu-command/src/filters/skip/command.rs +++ b/crates/nu-command/src/filters/skip/command.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/skip/until.rs b/crates/nu-command/src/filters/skip/until.rs index 584929b6f1..1a65aa3b58 100644 --- a/crates/nu-command/src/filters/skip/until.rs +++ b/crates/nu-command/src/filters/skip/until.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/filters/skip/while_.rs b/crates/nu-command/src/filters/skip/while_.rs index adc9882b73..55bba5caa2 100644 --- a/crates/nu-command/src/filters/skip/while_.rs +++ b/crates/nu-command/src/filters/skip/while_.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/filters/uniq.rs b/crates/nu-command/src/filters/uniq.rs index 53a60229f7..b6b935fda6 100644 --- a/crates/nu-command/src/filters/uniq.rs +++ b/crates/nu-command/src/filters/uniq.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/filters/update.rs b/crates/nu-command/src/filters/update.rs index a6bfdab0dc..78d4d9d756 100644 --- a/crates/nu-command/src/filters/update.rs +++ b/crates/nu-command/src/filters/update.rs @@ -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()}), }] } } diff --git a/crates/nu-command/src/formats/from/eml.rs b/crates/nu-command/src/formats/from/eml.rs index 9bb65b3298..fb6af3c63c 100644 --- a/crates/nu-command/src/formats/from/eml.rs +++ b/crates/nu-command/src/formats/from/eml.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/formats/from/ics.rs b/crates/nu-command/src/formats/from/ics.rs index c644ab787d..b49a6e0f8c 100644 --- a/crates/nu-command/src/formats/from/ics.rs +++ b/crates/nu-command/src/formats/from/ics.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/formats/from/ini.rs b/crates/nu-command/src/formats/from/ini.rs index 63df9bb7c4..6273c2a000 100644 --- a/crates/nu-command/src/formats/from/ini.rs +++ b/crates/nu-command/src/formats/from/ini.rs @@ -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(), }), }] } diff --git a/crates/nu-command/src/formats/from/json.rs b/crates/nu-command/src/formats/from/json.rs index d0f47626c4..3b3a9d8dea 100644 --- a/crates/nu-command/src/formats/from/json.rs +++ b/crates/nu-command/src/formats/from/json.rs @@ -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(), }), }, ] diff --git a/crates/nu-command/src/formats/from/ods.rs b/crates/nu-command/src/formats/from/ods.rs index e178ee67a2..146bffd8a1 100644 --- a/crates/nu-command/src/formats/from/ods.rs +++ b/crates/nu-command/src/formats/from/ods.rs @@ -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, ShellError> { +fn convert_columns(columns: &[Value], span: Span) -> Result, 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::, _>>()?; @@ -82,7 +82,7 @@ fn convert_columns(columns: &[Value]) -> Result, ShellError> { Ok(res) } -fn collect_binary(input: PipelineData) -> Result, ShellError> { +fn collect_binary(input: PipelineData, span: Span) -> Result, ShellError> { let mut bytes = vec![]; let mut values = input.into_iter(); @@ -94,7 +94,7 @@ fn collect_binary(input: PipelineData) -> Result, 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, ) -> Result { - let bytes = collect_binary(input)?; + let bytes = collect_binary(input, head)?; let buf: Cursor> = Cursor::new(bytes); let mut ods = Ods::<_>::new(buf) .map_err(|_| ShellError::UnsupportedInput("Could not load ods file".to_string(), head))?; diff --git a/crates/nu-command/src/formats/from/ssv.rs b/crates/nu-command/src/formats/from/ssv.rs index 2bc7fdfb93..c378b6ba1d 100644 --- a/crates/nu-command/src/formats/from/ssv.rs +++ b/crates/nu-command/src/formats/from/ssv.rs @@ -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() }), }] } diff --git a/crates/nu-command/src/formats/from/toml.rs b/crates/nu-command/src/formats/from/toml.rs index 4d702b2731..378e92216d 100644 --- a/crates/nu-command/src/formats/from/toml.rs +++ b/crates/nu-command/src/formats/from/toml.rs @@ -29,9 +29,9 @@ impl Command for FromToml { 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 { @@ -43,23 +43,23 @@ b = [1, 2]' | from toml", 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(), }), }, ] diff --git a/crates/nu-command/src/formats/from/url.rs b/crates/nu-command/src/formats/from/url.rs index cac2f898a4..dab7da89c2 100644 --- a/crates/nu-command/src/formats/from/url.rs +++ b/crates/nu-command/src/formats/from/url.rs @@ -47,7 +47,7 @@ impl Command for FromUrl { Value::test_string("ham"), Value::test_string("butter"), ], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/formats/from/vcf.rs b/crates/nu-command/src/formats/from/vcf.rs index 9d009d76c0..5c7566609b 100644 --- a/crates/nu-command/src/formats/from/vcf.rs +++ b/crates/nu-command/src/formats/from/vcf.rs @@ -58,17 +58,17 @@ END:VCARD' | from vcf", vals: vec![ Value::String { val: "N".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "Foo".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Nothing { - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }, Value::Record { cols: vec![ @@ -79,17 +79,17 @@ END:VCARD' | from vcf", vals: vec![ Value::String { val: "FN".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "Bar".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Nothing { - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }, Value::Record { cols: vec![ @@ -100,24 +100,24 @@ END:VCARD' | from vcf", vals: vec![ Value::String { val: "EMAIL".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "foo@bar.com".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Nothing { - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/formats/from/xlsx.rs b/crates/nu-command/src/formats/from/xlsx.rs index 0746c3e864..3aa98655c2 100644 --- a/crates/nu-command/src/formats/from/xlsx.rs +++ b/crates/nu-command/src/formats/from/xlsx.rs @@ -43,7 +43,7 @@ impl Command for FromXlsx { 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 FromXlsx { } } -fn convert_columns(columns: &[Value]) -> Result, ShellError> { +fn convert_columns(columns: &[Value], span: Span) -> Result, 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::, _>>()?; @@ -82,7 +82,7 @@ fn convert_columns(columns: &[Value]) -> Result, ShellError> { Ok(res) } -fn collect_binary(input: PipelineData) -> Result, ShellError> { +fn collect_binary(input: PipelineData, span: Span) -> Result, ShellError> { let mut bytes = vec![]; let mut values = input.into_iter(); @@ -94,7 +94,7 @@ fn collect_binary(input: PipelineData) -> Result, 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_xlsx( head: Span, sel_sheets: Vec, ) -> Result { - let bytes = collect_binary(input)?; + let bytes = collect_binary(input, head)?; let buf: Cursor> = Cursor::new(bytes); let mut xlsx = Xlsx::<_>::new(buf) .map_err(|_| ShellError::UnsupportedInput("Could not load xlsx file".to_string(), head))?; diff --git a/crates/nu-command/src/formats/from/xml.rs b/crates/nu-command/src/formats/from/xml.rs index 7217396198..8d87dc8a31 100644 --- a/crates/nu-command/src/formats/from/xml.rs +++ b/crates/nu-command/src/formats/from/xml.rs @@ -55,31 +55,31 @@ impl Command for FromXml { Value::List { vals: vec![Value::String { val: "Event".to_string(), - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }, Value::Record { cols: vec![], vals: vec![], - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }, Value::Record { cols: vec![], vals: vec![], - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }] } @@ -201,26 +201,26 @@ mod tests { fn string(input: impl Into) -> Value { Value::String { val: input.into(), - span: Span::unknown(), + span: Span::test_data(), } } fn row(entries: IndexMap) -> Value { Value::from(Spanned { item: entries, - span: Span::unknown(), + span: Span::test_data(), }) } fn table(list: &[Value]) -> Value { Value::List { vals: list.to_vec(), - span: Span::unknown(), + span: Span::test_data(), } } fn parse(xml: &str) -> Result { - from_xml_string_to_value(xml.to_string(), Span::unknown()) + from_xml_string_to_value(xml.to_string(), Span::test_data()) } #[test] diff --git a/crates/nu-command/src/formats/from/yaml.rs b/crates/nu-command/src/formats/from/yaml.rs index fed07688a3..d8e8fcfdab 100644 --- a/crates/nu-command/src/formats/from/yaml.rs +++ b/crates/nu-command/src/formats/from/yaml.rs @@ -33,9 +33,9 @@ impl Command for FromYaml { 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 { @@ -46,18 +46,18 @@ impl Command for FromYaml { Value::Record { cols: vec!["a".to_string()], vals: vec![Value::test_int(1)], - span: Span::unknown(), + span: Span::test_data(), }, Value::Record { cols: vec!["b".to_string()], vals: vec![Value::List { vals: vec![Value::test_int(1), Value::test_int(2)], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -233,9 +233,9 @@ mod test { cols: vec!["value".to_string()], vals: vec![Value::String { val: "{{ something }}".to_string(), - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, TestCase { @@ -245,15 +245,15 @@ mod test { cols: vec!["value".to_string()], vals: vec![Value::String { val: "{{ something }}".to_string(), - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, ]; let config = Config::default(); for tc in tt { - let actual = from_yaml_string_to_value(tc.input.to_owned(), Span::unknown()); + let actual = from_yaml_string_to_value(tc.input.to_owned(), Span::test_data()); if actual.is_err() { assert!( tc.expected.is_err(), diff --git a/crates/nu-command/src/formats/to/delimited.rs b/crates/nu-command/src/formats/to/delimited.rs index 1103ecf006..ab54c3a2c1 100644 --- a/crates/nu-command/src/formats/to/delimited.rs +++ b/crates/nu-command/src/formats/to/delimited.rs @@ -7,6 +7,7 @@ fn from_value_to_delimited_string( value: &Value, separator: char, config: &Config, + head: Span, ) -> Result { match value { Value::Record { cols, vals, span } => { @@ -19,7 +20,7 @@ fn from_value_to_delimited_string( for (k, v) in cols.iter().zip(vals.iter()) { fields.push_back(k.clone()); - values.push_back(to_string_tagged_value(v, config)?); + values.push_back(to_string_tagged_value(v, config, *span)?); } wtr.write_record(fields).expect("can not write."); @@ -44,7 +45,8 @@ fn from_value_to_delimited_string( wtr.write_record( vals.iter() .map(|ele| { - to_string_tagged_value(ele, config).unwrap_or_else(|_| String::new()) + to_string_tagged_value(ele, config, *span) + .unwrap_or_else(|_| String::new()) }) .collect::>(), ) @@ -57,7 +59,7 @@ fn from_value_to_delimited_string( let mut row = vec![]; for desc in &merged_descriptors { row.push(match l.to_owned().get_data_by_key(desc) { - Some(s) => to_string_tagged_value(&s, config)?, + Some(s) => to_string_tagged_value(&s, config, *span)?, None => String::new(), }); } @@ -72,11 +74,11 @@ fn from_value_to_delimited_string( })?; Ok(v) } - _ => to_string_tagged_value(value, config), + _ => to_string_tagged_value(value, config, head), } } -fn to_string_tagged_value(v: &Value, config: &Config) -> Result { +fn to_string_tagged_value(v: &Value, config: &Config, span: Span) -> Result { match &v { Value::String { .. } | Value::Bool { .. } @@ -94,7 +96,7 @@ fn to_string_tagged_value(v: &Value, config: &Config) -> Result Ok(String::new()), _ => Err(ShellError::UnsupportedInput( "Unexpected value".to_string(), - v.span().unwrap_or_else(|_| Span::unknown()), + v.span().unwrap_or(span), )), } } @@ -126,7 +128,7 @@ pub fn to_delimited_data( config: Config, ) -> Result { let value = input.into_value(span); - let output = match from_value_to_delimited_string(&value, sep, &config) { + let output = match from_value_to_delimited_string(&value, sep, &config, span) { Ok(mut x) => { if noheaders { if let Some(second_line) = x.find('\n') { @@ -139,7 +141,7 @@ pub fn to_delimited_data( Err(_) => Err(ShellError::CantConvert( format_name.into(), value.get_type().to_string(), - value.span().unwrap_or_else(|_| Span::unknown()), + value.span().unwrap_or(span), )), }?; Ok(Value::string(output, span).into_pipeline_data()) diff --git a/crates/nu-command/src/formats/to/md.rs b/crates/nu-command/src/formats/to/md.rs index 48efc31c82..9f5eca2e25 100644 --- a/crates/nu-command/src/formats/to/md.rs +++ b/crates/nu-command/src/formats/to/md.rs @@ -352,7 +352,7 @@ mod tests { let value = Value::Record { cols: vec!["H1".to_string()], vals: vec![Value::test_string("Ecuador")], - span: Span::unknown(), + span: Span::test_data(), }; assert_eq!(fragment(value, false, &Config::default()), "# Ecuador\n"); @@ -363,7 +363,7 @@ mod tests { let value = Value::Record { cols: vec!["H2".to_string()], vals: vec![Value::test_string("Ecuador")], - span: Span::unknown(), + span: Span::test_data(), }; assert_eq!(fragment(value, false, &Config::default()), "## Ecuador\n"); @@ -374,7 +374,7 @@ mod tests { let value = Value::Record { cols: vec!["H3".to_string()], vals: vec![Value::test_string("Ecuador")], - span: Span::unknown(), + span: Span::test_data(), }; assert_eq!(fragment(value, false, &Config::default()), "### Ecuador\n"); @@ -385,7 +385,7 @@ mod tests { let value = Value::Record { cols: vec!["BLOCKQUOTE".to_string()], vals: vec![Value::test_string("Ecuador")], - span: Span::unknown(), + span: Span::test_data(), }; assert_eq!(fragment(value, false, &Config::default()), "> Ecuador\n"); @@ -398,20 +398,20 @@ mod tests { Value::Record { cols: vec!["country".to_string()], vals: vec![Value::test_string("Ecuador")], - span: Span::unknown(), + span: Span::test_data(), }, Value::Record { cols: vec!["country".to_string()], vals: vec![Value::test_string("New Zealand")], - span: Span::unknown(), + span: Span::test_data(), }, Value::Record { cols: vec!["country".to_string()], vals: vec![Value::test_string("USA")], - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; assert_eq!( diff --git a/crates/nu-command/src/formats/to/toml.rs b/crates/nu-command/src/formats/to/toml.rs index 3f0d6100ba..d42d7c6c34 100644 --- a/crates/nu-command/src/formats/to/toml.rs +++ b/crates/nu-command/src/formats/to/toml.rs @@ -109,7 +109,7 @@ fn toml_into_pipeline_data( } } -fn value_to_toml_value(v: &Value) -> Result { +fn value_to_toml_value(v: &Value, head: Span) -> Result { match v { Value::Record { .. } => helper(v), Value::List { ref vals, span } => match &vals[..] { @@ -130,7 +130,7 @@ fn value_to_toml_value(v: &Value) -> Result { } _ => Err(ShellError::UnsupportedInput( format!("{:?} is not a valid top-level TOML", v.get_type()), - v.span().unwrap_or_else(|_| Span::unknown()), + v.span().unwrap_or(head), )), } } @@ -138,7 +138,7 @@ fn value_to_toml_value(v: &Value) -> Result { fn to_toml(input: PipelineData, span: Span) -> Result { let value = input.into_value(span); - let toml_value = value_to_toml_value(&value)?; + let toml_value = value_to_toml_value(&value, span)?; match toml_value { toml::Value::Array(ref vec) => match vec[..] { [toml::Value::Table(_)] => toml_into_pipeline_data( @@ -172,18 +172,21 @@ mod tests { let mut m = indexmap::IndexMap::new(); m.insert("rust".to_owned(), Value::test_string("editor")); - m.insert("is".to_owned(), Value::nothing(Span::unknown())); + m.insert("is".to_owned(), Value::nothing(Span::test_data())); m.insert( "features".to_owned(), Value::List { vals: vec![Value::test_string("hello"), Value::test_string("array")], - span: Span::unknown(), + span: Span::test_data(), }, ); - let tv = value_to_toml_value(&Value::from(Spanned { - item: m, - span: Span::unknown(), - })) + let tv = value_to_toml_value( + &Value::from(Spanned { + item: m, + span: Span::test_data(), + }), + Span::test_data(), + ) .expect("Expected Ok from valid TOML dictionary"); assert_eq!( tv.get("features"), @@ -193,8 +196,9 @@ mod tests { ])) ); // TOML string - let tv = value_to_toml_value(&Value::test_string( - r#" + let tv = value_to_toml_value( + &Value::test_string( + r#" title = "TOML Example" [owner] @@ -206,7 +210,9 @@ mod tests { sysinfo = "0.8.4" chrono = { version = "0.4.6", features = ["serde"] } "#, - )) + ), + Span::test_data(), + ) .expect("Expected Ok from valid TOML string"); assert_eq!( tv.get("title").unwrap(), @@ -215,12 +221,15 @@ mod tests { // // Negative Tests // - value_to_toml_value(&Value::test_string("not_valid")) + value_to_toml_value(&Value::test_string("not_valid"), Span::test_data()) .expect_err("Expected non-valid toml (String) to cause error!"); - value_to_toml_value(&Value::List { - vals: vec![Value::test_string("1")], - span: Span::unknown(), - }) + value_to_toml_value( + &Value::List { + vals: vec![Value::test_string("1")], + span: Span::test_data(), + }, + Span::test_data(), + ) .expect_err("Expected non-valid toml (Table) to cause error!"); } } diff --git a/crates/nu-command/src/formats/to/url.rs b/crates/nu-command/src/formats/to/url.rs index 718218b1eb..ec157f8976 100644 --- a/crates/nu-command/src/formats/to/url.rs +++ b/crates/nu-command/src/formats/to/url.rs @@ -73,7 +73,7 @@ fn to_url(input: PipelineData, head: Span) -> Result { } other => Err(ShellError::UnsupportedInput( "Expected a table from pipeline".to_string(), - other.span().unwrap_or_else(|_| Span::unknown()), + other.span().unwrap_or(head), )), }) .collect(); diff --git a/crates/nu-command/src/hash/md5.rs b/crates/nu-command/src/hash/md5.rs index bfaa8f8e1e..5d1af8fc06 100644 --- a/crates/nu-command/src/hash/md5.rs +++ b/crates/nu-command/src/hash/md5.rs @@ -16,7 +16,7 @@ impl HashDigest for Md5 { example: "echo 'abcdefghijklmnopqrstuvwxyz' | hash md5", result: Some(Value::String { val: "c3fcd3d76192e4007dfb496cca67e13b".to_owned(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -42,11 +42,11 @@ mod tests { fn hash_string() { let binary = Value::String { val: "abcdefghijklmnopqrstuvwxyz".to_owned(), - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::String { val: "c3fcd3d76192e4007dfb496cca67e13b".to_owned(), - span: Span::unknown(), + span: Span::test_data(), }; let actual = generic_digest::action::(&binary); assert_eq!(actual, expected); @@ -56,11 +56,11 @@ mod tests { fn hash_bytes() { let binary = Value::Binary { val: vec![0xC0, 0xFF, 0xEE], - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::String { val: "5f80e231382769b0102b1164cf722d83".to_owned(), - span: Span::unknown(), + span: Span::test_data(), }; let actual = generic_digest::action::(&binary); assert_eq!(actual, expected); diff --git a/crates/nu-command/src/hash/sha256.rs b/crates/nu-command/src/hash/sha256.rs index 7a63e90d8e..5c1485a35e 100644 --- a/crates/nu-command/src/hash/sha256.rs +++ b/crates/nu-command/src/hash/sha256.rs @@ -17,7 +17,7 @@ impl HashDigest for Sha256 { result: Some(Value::String { val: "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73" .to_owned(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -43,11 +43,11 @@ mod tests { fn hash_string() { let binary = Value::String { val: "abcdefghijklmnopqrstuvwxyz".to_owned(), - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::String { val: "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73".to_owned(), - span: Span::unknown(), + span: Span::test_data(), }; let actual = generic_digest::action::(&binary); assert_eq!(actual, expected); @@ -57,11 +57,11 @@ mod tests { fn hash_bytes() { let binary = Value::Binary { val: vec![0xC0, 0xFF, 0xEE], - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::String { val: "c47a10dc272b1221f0380a2ae0f7d7fa830b3e378f2f5309bbf13f61ad211913".to_owned(), - span: Span::unknown(), + span: Span::test_data(), }; let actual = generic_digest::action::(&binary); assert_eq!(actual, expected); diff --git a/crates/nu-command/src/lib.rs b/crates/nu-command/src/lib.rs index ce17687562..5d82ffe0e1 100644 --- a/crates/nu-command/src/lib.rs +++ b/crates/nu-command/src/lib.rs @@ -26,6 +26,7 @@ pub use core_commands::*; pub use date::*; pub use default_context::*; pub use env::*; +#[cfg(test)] pub use example_test::test_examples; pub use experimental::*; pub use filesystem::*; diff --git a/crates/nu-command/src/math/abs.rs b/crates/nu-command/src/math/abs.rs index 89341b89ae..fa3ece0a2b 100644 --- a/crates/nu-command/src/math/abs.rs +++ b/crates/nu-command/src/math/abs.rs @@ -41,11 +41,11 @@ impl Command for SubCommand { Value::test_int(50), Value::Float { val: 100.0, - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(25), ], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/math/avg.rs b/crates/nu-command/src/math/avg.rs index a5f6841a77..f8d0c11187 100644 --- a/crates/nu-command/src/math/avg.rs +++ b/crates/nu-command/src/math/avg.rs @@ -36,7 +36,7 @@ impl Command for SubCommand { example: "[-50 100.0 25] | math avg", result: Some(Value::Float { val: 25.0, - span: Span::unknown(), + span: Span::test_data(), }), }] } @@ -47,7 +47,7 @@ pub fn average(values: &[Value], head: &Span) -> Result { let total = &sum( Value::Int { val: 0, - span: Span::unknown(), + span: *head, }, values.to_vec(), *head, diff --git a/crates/nu-command/src/math/ceil.rs b/crates/nu-command/src/math/ceil.rs index b9e032ee54..ffc2a3b069 100644 --- a/crates/nu-command/src/math/ceil.rs +++ b/crates/nu-command/src/math/ceil.rs @@ -38,7 +38,7 @@ impl Command for SubCommand { example: "[1.5 2.3 -3.1] | math ceil", result: Some(Value::List { vals: vec![Value::test_int(2), Value::test_int(3), Value::test_int(-3)], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/math/eval.rs b/crates/nu-command/src/math/eval.rs index 1cfd6ec425..02bc56f3d2 100644 --- a/crates/nu-command/src/math/eval.rs +++ b/crates/nu-command/src/math/eval.rs @@ -35,7 +35,7 @@ impl Command for SubCommand { input: PipelineData, ) -> Result { let spanned_expr: Option> = call.opt(engine_state, stack, 0)?; - eval(spanned_expr, input, engine_state) + eval(spanned_expr, input, engine_state, call.head) } fn examples(&self) -> Vec { @@ -44,7 +44,7 @@ impl Command for SubCommand { example: "'10 / 4' | math eval", result: Some(Value::Float { val: 2.5, - span: Span::unknown(), + span: Span::test_data(), }), }] } @@ -54,6 +54,7 @@ pub fn eval( spanned_expr: Option>, input: PipelineData, engine_state: &EngineState, + head: Span, ) -> Result { if let Some(expr) = spanned_expr { match parse(&expr.item, &expr.span) { @@ -70,12 +71,12 @@ pub fn eval( input.map( move |val| { if let Ok(string) = val.as_string() { - match parse(&string, &val.span().unwrap_or_else(|_| Span::unknown())) { + match parse(&string, &val.span().unwrap_or(head)) { Ok(value) => value, Err(err) => Value::Error { error: ShellError::UnsupportedInput( format!("Math evaluation error: {}", err), - val.span().unwrap_or_else(|_| Span::unknown()), + val.span().unwrap_or(head), ), }, } @@ -83,7 +84,7 @@ pub fn eval( Value::Error { error: ShellError::UnsupportedInput( "Expected a string from pipeline".to_string(), - val.span().unwrap_or_else(|_| Span::unknown()), + val.span().unwrap_or(head), ), } } diff --git a/crates/nu-command/src/math/floor.rs b/crates/nu-command/src/math/floor.rs index cd8811d111..5442eaf2e1 100644 --- a/crates/nu-command/src/math/floor.rs +++ b/crates/nu-command/src/math/floor.rs @@ -38,7 +38,7 @@ impl Command for SubCommand { example: "[1.5 2.3 -3.1] | math floor", result: Some(Value::List { vals: vec![Value::test_int(1), Value::test_int(2), Value::test_int(-4)], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/math/median.rs b/crates/nu-command/src/math/median.rs index a5b91cf505..cae1499a8f 100644 --- a/crates/nu-command/src/math/median.rs +++ b/crates/nu-command/src/math/median.rs @@ -38,7 +38,7 @@ impl Command for SubCommand { example: "[3 8 9 12 12 15] | math median", result: Some(Value::Float { val: 10.5, - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/math/mode.rs b/crates/nu-command/src/math/mode.rs index 03f3e3e222..4115a4f07b 100644 --- a/crates/nu-command/src/math/mode.rs +++ b/crates/nu-command/src/math/mode.rs @@ -59,7 +59,7 @@ impl Command for SubCommand { example: "[3 3 9 12 12 15] | math mode", result: Some(Value::List { vals: vec![Value::test_int(3), Value::test_int(12)], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/math/reducers.rs b/crates/nu-command/src/math/reducers.rs index 68a41ff770..8f8eca2a74 100644 --- a/crates/nu-command/src/math/reducers.rs +++ b/crates/nu-command/src/math/reducers.rs @@ -103,7 +103,7 @@ pub fn sum(data: Vec, head: Span) -> Result { other => { return Err(ShellError::UnsupportedInput( "Attempted to compute the sum of a value that cannot be summed".to_string(), - other.span().unwrap_or_else(|_| Span::unknown()), + other.span().unwrap_or(head), )); } } @@ -121,7 +121,7 @@ pub fn product(data: Vec, head: Span) -> Result { }), None => Err(ShellError::UnsupportedInput( "Empty input".to_string(), - Span::unknown(), + head, )), _ => Ok(Value::nothing(head)), }?; @@ -135,7 +135,7 @@ pub fn product(data: Vec, head: Span) -> Result { return Err(ShellError::UnsupportedInput( "Attempted to compute the product of a value that cannot be multiplied" .to_string(), - other.span().unwrap_or_else(|_| Span::unknown()), + other.span().unwrap_or(head), )); } } diff --git a/crates/nu-command/src/math/round.rs b/crates/nu-command/src/math/round.rs index 1b6b9db5f7..06b0b601ea 100644 --- a/crates/nu-command/src/math/round.rs +++ b/crates/nu-command/src/math/round.rs @@ -50,7 +50,7 @@ impl Command for SubCommand { example: "[1.5 2.3 -3.1] | math round", result: Some(Value::List { vals: vec![Value::test_int(2), Value::test_int(2), Value::test_int(-3)], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -60,18 +60,18 @@ impl Command for SubCommand { vals: vec![ Value::Float { val: 1.56, - span: Span::unknown(), + span: Span::test_data(), }, Value::Float { val: 2.33, - span: Span::unknown(), + span: Span::test_data(), }, Value::Float { val: -3.11, - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/math/sqrt.rs b/crates/nu-command/src/math/sqrt.rs index 7cb9ca4d12..dcf50ac32e 100644 --- a/crates/nu-command/src/math/sqrt.rs +++ b/crates/nu-command/src/math/sqrt.rs @@ -38,7 +38,7 @@ impl Command for SubCommand { example: "[9 16] | math sqrt", result: Some(Value::List { vals: vec![Value::test_int(3), Value::test_int(4)], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/math/stddev.rs b/crates/nu-command/src/math/stddev.rs index f7b231f277..d7d370dd8a 100644 --- a/crates/nu-command/src/math/stddev.rs +++ b/crates/nu-command/src/math/stddev.rs @@ -40,7 +40,7 @@ impl Command for SubCommand { example: "[1 2 3 4 5] | math stddev", result: Some(Value::Float { val: std::f64::consts::SQRT_2, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -48,7 +48,7 @@ impl Command for SubCommand { example: "[1 2 3 4 5] | math stddev -s", result: Some(Value::Float { val: 1.5811388300841898, - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/math/variance.rs b/crates/nu-command/src/math/variance.rs index 6252a49f87..50ca64c20f 100644 --- a/crates/nu-command/src/math/variance.rs +++ b/crates/nu-command/src/math/variance.rs @@ -39,7 +39,7 @@ impl Command for SubCommand { example: "echo [1 2 3 4 5] | math variance", result: Some(Value::Float { val: 2.0, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -47,7 +47,7 @@ impl Command for SubCommand { example: "[1 2 3 4 5] | math variance -s", result: Some(Value::Float { val: 2.5, - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -75,7 +75,7 @@ fn sum_of_squares(values: &[Value], span: &Span) -> Result { }, _ => Err(ShellError::UnsupportedInput( "Attempted to compute the sum of squared values of a value that cannot be summed or squared.".to_string(), - value.span().unwrap_or_else(|_| Span::unknown()), + value.span().unwrap_or(*span), )) }?; let v_squared = &v.mul(*span, v)?; diff --git a/crates/nu-command/src/network/url/host.rs b/crates/nu-command/src/network/url/host.rs index 215c268758..18332bc5b5 100644 --- a/crates/nu-command/src/network/url/host.rs +++ b/crates/nu-command/src/network/url/host.rs @@ -36,7 +36,7 @@ impl Command for SubCommand { } fn examples(&self) -> Vec { - let span = Span::unknown(); + let span = Span::test_data(); vec![Example { description: "Get host of a url", example: "echo 'http://www.example.com/foo/bar' | url host", diff --git a/crates/nu-command/src/network/url/path.rs b/crates/nu-command/src/network/url/path.rs index c25b28557b..4096a0e14b 100644 --- a/crates/nu-command/src/network/url/path.rs +++ b/crates/nu-command/src/network/url/path.rs @@ -36,7 +36,7 @@ impl Command for SubCommand { } fn examples(&self) -> Vec { - let span = Span::unknown(); + let span = Span::test_data(); vec![ Example { description: "Get path of a url", diff --git a/crates/nu-command/src/network/url/query.rs b/crates/nu-command/src/network/url/query.rs index b5b4c8ba38..5c9ff7700e 100644 --- a/crates/nu-command/src/network/url/query.rs +++ b/crates/nu-command/src/network/url/query.rs @@ -36,7 +36,7 @@ impl Command for SubCommand { } fn examples(&self) -> Vec { - let span = Span::unknown(); + let span = Span::test_data(); vec![ Example { description: "Get query of a url", diff --git a/crates/nu-command/src/network/url/scheme.rs b/crates/nu-command/src/network/url/scheme.rs index 61c968b8dd..b95d3e2eff 100644 --- a/crates/nu-command/src/network/url/scheme.rs +++ b/crates/nu-command/src/network/url/scheme.rs @@ -36,7 +36,7 @@ impl Command for SubCommand { } fn examples(&self) -> Vec { - let span = Span::unknown(); + let span = Span::test_data(); vec![ Example { description: "Get scheme of a url", diff --git a/crates/nu-command/src/path/basename.rs b/crates/nu-command/src/path/basename.rs index 5888a7035e..223a86d5c1 100644 --- a/crates/nu-command/src/path/basename.rs +++ b/crates/nu-command/src/path/basename.rs @@ -83,9 +83,9 @@ impl Command for SubCommand { vals: vec![Value::Record { cols: vec!["name".to_string()], vals: vec![Value::test_string("Joe")], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -111,9 +111,9 @@ impl Command for SubCommand { vals: vec![Value::Record { cols: vec!["name".to_string()], vals: vec![Value::test_string("joe")], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { diff --git a/crates/nu-command/src/path/exists.rs b/crates/nu-command/src/path/exists.rs index 1a9f2b0adc..343c38e91c 100644 --- a/crates/nu-command/src/path/exists.rs +++ b/crates/nu-command/src/path/exists.rs @@ -62,7 +62,7 @@ impl Command for SubCommand { example: "'C:\\Users\\joe\\todo.txt' | path exists", result: Some(Value::Bool { val: false, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -81,7 +81,7 @@ impl Command for SubCommand { example: "'/home/joe/todo.txt' | path exists", result: Some(Value::Bool { val: false, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { diff --git a/crates/nu-command/src/path/join.rs b/crates/nu-command/src/path/join.rs index 48145ca8c3..4f4dbca62f 100644 --- a/crates/nu-command/src/path/join.rs +++ b/crates/nu-command/src/path/join.rs @@ -104,7 +104,7 @@ the output of 'path parse' and 'path split' subcommands."# example: r"[ [parent stem extension]; ['C:\Users\viking' 'spam' 'txt']] | path join", result: Some(Value::List { vals: vec![Value::test_string(r"C:\Users\viking\spam.txt")], - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -133,7 +133,7 @@ the output of 'path parse' and 'path split' subcommands."# example: r"[[ parent stem extension ]; [ '/home/viking' 'spam' 'txt' ]] | path join", result: Some(Value::List { vals: vec![Value::test_string(r"/home/viking/spam.txt")], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/path/split.rs b/crates/nu-command/src/path/split.rs index 26574c23f6..dc98a3f8ba 100644 --- a/crates/nu-command/src/path/split.rs +++ b/crates/nu-command/src/path/split.rs @@ -68,7 +68,7 @@ impl Command for SubCommand { Value::test_string("viking"), Value::test_string("spam.txt"), ], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -92,7 +92,7 @@ impl Command for SubCommand { Value::test_string("viking"), Value::test_string("spam.txt"), ], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { diff --git a/crates/nu-command/src/platform/ansi/gradient.rs b/crates/nu-command/src/platform/ansi/gradient.rs index d3d4a87807..1b1c269a8b 100644 --- a/crates/nu-command/src/platform/ansi/gradient.rs +++ b/crates/nu-command/src/platform/ansi/gradient.rs @@ -309,7 +309,7 @@ mod tests { Some(fg_end), None, None, - &Span::unknown(), + &Span::test_data(), ); assert_eq!(actual, expected); } diff --git a/crates/nu-command/src/platform/ansi/strip.rs b/crates/nu-command/src/platform/ansi/strip.rs index 987f4e460a..d3032fa2b6 100644 --- a/crates/nu-command/src/platform/ansi/strip.rs +++ b/crates/nu-command/src/platform/ansi/strip.rs @@ -117,7 +117,7 @@ mod tests { Value::test_string("\u{1b}[3;93;41mHello\u{1b}[0m \u{1b}[1;32mNu \u{1b}[1;35mWorld"); let expected = Value::test_string("Hello Nu World"); - let actual = action(&input_string, &Span::unknown()); + let actual = action(&input_string, &Span::test_data()); assert_eq!(actual, expected); } } diff --git a/crates/nu-command/src/strings/build_string.rs b/crates/nu-command/src/strings/build_string.rs index b9b58f6ff1..8046a8f0f9 100644 --- a/crates/nu-command/src/strings/build_string.rs +++ b/crates/nu-command/src/strings/build_string.rs @@ -31,7 +31,7 @@ impl Command for BuildString { description: "Builds a string from letters a b c", result: Some(Value::String { val: "abc".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -39,7 +39,7 @@ impl Command for BuildString { description: "Builds a string from letters a b c", result: Some(Value::String { val: "3=one plus two".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/format/command.rs b/crates/nu-command/src/strings/format/command.rs index 28efcd003f..db36518086 100644 --- a/crates/nu-command/src/strings/format/command.rs +++ b/crates/nu-command/src/strings/format/command.rs @@ -57,7 +57,7 @@ impl Command for Format { example: "echo [[col1, col2]; [v1, v2] [v3, v4]] | format '{col2}'", result: Some(Value::List { vals: vec![Value::test_string("v2"), Value::test_string("v4")], - span: Span::new(0, 0), + span: Span::test_data(), }), }, ] @@ -124,11 +124,8 @@ fn format( // We can only handle a Record or a List of Record's match data_as_value { - Value::Record { .. } => match format_record(format_operations, &data_as_value) { - Ok(value) => Ok(PipelineData::Value( - Value::string(value, Span::unknown()), - None, - )), + Value::Record { .. } => match format_record(format_operations, &data_as_value, span) { + Ok(value) => Ok(PipelineData::Value(Value::string(value, span), None)), Err(value) => Err(value), }, @@ -136,9 +133,9 @@ fn format( let mut list = vec![]; for val in vals.iter() { match val { - Value::Record { .. } => match format_record(format_operations, val) { + Value::Record { .. } => match format_record(format_operations, val, span) { Ok(value) => { - list.push(Value::string(value, Span::unknown())); + list.push(Value::string(value, span)); } Err(value) => { return Err(value); @@ -148,7 +145,7 @@ fn format( _ => { return Err(ShellError::UnsupportedInput( "Input data is not supported by this command.".to_string(), - Span::unknown(), + span, )) } } @@ -161,7 +158,7 @@ fn format( } _ => Err(ShellError::UnsupportedInput( "Input data is not supported by this command.".to_string(), - Span::unknown(), + span, )), } } @@ -169,6 +166,7 @@ fn format( fn format_record( format_operations: &[FormatOperation], data_as_value: &Value, + span: Span, ) -> Result { let mut output = String::new(); for op in format_operations { @@ -182,7 +180,7 @@ fn format_record( .clone() .follow_cell_path(&[PathMember::String { val: col_name.clone(), - span: Span::unknown(), + span, }]) { Ok(value_at_column) => output.push_str(value_at_column.as_string()?.as_str()), Err(se) => return Err(se), diff --git a/crates/nu-command/src/strings/parse.rs b/crates/nu-command/src/strings/parse.rs index b17c4bd7fb..8e4bb2d6ae 100644 --- a/crates/nu-command/src/strings/parse.rs +++ b/crates/nu-command/src/strings/parse.rs @@ -35,9 +35,9 @@ impl Command for Parse { vals: vec![Value::Record { cols: vec!["foo".to_string(), "bar".to_string()], vals: vec![Value::test_string("hi"), Value::test_string("there")], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }; vec![ diff --git a/crates/nu-command/src/strings/size.rs b/crates/nu-command/src/strings/size.rs index ad6d369944..db9faabdd8 100644 --- a/crates/nu-command/src/strings/size.rs +++ b/crates/nu-command/src/strings/size.rs @@ -47,22 +47,22 @@ impl Command for Size { vals: vec![ Value::Int { val: 0, - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 7, - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 38, - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 38, - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -78,22 +78,22 @@ impl Command for Size { vals: vec![ Value::Int { val: 0, - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 2, - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 13, - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 15, - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/split/chars.rs b/crates/nu-command/src/strings/split/chars.rs index caeacf2595..c633dc6d4f 100644 --- a/crates/nu-command/src/strings/split/chars.rs +++ b/crates/nu-command/src/strings/split/chars.rs @@ -32,7 +32,7 @@ impl Command for SubCommand { Value::test_string("l"), Value::test_string("o"), ], - span: Span::unknown(), + span: Span::test_data(), }), }] } diff --git a/crates/nu-command/src/strings/str_/capitalize.rs b/crates/nu-command/src/strings/str_/capitalize.rs index e674a4306b..fb11969058 100644 --- a/crates/nu-command/src/strings/str_/capitalize.rs +++ b/crates/nu-command/src/strings/str_/capitalize.rs @@ -44,7 +44,7 @@ impl Command for SubCommand { example: "'good day' | str capitalize", result: Some(Value::String { val: "Good day".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -52,7 +52,7 @@ impl Command for SubCommand { example: "'anton' | str capitalize", result: Some(Value::String { val: "Anton".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -60,17 +60,17 @@ impl Command for SubCommand { example: "[[lang, gems]; [nu_test, 100]] | str capitalize lang", result: Some(Value::List { vals: vec![Value::Record { - span: Span::unknown(), + span: Span::test_data(), cols: vec!["lang".to_string(), "gems".to_string()], vals: vec![ Value::String { val: "Nu_test".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -117,7 +117,7 @@ fn action(input: &Value, head: Span) -> Value { "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/case/camel_case.rs b/crates/nu-command/src/strings/str_/case/camel_case.rs index db545453dc..5ca2e5c9af 100644 --- a/crates/nu-command/src/strings/str_/case/camel_case.rs +++ b/crates/nu-command/src/strings/str_/case/camel_case.rs @@ -46,7 +46,7 @@ impl Command for SubCommand { example: " 'NuShell' | str camel-case", result: Some(Value::String { val: "nuShell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -54,7 +54,7 @@ impl Command for SubCommand { example: "'this-is-the-first-case' | str camel-case", result: Some(Value::String { val: "thisIsTheFirstCase".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -62,7 +62,7 @@ impl Command for SubCommand { example: " 'this_is_the_second_case' | str camel-case", result: Some(Value::String { val: "thisIsTheSecondCase".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -70,17 +70,17 @@ impl Command for SubCommand { example: r#"[[lang, gems]; [nu_test, 100]] | str camel-case lang"#, result: Some(Value::List { vals: vec![Value::Record { - span: Span::unknown(), + span: Span::test_data(), cols: vec!["lang".to_string(), "gems".to_string()], vals: vec![ Value::String { val: "nuTest".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/str_/case/kebab_case.rs b/crates/nu-command/src/strings/str_/case/kebab_case.rs index a1afc324c6..377cf4b182 100644 --- a/crates/nu-command/src/strings/str_/case/kebab_case.rs +++ b/crates/nu-command/src/strings/str_/case/kebab_case.rs @@ -46,7 +46,7 @@ impl Command for SubCommand { example: "'NuShell' | str kebab-case", result: Some(Value::String { val: "nu-shell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -54,7 +54,7 @@ impl Command for SubCommand { example: "'thisIsTheFirstCase' | str kebab-case", result: Some(Value::String { val: "this-is-the-first-case".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -62,7 +62,7 @@ impl Command for SubCommand { example: "'THIS_IS_THE_SECOND_CASE' | str kebab-case", result: Some(Value::String { val: "this-is-the-second-case".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -70,17 +70,17 @@ impl Command for SubCommand { example: r#"[[lang, gems]; [nuTest, 100]] | str kebab-case lang"#, result: Some(Value::List { vals: vec![Value::Record { - span: Span::unknown(), + span: Span::test_data(), cols: vec!["lang".to_string(), "gems".to_string()], vals: vec![ Value::String { val: "nu-test".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/str_/case/mod.rs b/crates/nu-command/src/strings/str_/case/mod.rs index 0d26d6c2ee..d2580c2aec 100644 --- a/crates/nu-command/src/strings/str_/case/mod.rs +++ b/crates/nu-command/src/strings/str_/case/mod.rs @@ -68,7 +68,7 @@ where "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/case/pascal_case.rs b/crates/nu-command/src/strings/str_/case/pascal_case.rs index 44dd100062..2f9729c5ab 100644 --- a/crates/nu-command/src/strings/str_/case/pascal_case.rs +++ b/crates/nu-command/src/strings/str_/case/pascal_case.rs @@ -46,7 +46,7 @@ impl Command for SubCommand { example: "'nu-shell' | str pascal-case", result: Some(Value::String { val: "NuShell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -54,7 +54,7 @@ impl Command for SubCommand { example: "'this-is-the-first-case' | str pascal-case", result: Some(Value::String { val: "ThisIsTheFirstCase".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -62,7 +62,7 @@ impl Command for SubCommand { example: "'this_is_the_second_case' | str pascal-case", result: Some(Value::String { val: "ThisIsTheSecondCase".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -70,17 +70,17 @@ impl Command for SubCommand { example: r#"[[lang, gems]; [nu_test, 100]] | str pascal-case lang"#, result: Some(Value::List { vals: vec![Value::Record { - span: Span::unknown(), + span: Span::test_data(), cols: vec!["lang".to_string(), "gems".to_string()], vals: vec![ Value::String { val: "NuTest".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs b/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs index e924c1ed6f..8083440f74 100644 --- a/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs +++ b/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs @@ -45,7 +45,7 @@ impl Command for SubCommand { example: r#" "NuShell" | str screaming-snake-case"#, result: Some(Value::String { val: "NU_SHELL".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -53,7 +53,7 @@ impl Command for SubCommand { example: r#" "this_is_the_second_case" | str screaming-snake-case"#, result: Some(Value::String { val: "THIS_IS_THE_SECOND_CASE".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -61,7 +61,7 @@ impl Command for SubCommand { example: r#""this-is-the-first-case" | str screaming-snake-case"#, result: Some(Value::String { val: "THIS_IS_THE_FIRST_CASE".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -69,17 +69,17 @@ impl Command for SubCommand { example: r#"[[lang, gems]; [nu_test, 100]] | str screaming-snake-case lang"#, result: Some(Value::List { vals: vec![Value::Record { - span: Span::unknown(), + span: Span::test_data(), cols: vec!["lang".to_string(), "gems".to_string()], vals: vec![ Value::String { val: "NU_TEST".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/str_/case/snake_case.rs b/crates/nu-command/src/strings/str_/case/snake_case.rs index 4a98186776..5dda6e799d 100644 --- a/crates/nu-command/src/strings/str_/case/snake_case.rs +++ b/crates/nu-command/src/strings/str_/case/snake_case.rs @@ -44,7 +44,7 @@ impl Command for SubCommand { example: r#" "NuShell" | str snake-case"#, result: Some(Value::String { val: "nu_shell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -52,7 +52,7 @@ impl Command for SubCommand { example: r#" "this_is_the_second_case" | str snake-case"#, result: Some(Value::String { val: "this_is_the_second_case".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -60,7 +60,7 @@ impl Command for SubCommand { example: r#""this-is-the-first-case" | str snake-case"#, result: Some(Value::String { val: "this_is_the_first_case".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -68,17 +68,17 @@ impl Command for SubCommand { example: r#"[[lang, gems]; [nuTest, 100]] | str snake-case lang"#, result: Some(Value::List { vals: vec![Value::Record { - span: Span::unknown(), + span: Span::test_data(), cols: vec!["lang".to_string(), "gems".to_string()], vals: vec![ Value::String { val: "nu_test".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/str_/collect.rs b/crates/nu-command/src/strings/str_/collect.rs index a99b172b90..5547fadf2b 100644 --- a/crates/nu-command/src/strings/str_/collect.rs +++ b/crates/nu-command/src/strings/str_/collect.rs @@ -67,7 +67,7 @@ impl Command for StrCollect { example: "['nu', 'shell'] | str collect", result: Some(Value::String { val: "nushell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -75,7 +75,7 @@ impl Command for StrCollect { example: "['nu', 'shell'] | str collect '-'", result: Some(Value::String { val: "nu-shell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, ] diff --git a/crates/nu-command/src/strings/str_/contains.rs b/crates/nu-command/src/strings/str_/contains.rs index 7d50537a41..eb95733eab 100644 --- a/crates/nu-command/src/strings/str_/contains.rs +++ b/crates/nu-command/src/strings/str_/contains.rs @@ -48,7 +48,7 @@ impl Command for SubCommand { example: "'my_library.rb' | str contains '.rb'", result: Some(Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -56,7 +56,7 @@ impl Command for SubCommand { example: "'my_library.rb' | str contains -i '.RB'", result: Some(Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -68,13 +68,13 @@ impl Command for SubCommand { vals: vec![ Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -86,13 +86,13 @@ impl Command for SubCommand { vals: vec![ Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }, Value::test_int(100), ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -104,16 +104,16 @@ impl Command for SubCommand { vals: vec![ Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }, Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -121,7 +121,7 @@ impl Command for SubCommand { example: "'hello' | str contains 'banana'", result: Some(Value::Bool { val: false, - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -177,7 +177,7 @@ fn action(input: &Value, case_insensitive: bool, pattern: &str, head: Span) -> V "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/downcase.rs b/crates/nu-command/src/strings/str_/downcase.rs index df8127497b..d048d8c814 100644 --- a/crates/nu-command/src/strings/str_/downcase.rs +++ b/crates/nu-command/src/strings/str_/downcase.rs @@ -44,7 +44,7 @@ impl Command for SubCommand { example: "'NU' | str downcase", result: Some(Value::String { val: "nu".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -52,7 +52,7 @@ impl Command for SubCommand { example: "'TESTa' | str downcase", result: Some(Value::String { val: "testa".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -64,16 +64,16 @@ impl Command for SubCommand { vals: vec![ Value::String { val: "test".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "ABC".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -85,16 +85,16 @@ impl Command for SubCommand { vals: vec![ Value::String { val: "test".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "abc".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -141,7 +141,7 @@ fn action(input: &Value, head: Span) -> Value { "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/ends_with.rs b/crates/nu-command/src/strings/str_/ends_with.rs index 059ccbd52f..342f177f95 100644 --- a/crates/nu-command/src/strings/str_/ends_with.rs +++ b/crates/nu-command/src/strings/str_/ends_with.rs @@ -46,7 +46,7 @@ impl Command for SubCommand { example: "'my_library.rb' | str ends-with '.rb'", result: Some(Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -54,7 +54,7 @@ impl Command for SubCommand { example: "'my_library.rb' | str ends-with '.txt'", result: Some(Value::Bool { val: false, - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -106,7 +106,7 @@ fn action(input: &Value, pattern: &str, head: Span) -> Value { "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/find_replace.rs b/crates/nu-command/src/strings/str_/find_replace.rs index d486cb66bf..2d0ac02c01 100644 --- a/crates/nu-command/src/strings/str_/find_replace.rs +++ b/crates/nu-command/src/strings/str_/find_replace.rs @@ -57,7 +57,7 @@ impl Command for SubCommand { example: "'my_library.rb' | str find-replace '(.+).rb' '$1.nu'", result: Some(Value::String { val: "my_library.nu".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -65,7 +65,7 @@ impl Command for SubCommand { example: "'abc abc abc' | str find-replace -a 'b' 'z'", result: Some(Value::String { val: "azc azc azc".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -78,20 +78,20 @@ impl Command for SubCommand { vals: vec![ Value::String { val: "azc".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "abc".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "ads".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }], - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -177,7 +177,7 @@ fn action( "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } @@ -199,7 +199,7 @@ mod tests { fn can_have_capture_groups() { let word = Value::String { val: "Cargo.toml".to_string(), - span: Span::unknown(), + span: Span::test_data(), }; let options = Arguments { @@ -209,12 +209,12 @@ mod tests { all: false, }; - let actual = action(&word, &options, Span::unknown()); + let actual = action(&word, &options, Span::test_data()); assert_eq!( actual, Value::String { val: "Carga.toml".to_string(), - span: Span::unknown() + span: Span::test_data() } ); } diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index af58b3775b..26c46648d4 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -192,7 +192,7 @@ fn action( "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } @@ -284,7 +284,7 @@ mod tests { fn returns_index_of_substring() { let word = Value::String { val: String::from("Cargo.tomL"), - span: Span::unknown(), + span: Span::test_data(), }; let options = Arguments { @@ -292,13 +292,13 @@ mod tests { range: Some(Value::String { val: String::from(""), - span: Span::unknown(), + span: Span::test_data(), }), column_paths: vec![], end: false, }; - let actual = action(&word, &options, Span::unknown()); + let actual = action(&word, &options, Span::test_data()); assert_eq!(actual, Value::test_int(5)); } @@ -306,7 +306,7 @@ mod tests { fn index_of_does_not_exist_in_string() { let word = Value::String { val: String::from("Cargo.tomL"), - span: Span::unknown(), + span: Span::test_data(), }; let options = Arguments { @@ -314,13 +314,13 @@ mod tests { range: Some(Value::String { val: String::from(""), - span: Span::unknown(), + span: Span::test_data(), }), column_paths: vec![], end: false, }; - let actual = action(&word, &options, Span::unknown()); + let actual = action(&word, &options, Span::test_data()); assert_eq!(actual, Value::test_int(-1)); } @@ -329,7 +329,7 @@ mod tests { fn returns_index_of_next_substring() { let word = Value::String { val: String::from("Cargo.Cargo"), - span: Span::unknown(), + span: Span::test_data(), }; let options = Arguments { @@ -337,13 +337,13 @@ mod tests { range: Some(Value::String { val: String::from("1"), - span: Span::unknown(), + span: Span::test_data(), }), column_paths: vec![], end: false, }; - let actual = action(&word, &options, Span::unknown()); + let actual = action(&word, &options, Span::test_data()); assert_eq!(actual, Value::test_int(6)); } @@ -351,7 +351,7 @@ mod tests { fn index_does_not_exist_due_to_end_index() { let word = Value::String { val: String::from("Cargo.Banana"), - span: Span::unknown(), + span: Span::test_data(), }; let options = Arguments { @@ -359,13 +359,13 @@ mod tests { range: Some(Value::String { val: String::from(",5"), - span: Span::unknown(), + span: Span::test_data(), }), column_paths: vec![], end: false, }; - let actual = action(&word, &options, Span::unknown()); + let actual = action(&word, &options, Span::test_data()); assert_eq!(actual, Value::test_int(-1)); } @@ -373,7 +373,7 @@ mod tests { fn returns_index_of_nums_in_middle_due_to_index_limit_from_both_ends() { let word = Value::String { val: String::from("123123123"), - span: Span::unknown(), + span: Span::test_data(), }; let options = Arguments { @@ -381,13 +381,13 @@ mod tests { range: Some(Value::String { val: String::from("2,6"), - span: Span::unknown(), + span: Span::test_data(), }), column_paths: vec![], end: false, }; - let actual = action(&word, &options, Span::unknown()); + let actual = action(&word, &options, Span::test_data()); assert_eq!(actual, Value::test_int(3)); } @@ -395,7 +395,7 @@ mod tests { fn index_does_not_exists_due_to_strict_bounds() { let word = Value::String { val: String::from("123456"), - span: Span::unknown(), + span: Span::test_data(), }; let options = Arguments { @@ -403,13 +403,13 @@ mod tests { range: Some(Value::String { val: String::from("2,4"), - span: Span::unknown(), + span: Span::test_data(), }), column_paths: vec![], end: false, }; - let actual = action(&word, &options, Span::unknown()); + let actual = action(&word, &options, Span::test_data()); assert_eq!(actual, Value::test_int(-1)); } } diff --git a/crates/nu-command/src/strings/str_/length.rs b/crates/nu-command/src/strings/str_/length.rs index 4945c88c2b..b318f2b185 100644 --- a/crates/nu-command/src/strings/str_/length.rs +++ b/crates/nu-command/src/strings/str_/length.rs @@ -49,7 +49,7 @@ impl Command for SubCommand { example: "['hi' 'there'] | str length", result: Some(Value::List { vals: vec![Value::test_int(2), Value::test_int(5)], - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -96,7 +96,7 @@ fn action(input: &Value, head: Span) -> Value { "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/lpad.rs b/crates/nu-command/src/strings/str_/lpad.rs index a20ae4d32b..8c2bd4fa69 100644 --- a/crates/nu-command/src/strings/str_/lpad.rs +++ b/crates/nu-command/src/strings/str_/lpad.rs @@ -58,7 +58,7 @@ impl Command for SubCommand { example: "'nushell' | str lpad -l 10 -c '*'", result: Some(Value::String { val: "***nushell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -66,7 +66,7 @@ impl Command for SubCommand { example: "'123' | str lpad -l 10 -c '0'", result: Some(Value::String { val: "0000000123".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -74,7 +74,7 @@ impl Command for SubCommand { example: "'123456789' | str lpad -l 3 -c '0'", result: Some(Value::String { val: "123".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -82,7 +82,7 @@ impl Command for SubCommand { example: "'▉' | str lpad -l 10 -c '▉'", result: Some(Value::String { val: "▉▉▉▉▉▉▉▉▉▉".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -154,7 +154,7 @@ fn action( None => Value::Error { error: ShellError::UnsupportedInput( String::from("Length argument is missing"), - Span::unknown(), + head, ), }, }, @@ -164,7 +164,7 @@ fn action( "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/reverse.rs b/crates/nu-command/src/strings/str_/reverse.rs index 8607671513..f89d4a1215 100644 --- a/crates/nu-command/src/strings/str_/reverse.rs +++ b/crates/nu-command/src/strings/str_/reverse.rs @@ -43,7 +43,7 @@ impl Command for SubCommand { example: "'Nushell' | str reverse", result: Some(Value::String { val: "llehsuN".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }] } @@ -90,7 +90,7 @@ fn action(input: &Value, head: Span) -> Value { "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/rpad.rs b/crates/nu-command/src/strings/str_/rpad.rs index 8f7126e0a0..add8be3c70 100644 --- a/crates/nu-command/src/strings/str_/rpad.rs +++ b/crates/nu-command/src/strings/str_/rpad.rs @@ -58,7 +58,7 @@ impl Command for SubCommand { example: "'nushell' | str rpad -l 10 -c '*'", result: Some(Value::String { val: "nushell***".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -66,7 +66,7 @@ impl Command for SubCommand { example: "'123' | str rpad -l 10 -c '0'", result: Some(Value::String { val: "1230000000".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -74,7 +74,7 @@ impl Command for SubCommand { example: "'123456789' | str rpad -l 3 -c '0'", result: Some(Value::String { val: "123".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -82,7 +82,7 @@ impl Command for SubCommand { example: "'▉' | str rpad -l 10 -c '▉'", result: Some(Value::String { val: "▉▉▉▉▉▉▉▉▉▉".to_string(), - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -153,7 +153,7 @@ fn action( None => Value::Error { error: ShellError::UnsupportedInput( String::from("Length argument is missing"), - Span::unknown(), + head, ), }, }, @@ -163,7 +163,7 @@ fn action( "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/starts_with.rs b/crates/nu-command/src/strings/str_/starts_with.rs index 9f26ba3f49..645ea4d6c9 100644 --- a/crates/nu-command/src/strings/str_/starts_with.rs +++ b/crates/nu-command/src/strings/str_/starts_with.rs @@ -53,7 +53,7 @@ impl Command for SubCommand { example: "'my_library.rb' | str starts-with 'my'", result: Some(Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -61,7 +61,7 @@ impl Command for SubCommand { example: "'Cargo.toml' | str starts-with 'Car'", result: Some(Value::Bool { val: true, - span: Span::unknown(), + span: Span::test_data(), }), }, Example { @@ -69,7 +69,7 @@ impl Command for SubCommand { example: "'Cargo.toml' | str starts-with '.toml'", result: Some(Value::Bool { val: false, - span: Span::unknown(), + span: Span::test_data(), }), }, ] @@ -127,7 +127,7 @@ fn action(input: &Value, Arguments { pattern, .. }: &Arguments, head: Span) -> V "Input's type is {}. This command only works with strings.", other.get_type() ), - Span::unknown(), + head, ), }, } diff --git a/crates/nu-command/src/strings/str_/substring.rs b/crates/nu-command/src/strings/str_/substring.rs index f37a42cec0..9e06840ab7 100644 --- a/crates/nu-command/src/strings/str_/substring.rs +++ b/crates/nu-command/src/strings/str_/substring.rs @@ -305,7 +305,7 @@ mod tests { fn substrings_indexes() { let word = Value::String { val: "andres".to_string(), - span: Span::unknown(), + span: Span::test_data(), }; let cases = vec![ @@ -336,13 +336,13 @@ mod tests { for expectation in &cases { let expected = expectation.expected; - let actual = action(&word, &expectation.options(), Span::unknown()); + let actual = action(&word, &expectation.options(), Span::test_data()); assert_eq!( actual, Value::String { val: expected.to_string(), - span: Span::unknown() + span: Span::test_data() } ); } diff --git a/crates/nu-command/src/strings/str_/trim/command.rs b/crates/nu-command/src/strings/str_/trim/command.rs index 98ed9fd558..2063ec0ccc 100644 --- a/crates/nu-command/src/strings/str_/trim/command.rs +++ b/crates/nu-command/src/strings/str_/trim/command.rs @@ -328,10 +328,10 @@ mod tests { .iter() .map(|x| Value::String { val: x.to_string(), - span: Span::unknown(), + span: Span::test_data(), }) .collect(), - span: Span::unknown(), + span: Span::test_data(), } } @@ -341,10 +341,10 @@ mod tests { .iter() .map(|x| Value::String { val: x.to_string(), - span: Span::unknown(), + span: Span::test_data(), }) .collect(), - span: Span::unknown(), + span: Span::test_data(), } } @@ -359,7 +359,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -379,7 +379,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -399,7 +399,7 @@ mod tests { let actual = action( &number, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -420,7 +420,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -440,7 +440,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -460,7 +460,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some('!'), &closure_flags, &trim, @@ -479,7 +479,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some(' '), &closure_flags, &trim, @@ -503,7 +503,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -518,35 +518,35 @@ mod tests { vals: vec![ Value::String { val: " nu shell ".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: " d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::List { vals: vec![ Value::String { val: "nushell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let closure_flags = ClosureFlags { @@ -556,7 +556,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -576,7 +576,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some('.'), &closure_flags, &trim, @@ -596,7 +596,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), Some('!'), &closure_flags, &trim, @@ -611,35 +611,35 @@ mod tests { vals: vec![ Value::String { val: "##nu####shell##".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "#d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::List { vals: vec![ Value::String { val: "nushell".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let closure_flags = ClosureFlags { @@ -649,7 +649,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), Some('#'), &closure_flags, &trim, @@ -669,7 +669,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -689,7 +689,7 @@ mod tests { let actual = action( &number, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -709,7 +709,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -729,7 +729,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -744,35 +744,35 @@ mod tests { vals: vec![ Value::String { val: " a ".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: " d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::List { vals: vec![ Value::String { val: "a ".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let closure_flags = ClosureFlags { @@ -782,7 +782,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -802,7 +802,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some('!'), &closure_flags, &trim, @@ -821,7 +821,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -841,7 +841,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -861,7 +861,7 @@ mod tests { let actual = action( &number, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -881,7 +881,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -896,35 +896,35 @@ mod tests { vals: vec![ Value::String { val: " a ".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: " d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::List { vals: vec![ Value::String { val: " a".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: " d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let closure_flags = ClosureFlags { @@ -934,7 +934,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -954,7 +954,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some('#'), &closure_flags, &trim, @@ -974,7 +974,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some(' '), &closure_flags, &trim, @@ -994,7 +994,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some(' '), &closure_flags, &trim, @@ -1013,7 +1013,7 @@ mod tests { let actual = action( &number, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -1033,7 +1033,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -1048,35 +1048,35 @@ mod tests { vals: vec![ Value::String { val: " a b c d ".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: " b c d e f".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let expected = Value::List { vals: vec![ Value::String { val: "a b c d".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, Value::Int { val: 65, - span: Span::unknown(), + span: Span::test_data(), }, Value::String { val: "b c d e f".to_string(), - span: Span::unknown(), + span: Span::test_data(), }, ], - span: Span::unknown(), + span: Span::test_data(), }; let closure_flags = ClosureFlags { @@ -1086,7 +1086,7 @@ mod tests { let actual = action( &row, - Span::unknown(), + Span::test_data(), None, &closure_flags, &trim, @@ -1106,7 +1106,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some('.'), &closure_flags, &trim, @@ -1127,7 +1127,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some(' '), &closure_flags, &trim, @@ -1148,7 +1148,7 @@ mod tests { let actual = action( &word, - Span::unknown(), + Span::test_data(), Some(' '), &closure_flags, &trim, diff --git a/crates/nu-command/src/strings/str_/upcase.rs b/crates/nu-command/src/strings/str_/upcase.rs index 9f64c74eaa..94f8a58dcb 100644 --- a/crates/nu-command/src/strings/str_/upcase.rs +++ b/crates/nu-command/src/strings/str_/upcase.rs @@ -102,7 +102,7 @@ mod tests { fn upcases() { let word = Value::test_string("andres"); - let actual = action(&word, Span::unknown()); + let actual = action(&word, Span::test_data()); let expected = Value::test_string("ANDRES"); assert_eq!(actual, expected); } diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 543fbe0a24..c8fc256bd1 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -79,7 +79,7 @@ impl Command for External { "PWD".into(), Value::String { val: name.item.clone(), - span: Span::unknown(), + span: call.head, }, ); return Ok(PipelineData::new(call.head)); diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index 7a7ec8a047..d0b36990f2 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -71,7 +71,7 @@ prints out the list properly."# match input { PipelineData::Value(Value::List { vals, .. }, ..) => { // dbg!("value::list"); - let data = convert_to_list(vals, &config); + let data = convert_to_list(vals, &config, call.head); if let Some(items) = data { Ok(create_grid_output( items, @@ -88,7 +88,7 @@ prints out the list properly."# } PipelineData::Stream(stream, ..) => { // dbg!("value::stream"); - let data = convert_to_list(stream, &config); + let data = convert_to_list(stream, &config, call.head); if let Some(items) = data { Ok(create_grid_output( items, @@ -178,7 +178,7 @@ fn create_grid_output( if use_grid_icons { let no_ansi = strip_ansi(&value); let path = std::path::Path::new(&no_ansi); - let icon = icon_for_file(path)?; + let icon = icon_for_file(path, call.head)?; let ls_colors_style = ls_colors.style_for_path(path); // eprintln!("ls_colors_style: {:?}", &ls_colors_style); @@ -236,6 +236,7 @@ fn create_grid_output( fn convert_to_list( iter: impl IntoIterator, config: &Config, + head: Span, ) -> Option> { let mut iter = iter.into_iter().peekable(); @@ -259,7 +260,7 @@ fn convert_to_list( Value::Record { .. } => { item.clone().follow_cell_path(&[PathMember::String { val: header.into(), - span: Span::unknown(), + span: head, }]) } _ => Ok(item.clone()), diff --git a/crates/nu-command/src/viewers/icons.rs b/crates/nu-command/src/viewers/icons.rs index 198ec23984..ed6a4b62d2 100644 --- a/crates/nu-command/src/viewers/icons.rs +++ b/crates/nu-command/src/viewers/icons.rs @@ -130,7 +130,7 @@ lazy_static! { }; } -pub fn icon_for_file(file_path: &Path) -> Result { +pub fn icon_for_file(file_path: &Path, span: Span) -> Result { let extensions = Box::new(FileExtensions); let fp = format!("{}", file_path.display()); @@ -143,7 +143,7 @@ pub fn icon_for_file(file_path: &Path) -> Result { ShellError::SpannedLabeledError( "File name error".into(), "Unable to get file name".into(), - Span::unknown(), + span, ) })? .to_str() @@ -151,7 +151,7 @@ pub fn icon_for_file(file_path: &Path) -> Result { ShellError::SpannedLabeledError( "Unable to get str error".into(), "Unable to convert to str file name".into(), - Span::unknown(), + span, ) })?; Ok(match str { @@ -167,7 +167,7 @@ pub fn icon_for_file(file_path: &Path) -> Result { ShellError::SpannedLabeledError( "Unable to get str error".into(), "Unable to convert to str file name".into(), - Span::unknown(), + span, ) })?; Ok(match str { diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 1f53410533..7071c7eccf 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -52,7 +52,7 @@ impl Command for Table { match input { PipelineData::Value(Value::List { vals, .. }, ..) => { - let table = convert_to_table(0, vals, ctrlc, &config)?; + let table = convert_to_table(0, vals, ctrlc, &config, call.head)?; if let Some(table) = table { let result = nu_table::draw_table(&table, term_width, &color_hm, &config); @@ -220,6 +220,7 @@ fn convert_to_table( iter: impl IntoIterator, ctrlc: Option>, config: &Config, + head: Span, ) -> Result, ShellError> { let mut iter = iter.into_iter().peekable(); let color_hm = get_color_config(config); @@ -257,7 +258,7 @@ fn convert_to_table( Value::Record { .. } => { item.clone().follow_cell_path(&[PathMember::String { val: header.into(), - span: Span::unknown(), + span: head, }]) } _ => Ok(item.clone()), @@ -399,6 +400,7 @@ impl Iterator for PagingTableCreator { batch.into_iter(), self.ctrlc.clone(), &self.config, + self.head, ); self.row_offset += idx; diff --git a/crates/nu-engine/src/documentation.rs b/crates/nu-engine/src/documentation.rs index ed4211e29f..5151f23299 100644 --- a/crates/nu-engine/src/documentation.rs +++ b/crates/nu-engine/src/documentation.rs @@ -15,7 +15,7 @@ pub struct DocumentationConfig { brief: bool, } -fn generate_doc(name: &str, engine_state: &EngineState) -> (Vec, Vec) { +fn generate_doc(name: &str, engine_state: &EngineState, head: Span) -> (Vec, Vec) { let mut cols = vec![]; let mut vals = vec![]; @@ -27,20 +27,20 @@ fn generate_doc(name: &str, engine_state: &EngineState) -> (Vec, Vec (Vec, Vec Value { +pub fn generate_docs(engine_state: &EngineState, head: Span) -> Value { let signatures = engine_state.get_signatures(true); // cmap will map parent commands to it's subcommands e.g. to -> [to csv, to yaml, to bson] @@ -90,15 +90,15 @@ pub fn generate_docs(engine_state: &EngineState) -> Value { if !cmap.contains_key(&sig.name) { continue; } - let mut row_entries = generate_doc(&sig.name, engine_state); + let mut row_entries = generate_doc(&sig.name, engine_state, head); // Iterate over all the subcommands of the parent command let mut sub_table = Vec::new(); for sub_name in cmap.get(&sig.name).unwrap_or(&Vec::new()) { - let (cols, vals) = generate_doc(sub_name, engine_state); + let (cols, vals) = generate_doc(sub_name, engine_state, head); sub_table.push(Value::Record { cols, vals, - span: Span::unknown(), + span: head, }); } @@ -106,18 +106,18 @@ pub fn generate_docs(engine_state: &EngineState) -> Value { row_entries.0.push("subcommands".into()); row_entries.1.push(Value::List { vals: sub_table, - span: Span::unknown(), + span: head, }); } table.push(Value::Record { cols: row_entries.0, vals: row_entries.1, - span: Span::unknown(), + span: head, }); } Value::List { vals: table, - span: Span::unknown(), + span: head, } } diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 9df53e46a5..9a5a972b9d 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -67,7 +67,7 @@ fn eval_call( let span = if let Some(rest_item) = rest_items.first() { rest_item.span()? } else { - Span::unknown() + call.head }; stack.add_var( @@ -152,7 +152,7 @@ fn eval_external( call.named.push(( Spanned { item: "last_expression".into(), - span: Span::unknown(), + span: *name_span, }, None, )) @@ -191,25 +191,19 @@ pub fn eval_expression( let from = if let Some(f) = from { eval_expression(engine_state, stack, f)? } else { - Value::Nothing { - span: Span::unknown(), - } + Value::Nothing { span: expr.span } }; let next = if let Some(s) = next { eval_expression(engine_state, stack, s)? } else { - Value::Nothing { - span: Span::unknown(), - } + Value::Nothing { span: expr.span } }; let to = if let Some(t) = to { eval_expression(engine_state, stack, t)? } else { - Value::Nothing { - span: Span::unknown(), - } + Value::Nothing { span: expr.span } }; Ok(Value::Range { @@ -228,9 +222,7 @@ pub fn eval_expression( value.follow_cell_path(&cell_path.tail) } - Expr::ImportPattern(_) => Ok(Value::Nothing { - span: Span::unknown(), - }), + Expr::ImportPattern(_) => Ok(Value::Nothing { span: expr.span }), Expr::Call(call) => { // FIXME: protect this collect with ctrl-c Ok( diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 5868c60743..9842f3ac97 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -625,10 +625,11 @@ pub fn parse_call( working_set: &mut StateWorkingSet, spans: &[Span], expand_aliases: bool, + head: Span, ) -> (Expression, Option) { if spans.is_empty() { return ( - garbage(Span::unknown()), + garbage(head), Some(ParseError::UnknownState( "Encountered command with zero spans".into(), span(spans), @@ -715,7 +716,7 @@ pub fn parse_call( if test_equal == [b'='] { return ( - garbage(Span::unknown()), + garbage(span(spans)), Some(ParseError::UnknownState( "Incomplete statement".into(), span(spans), @@ -987,7 +988,7 @@ pub fn parse_range( } } } else { - (None, Span::unknown()) + (None, span) }; let range_op = RangeOperator { @@ -1384,7 +1385,7 @@ pub fn parse_full_cell_path( ( Expression { expr: Expr::Var(var_id), - span: Span::unknown(), + span, ty: Type::Unknown, custom_completion: None, }, @@ -1806,7 +1807,7 @@ pub fn parse_import_pattern( ImportPattern { head: ImportPatternHead { name: vec![], - span: Span::unknown(), + span: span(spans), }, members: vec![], hidden: HashSet::new(), @@ -3127,7 +3128,7 @@ pub fn parse_expression( let (output, err) = if is_math_expression_byte(bytes[0]) { parse_math_expression(working_set, &spans[pos..], None) } else { - parse_call(working_set, &spans[pos..], expand_aliases) + parse_call(working_set, &spans[pos..], expand_aliases, spans[0]) }; let with_env = working_set.find_decl(b"with-env"); @@ -3592,7 +3593,7 @@ fn wrap_expr_with_collect(working_set: &mut StateWorkingSet, expr: &Expression) Expression { expr: Expr::Call(Box::new(Call { - head: Span::unknown(), + head: span, named: vec![], positional: output, decl_id, diff --git a/crates/nu-plugin/src/serializers/capnp/call.rs b/crates/nu-plugin/src/serializers/capnp/call.rs index abe3c5fa57..264c92c9b2 100644 --- a/crates/nu-plugin/src/serializers/capnp/call.rs +++ b/crates/nu-plugin/src/serializers/capnp/call.rs @@ -72,7 +72,7 @@ pub(crate) fn deserialize_call( } fn deserialize_positionals( - _span: Span, + span: Span, reader: evaluated_call::Reader, ) -> Result, ShellError> { let positional_reader = reader @@ -81,7 +81,7 @@ fn deserialize_positionals( positional_reader .iter() - .map(value::deserialize_value) + .map(move |x| value::deserialize_value(x, span)) .collect() } @@ -110,7 +110,7 @@ fn deserialize_named(span: Span, reader: evaluated_call::Reader) -> Result Result Result { let reader = reader.map_err(|e| ShellError::PluginFailedToDecode(e.to_string()))?; - let val = value::deserialize_value(reader) + + let span = reader + .get_span() .map_err(|e| ShellError::PluginFailedToDecode(e.to_string()))?; + let val = value::deserialize_value( + reader, + Span { + start: span.get_start() as usize, + end: span.get_end() as usize, + }, + ) + .map_err(|e| ShellError::PluginFailedToDecode(e.to_string()))?; + Ok(PluginResponse::Value(Box::new(val))) } } diff --git a/crates/nu-plugin/src/serializers/capnp/value.rs b/crates/nu-plugin/src/serializers/capnp/value.rs index 9cfa5eeb5e..1cef8a8766 100644 --- a/crates/nu-plugin/src/serializers/capnp/value.rs +++ b/crates/nu-plugin/src/serializers/capnp/value.rs @@ -51,7 +51,9 @@ pub(crate) fn serialize_value(value: &Value, mut builder: value::Builder) { _ => { // If there is the need to pass other type of value to the plugin // we have to define the encoding for that object in this match - Span::unknown() + + // FIXME: put this in a proper span + Span { start: 0, end: 0 } } }; @@ -60,7 +62,7 @@ pub(crate) fn serialize_value(value: &Value, mut builder: value::Builder) { span.set_end(value_span.end as u64); } -pub(crate) fn deserialize_value(reader: value::Reader) -> Result { +pub(crate) fn deserialize_value(reader: value::Reader, head: Span) -> Result { let span_reader = reader .get_span() .map_err(|e| ShellError::PluginFailedToDecode(e.to_string()))?; @@ -98,7 +100,7 @@ pub(crate) fn deserialize_value(reader: value::Reader) -> Result, ShellError>>()?; Ok(Value::Record { cols, vals, span }) @@ -108,7 +110,7 @@ pub(crate) fn deserialize_value(reader: value::Reader) -> Result, ShellError>>()?; Ok(Value::List { @@ -116,9 +118,7 @@ pub(crate) fn deserialize_value(reader: value::Reader) -> Result Ok(Value::Nothing { - span: Span::unknown(), - }), + Err(capnp::NotInSchema(_)) => Ok(Value::Nothing { span: head }), } } @@ -147,7 +147,17 @@ mod tests { .get_root::() .map_err(|e| ShellError::PluginFailedToDecode(e.to_string()))?; - deserialize_value(reader.reborrow()) + let span = reader + .get_span() + .map_err(|e| ShellError::PluginFailedToDecode(e.to_string()))?; + + deserialize_value( + reader.reborrow(), + Span { + start: span.get_start() as usize, + end: span.get_end() as usize, + }, + ) } #[test] diff --git a/crates/nu-protocol/src/ast/call.rs b/crates/nu-protocol/src/ast/call.rs index f2f9a9c431..4586415577 100644 --- a/crates/nu-protocol/src/ast/call.rs +++ b/crates/nu-protocol/src/ast/call.rs @@ -20,7 +20,7 @@ impl Call { pub fn new() -> Call { Self { decl_id: 0, - head: Span::unknown(), + head: Span { start: 0, end: 0 }, positional: vec![], named: vec![], } diff --git a/crates/nu-protocol/src/ast/import_pattern.rs b/crates/nu-protocol/src/ast/import_pattern.rs index b370fe27d7..a35fb671b9 100644 --- a/crates/nu-protocol/src/ast/import_pattern.rs +++ b/crates/nu-protocol/src/ast/import_pattern.rs @@ -28,7 +28,7 @@ impl ImportPattern { ImportPattern { head: ImportPatternHead { name: vec![], - span: Span::unknown(), + span: Span { start: 0, end: 0 }, }, members: vec![], hidden: HashSet::new(), diff --git a/crates/nu-protocol/src/pipeline_data.rs b/crates/nu-protocol/src/pipeline_data.rs index 51d917970b..f8769c56e7 100644 --- a/crates/nu-protocol/src/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline_data.rs @@ -54,6 +54,7 @@ impl PipelineData { pub fn into_value(self, span: Span) -> Value { match self { + PipelineData::Value(Value::Nothing { .. }, ..) => Value::nothing(span), PipelineData::Value(v, ..) => v, PipelineData::Stream(s, ..) => Value::List { vals: s.collect(), @@ -79,12 +80,16 @@ impl PipelineData { } } - pub fn follow_cell_path(self, cell_path: &[PathMember]) -> Result { + pub fn follow_cell_path( + self, + cell_path: &[PathMember], + head: Span, + ) -> Result { match self { // FIXME: there are probably better ways of doing this PipelineData::Stream(stream, ..) => Value::List { vals: stream.collect(), - span: Span::unknown(), + span: head, } .follow_cell_path(cell_path), PipelineData::Value(v, ..) => v.follow_cell_path(cell_path), @@ -95,12 +100,13 @@ impl PipelineData { &mut self, cell_path: &[PathMember], callback: Box Value>, + head: Span, ) -> Result<(), ShellError> { match self { // FIXME: there are probably better ways of doing this PipelineData::Stream(stream, ..) => Value::List { vals: stream.collect(), - span: Span::unknown(), + span: head, } .update_cell_path(cell_path, callback), PipelineData::Value(v, ..) => v.update_cell_path(cell_path, callback), diff --git a/crates/nu-protocol/src/span.rs b/crates/nu-protocol/src/span.rs index cea29479db..4196e751b3 100644 --- a/crates/nu-protocol/src/span.rs +++ b/crates/nu-protocol/src/span.rs @@ -31,7 +31,8 @@ impl Span { Span { start, end } } - pub fn unknown() -> Span { + /// Note: Only use this for test data, *not* live data, as it will point into unknown source when used in errors + pub fn test_data() -> Span { Span { start: 0, end: 0 } } @@ -51,7 +52,7 @@ pub fn span(spans: &[Span]) -> Span { let length = spans.len(); if length == 0 { - Span::unknown() + panic!("Internal error: tried to create a 0-length span") } else if length == 1 { spans[0] } else { diff --git a/crates/nu-protocol/src/value/from.rs b/crates/nu-protocol/src/value/from.rs index 5185bb9977..ea3ff0ef7f 100644 --- a/crates/nu-protocol/src/value/from.rs +++ b/crates/nu-protocol/src/value/from.rs @@ -1,112 +1,4 @@ -use crate::{ShellError, Span, Value}; - -impl From for Value { - fn from(val: String) -> Self { - Value::String { - val, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: bool) -> Self { - Value::Bool { - val, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: u8) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: u16) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: u32) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: u64) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: i8) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: i16) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: i32) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: i64) -> Self { - Value::Int { - val: val as i64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: f32) -> Self { - Value::Float { - val: val as f64, - span: Span::unknown(), - } - } -} - -impl From for Value { - fn from(val: f64) -> Self { - Value::Float { - val: val as f64, - span: Span::unknown(), - } - } -} +use crate::{ShellError, Value}; impl Value { pub fn as_f64(&self) -> Result { diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index daa1910040..b062a013e8 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -673,27 +673,35 @@ impl Value { Value::Bool { val, span } } - // Only use these for test data. Span::unknown() should not be used in user data + // Only use these for test data. Should not be used in user data pub fn test_string(s: impl Into) -> Value { Value::String { val: s.into(), - span: Span::unknown(), + span: Span::test_data(), } } - // Only use these for test data. Span::unknown() should not be used in user data + // Only use these for test data. Should not be used in user data pub fn test_int(val: i64) -> Value { Value::Int { val, - span: Span::unknown(), + span: Span::test_data(), } } - // Only use these for test data. Span::unknown() should not be used in user data + // Only use these for test data. Should not be used in user data pub fn test_float(val: f64) -> Value { Value::Float { val, - span: Span::unknown(), + span: Span::test_data(), + } + } + + // Only use these for test data. Should not be used in user data + pub fn test_bool(val: bool) -> Value { + Value::Bool { + val, + span: Span::test_data(), } } } @@ -701,7 +709,7 @@ impl Value { impl Default for Value { fn default() -> Self { Value::Nothing { - span: Span::unknown(), + span: Span { start: 0, end: 0 }, } } } diff --git a/crates/nu-protocol/src/value/range.rs b/crates/nu-protocol/src/value/range.rs index 63949d98da..bff06d1387 100644 --- a/crates/nu-protocol/src/value/range.rs +++ b/crates/nu-protocol/src/value/range.rs @@ -28,7 +28,7 @@ impl Range { let from = if let Value::Nothing { .. } = from { Value::Int { val: 0i64, - span: Span::unknown(), + span: expr_span, } } else { from @@ -38,12 +38,12 @@ impl Range { if let Ok(Value::Bool { val: true, .. }) = next.lt(expr_span, &from) { Value::Int { val: -100i64, - span: Span::unknown(), + span: expr_span, } } else { Value::Int { val: 100i64, - span: Span::unknown(), + span: expr_span, } } } else { @@ -58,12 +58,12 @@ impl Range { if moves_up { Value::Int { val: 1i64, - span: Span::unknown(), + span: expr_span, } } else { Value::Int { val: -1i64, - span: Span::unknown(), + span: expr_span, } } } else { @@ -72,7 +72,7 @@ impl Range { let zero = Value::Int { val: 0i64, - span: Span::unknown(), + span: expr_span, }; // Increment must be non-zero, otherwise we iterate forever diff --git a/crates/nu_plugin_gstat/src/gstat.rs b/crates/nu_plugin_gstat/src/gstat.rs index 0c38db1ac2..53c46b51fe 100644 --- a/crates/nu_plugin_gstat/src/gstat.rs +++ b/crates/nu_plugin_gstat/src/gstat.rs @@ -55,7 +55,7 @@ impl GStat { } None => Spanned { item: ".".to_string(), - span: Span::unknown(), + span: *span, }, }; diff --git a/crates/nu_plugin_gstat/src/nu/mod.rs b/crates/nu_plugin_gstat/src/nu/mod.rs index 71623f587e..fd626d7109 100644 --- a/crates/nu_plugin_gstat/src/nu/mod.rs +++ b/crates/nu_plugin_gstat/src/nu/mod.rs @@ -1,6 +1,6 @@ use crate::GStat; use nu_plugin::{EvaluatedCall, LabeledError, Plugin}; -use nu_protocol::{Category, Signature, Span, Spanned, SyntaxShape, Value}; +use nu_protocol::{Category, Signature, Spanned, SyntaxShape, Value}; impl Plugin for GStat { fn signature(&self) -> Vec { @@ -17,9 +17,7 @@ impl Plugin for GStat { input: &Value, ) -> Result { if name != "gstat" { - return Ok(Value::Nothing { - span: Span::unknown(), - }); + return Ok(Value::Nothing { span: call.head }); } let repo_path: Option> = call.opt(0)?; diff --git a/crates/nu_plugin_inc/src/inc.rs b/crates/nu_plugin_inc/src/inc.rs index 9bd20b46c7..a221fa4fed 100644 --- a/crates/nu_plugin_inc/src/inc.rs +++ b/crates/nu_plugin_inc/src/inc.rs @@ -25,7 +25,7 @@ impl Inc { Default::default() } - fn apply(&self, input: &str) -> Value { + fn apply(&self, input: &str, head: Span) -> Value { match &self.action { Some(Action::SemVerAction(act_on)) => { let mut ver = match semver::Version::parse(input) { @@ -33,7 +33,7 @@ impl Inc { Err(_) => { return Value::String { val: input.to_string(), - span: Span::unknown(), + span: head, } } }; @@ -46,17 +46,17 @@ impl Inc { Value::String { val: ver.to_string(), - span: Span::unknown(), + span: head, } } Some(Action::Default) | None => match input.parse::() { Ok(v) => Value::String { val: (v + 1).to_string(), - span: Span::unknown(), + span: head, }, Err(_) => Value::String { val: input.to_string(), - span: Span::unknown(), + span: head, }, }, } @@ -88,7 +88,7 @@ impl Inc { val: val + 1, span: *span, }), - Value::String { val, .. } => Ok(self.apply(val)), + Value::String { val, .. } => Ok(self.apply(val, head)), x => { let msg = x.as_string().map_err(|e| LabeledError { label: "Unable to extract string".into(), @@ -122,33 +122,33 @@ mod tests { fn major() { let expected = Value::String { val: "1.0.0".to_string(), - span: Span::unknown(), + span: Span::test_data(), }; let mut inc = Inc::new(); inc.for_semver(SemVerAction::Major); - assert_eq!(inc.apply("0.1.3"), expected) + assert_eq!(inc.apply("0.1.3", Span::test_data()), expected) } #[test] fn minor() { let expected = Value::String { val: "0.2.0".to_string(), - span: Span::unknown(), + span: Span::test_data(), }; let mut inc = Inc::new(); inc.for_semver(SemVerAction::Minor); - assert_eq!(inc.apply("0.1.3"), expected) + assert_eq!(inc.apply("0.1.3", Span::test_data()), expected) } #[test] fn patch() { let expected = Value::String { val: "0.1.4".to_string(), - span: Span::unknown(), + span: Span::test_data(), }; let mut inc = Inc::new(); inc.for_semver(SemVerAction::Patch); - assert_eq!(inc.apply("0.1.3"), expected) + assert_eq!(inc.apply("0.1.3", Span::test_data()), expected) } } } diff --git a/crates/nu_plugin_inc/src/nu/mod.rs b/crates/nu_plugin_inc/src/nu/mod.rs index 676cf0bb10..21ea19befa 100644 --- a/crates/nu_plugin_inc/src/nu/mod.rs +++ b/crates/nu_plugin_inc/src/nu/mod.rs @@ -1,7 +1,7 @@ use crate::inc::SemVerAction; use crate::Inc; use nu_plugin::{EvaluatedCall, LabeledError, Plugin}; -use nu_protocol::{Signature, Span, Value}; +use nu_protocol::{Signature, Value}; impl Plugin for Inc { fn signature(&self) -> Vec { @@ -31,9 +31,7 @@ impl Plugin for Inc { input: &Value, ) -> Result { if name != "inc" { - return Ok(Value::Nothing { - span: Span::unknown(), - }); + return Ok(Value::Nothing { span: call.head }); } if call.has_flag("major") { diff --git a/src/main.rs b/src/main.rs index f64bad00ad..881564a70f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,7 +135,7 @@ fn main() -> Result<()> { Value::Record { cols: vec![], vals: vec![], - span: Span::unknown(), + span: Span { start: 0, end: 0 }, }, ); @@ -160,7 +160,7 @@ fn main() -> Result<()> { &engine_state, &mut stack, &block, - PipelineData::new(Span::unknown()), + PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored ) { Ok(pipeline_data) => { for item in pipeline_data { @@ -203,7 +203,7 @@ fn main() -> Result<()> { &engine_state, &mut stack, &block, - PipelineData::new(Span::unknown()), + PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored ) { Ok(pipeline_data) => { for item in pipeline_data { @@ -254,7 +254,7 @@ fn main() -> Result<()> { Value::Record { cols: vec![], vals: vec![], - span: Span::unknown(), + span: Span::new(0, 0), }, ); @@ -552,7 +552,7 @@ fn update_prompt<'prompt>( engine_state, &mut stack, block, - PipelineData::new(Span::unknown()), + PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored ) { Ok(pipeline_data) => { let config = stack.get_config().unwrap_or_default(); @@ -600,7 +600,7 @@ fn eval_source( engine_state, stack, &block, - PipelineData::new(Span::unknown()), + PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored ) { Ok(pipeline_data) => { if let Err(err) = print_pipeline_data(pipeline_data, engine_state, stack) {