diff --git a/crates/nu-cli/src/reedline_config.rs b/crates/nu-cli/src/reedline_config.rs index 43c9f21671..b85c586ce4 100644 --- a/crates/nu-cli/src/reedline_config.rs +++ b/crates/nu-cli/src/reedline_config.rs @@ -7,8 +7,7 @@ use nu_parser::parse; use nu_protocol::{ create_menus, engine::{EngineState, Stack, StateWorkingSet}, - extract_value, Config, IntoPipelineData, ParsedKeybinding, ParsedMenu, PipelineData, - ShellError, Span, Value, + extract_value, Config, ParsedKeybinding, ParsedMenu, PipelineData, ShellError, Span, Value, }; use reedline::{ default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings, @@ -110,7 +109,7 @@ pub(crate) fn add_menus( }; let mut temp_stack = Stack::new(); - let input = Value::nothing(Span::test_data()).into_pipeline_data(); + let input = PipelineData::Empty; let res = eval_block(&engine_state, &mut temp_stack, &block, input, false, false)?; if let PipelineData::Value(value, None) = res { diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index aef3a56195..e8441b241d 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -639,7 +639,7 @@ pub fn eval_string_with_input( false, true, ) - .map(|x| x.into_value(Span::test_data())) + .map(|x| x.into_value(Span::unknown())) } pub fn get_command_finished_marker(stack: &Stack, engine_state: &EngineState) -> String { diff --git a/crates/nu-command/src/bits/and.rs b/crates/nu-command/src/bits/and.rs index 47d77e441a..7ba4ffebdd 100644 --- a/crates/nu-command/src/bits/and.rs +++ b/crates/nu-command/src/bits/and.rs @@ -58,7 +58,7 @@ impl Command for SubCommand { Example { description: "Apply bits and to two numbers", example: "2 | bits and 2", - result: Some(Value::int(2, Span::test_data())), + result: Some(Value::test_int(2)), }, Example { description: "Apply logical and to a list of numbers", diff --git a/crates/nu-command/src/bits/or.rs b/crates/nu-command/src/bits/or.rs index 7c40919a6b..5009999e4e 100644 --- a/crates/nu-command/src/bits/or.rs +++ b/crates/nu-command/src/bits/or.rs @@ -58,7 +58,7 @@ impl Command for SubCommand { Example { description: "Apply bits or to two numbers", example: "2 | bits or 6", - result: Some(Value::int(6, Span::test_data())), + result: Some(Value::test_int(6)), }, Example { description: "Apply logical or to a list of numbers", diff --git a/crates/nu-command/src/bits/rotate_left.rs b/crates/nu-command/src/bits/rotate_left.rs index d44c60cd20..f31e23fcab 100644 --- a/crates/nu-command/src/bits/rotate_left.rs +++ b/crates/nu-command/src/bits/rotate_left.rs @@ -81,7 +81,7 @@ impl Command for SubCommand { Example { description: "Rotate left a number with 2 bits", example: "17 | bits rol 2", - result: Some(Value::int(68, Span::test_data())), + result: Some(Value::test_int(68)), }, Example { description: "Rotate left a list of numbers with 2 bits", diff --git a/crates/nu-command/src/bits/rotate_right.rs b/crates/nu-command/src/bits/rotate_right.rs index b026da148e..05d8f1a677 100644 --- a/crates/nu-command/src/bits/rotate_right.rs +++ b/crates/nu-command/src/bits/rotate_right.rs @@ -81,7 +81,7 @@ impl Command for SubCommand { Example { description: "Rotate right a number with 60 bits", example: "17 | bits ror 60", - result: Some(Value::int(272, Span::test_data())), + result: Some(Value::test_int(272)), }, Example { description: "Rotate right a list of numbers of one byte", diff --git a/crates/nu-command/src/bits/shift_left.rs b/crates/nu-command/src/bits/shift_left.rs index cb087296c3..e96fa6604e 100644 --- a/crates/nu-command/src/bits/shift_left.rs +++ b/crates/nu-command/src/bits/shift_left.rs @@ -81,17 +81,17 @@ impl Command for SubCommand { Example { description: "Shift left a number by 7 bits", example: "2 | bits shl 7", - result: Some(Value::int(256, Span::test_data())), + result: Some(Value::test_int(256)), }, Example { description: "Shift left a number with 1 byte by 7 bits", example: "2 | bits shl 7 -n 1", - result: Some(Value::int(0, Span::test_data())), + result: Some(Value::test_int(0)), }, Example { description: "Shift left a signed number by 1 bit", example: "0x7F | bits shl 1 -s", - result: Some(Value::int(254, Span::test_data())), + result: Some(Value::test_int(254)), }, Example { description: "Shift left a list of numbers", diff --git a/crates/nu-command/src/bits/shift_right.rs b/crates/nu-command/src/bits/shift_right.rs index 8a721894bb..ec68a9a5a8 100644 --- a/crates/nu-command/src/bits/shift_right.rs +++ b/crates/nu-command/src/bits/shift_right.rs @@ -81,7 +81,7 @@ impl Command for SubCommand { Example { description: "Shift right a number with 2 bits", example: "8 | bits shr 2", - result: Some(Value::int(2, Span::test_data())), + result: Some(Value::test_int(2)), }, Example { description: "Shift right a list of numbers", diff --git a/crates/nu-command/src/bits/xor.rs b/crates/nu-command/src/bits/xor.rs index 3ce0d5a3cf..a3ca34b417 100644 --- a/crates/nu-command/src/bits/xor.rs +++ b/crates/nu-command/src/bits/xor.rs @@ -57,7 +57,7 @@ impl Command for SubCommand { Example { description: "Apply bits xor to two numbers", example: "2 | bits xor 2", - result: Some(Value::int(0, Span::test_data())), + result: Some(Value::test_int(0)), }, Example { description: "Apply logical xor to a list of numbers", diff --git a/crates/nu-command/src/bytes/ends_with.rs b/crates/nu-command/src/bytes/ends_with.rs index 725c1ceb05..44aeb12e66 100644 --- a/crates/nu-command/src/bytes/ends_with.rs +++ b/crates/nu-command/src/bytes/ends_with.rs @@ -68,17 +68,17 @@ impl Command for BytesEndsWith { Example { description: "Checks if binary ends with `0x[AA]`", example: "0x[1F FF AA AA] | bytes ends-with 0x[AA]", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Checks if binary ends with `0x[FF AA AA]`", example: "0x[1F FF AA AA] | bytes ends-with 0x[FF AA AA]", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Checks if binary ends with `0x[11]`", example: "0x[1F FF AA AA] | bytes ends-with 0x[11]", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, ] } diff --git a/crates/nu-command/src/bytes/starts_with.rs b/crates/nu-command/src/bytes/starts_with.rs index 8360947545..16504100d3 100644 --- a/crates/nu-command/src/bytes/starts_with.rs +++ b/crates/nu-command/src/bytes/starts_with.rs @@ -74,17 +74,17 @@ impl Command for BytesStartsWith { Example { description: "Checks if binary starts with `0x[1F FF AA]`", example: "0x[1F FF AA AA] | bytes starts-with 0x[1F FF AA]", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Checks if binary starts with `0x[1F]`", example: "0x[1F FF AA AA] | bytes starts-with 0x[1F]", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Checks if binary starts with `0x[1F]`", example: "0x[1F FF AA AA] | bytes starts-with 0x[11]", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, ] } diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index 85159e8550..a4b549790f 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -113,7 +113,7 @@ impl Command for SubCommand { Example { description: "Convert file size to integer", example: "4KB | into int", - result: Some(Value::int(4000, Span::test_data())), + result: Some(Value::test_int(4000)), }, Example { description: "Convert bool to integer", diff --git a/crates/nu-command/src/core_commands/hide.rs b/crates/nu-command/src/core_commands/hide.rs index 3918098ef5..516a565e99 100644 --- a/crates/nu-command/src/core_commands/hide.rs +++ b/crates/nu-command/src/core_commands/hide.rs @@ -1,7 +1,7 @@ use nu_protocol::ast::{Call, Expr, Expression}; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, + Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -85,7 +85,7 @@ This command is a parser keyword. For details, check: Example { description: "Hide an environment variable", example: r#"let-env HZ_ENV_ABC = 1; hide HZ_ENV_ABC; 'HZ_ENV_ABC' in (env).name"#, - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, ] } diff --git a/crates/nu-command/src/core_commands/hide_env.rs b/crates/nu-command/src/core_commands/hide_env.rs index 2be0890d69..369877d4f6 100644 --- a/crates/nu-command/src/core_commands/hide_env.rs +++ b/crates/nu-command/src/core_commands/hide_env.rs @@ -2,8 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - did_you_mean, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, - SyntaxShape, Type, Value, + did_you_mean, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, + Type, Value, }; #[derive(Clone)] @@ -70,7 +70,7 @@ impl Command for HideEnv { vec![Example { description: "Hide an environment variable", example: r#"let-env HZ_ENV_ABC = 1; hide-env HZ_ENV_ABC; 'HZ_ENV_ABC' in (env).name"#, - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }] } } diff --git a/crates/nu-command/src/core_commands/loop_.rs b/crates/nu-command/src/core_commands/loop_.rs index fb30336a30..7c3878f7d1 100644 --- a/crates/nu-command/src/core_commands/loop_.rs +++ b/crates/nu-command/src/core_commands/loop_.rs @@ -2,7 +2,7 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Block, Command, EngineState, Stack}; use nu_protocol::{ - Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, + Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -81,7 +81,7 @@ impl Command for Loop { vec![Example { description: "Loop while a condition is true", example: "mut x = 0; loop { if $x > 10 { break }; $x = $x + 1 }; $x", - result: Some(Value::int(11, Span::test_data())), + result: Some(Value::test_int(11)), }] } } diff --git a/crates/nu-command/src/example_test.rs b/crates/nu-command/src/example_test.rs index 7e2e5612d8..65584acac3 100644 --- a/crates/nu-command/src/example_test.rs +++ b/crates/nu-command/src/example_test.rs @@ -209,10 +209,7 @@ mod test_examples { let mut stack = Stack::new(); // Set up PWD - stack.add_env_var( - "PWD".to_string(), - Value::string(cwd.to_string_lossy(), Span::test_data()), - ); + stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy())); engine_state .merge_env(&mut stack, cwd) @@ -294,10 +291,7 @@ mod test_examples { let mut stack = Stack::new(); - stack.add_env_var( - "PWD".to_string(), - Value::string(cwd.to_string_lossy(), Span::test_data()), - ); + stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy())); match nu_engine::eval_block(engine_state, &mut stack, &block, input, true, true) { Err(err) => panic!("test eval error in `{}`: {:?}", "TODO", err), diff --git a/crates/nu-command/src/filters/each.rs b/crates/nu-command/src/filters/each.rs index 23d578f90a..6490424276 100644 --- a/crates/nu-command/src/filters/each.rs +++ b/crates/nu-command/src/filters/each.rs @@ -54,11 +54,7 @@ with 'transpose' first."# } fn examples(&self) -> Vec { - let stream_test_1 = vec![ - Value::int(2, Span::test_data()), - Value::int(4, Span::test_data()), - Value::int(6, Span::test_data()), - ]; + let stream_test_1 = vec![Value::test_int(2), Value::test_int(4), Value::test_int(6)]; let stream_test_2 = vec![ Value::Nothing { diff --git a/crates/nu-command/src/filters/each_while.rs b/crates/nu-command/src/filters/each_while.rs index b1f10f950f..bc04b3de45 100644 --- a/crates/nu-command/src/filters/each_while.rs +++ b/crates/nu-command/src/filters/each_while.rs @@ -42,10 +42,7 @@ impl Command for EachWhile { } fn examples(&self) -> Vec { - let stream_test_1 = vec![ - Value::int(2, Span::test_data()), - Value::int(4, Span::test_data()), - ]; + let stream_test_1 = vec![Value::test_int(2), Value::test_int(4)]; let stream_test_2 = vec![ Value::test_string("Output: 1"), Value::test_string("Output: 2"), diff --git a/crates/nu-command/src/filters/empty.rs b/crates/nu-command/src/filters/empty.rs index 00f0af0bc4..404ae3b3eb 100644 --- a/crates/nu-command/src/filters/empty.rs +++ b/crates/nu-command/src/filters/empty.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::{Call, CellPath}; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Type, Value, + Category, Example, IntoPipelineData, PipelineData, Signature, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -43,18 +43,18 @@ impl Command for Empty { Example { description: "Check if a string is empty", example: "'' | is-empty", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Check if a list is empty", example: "[] | is-empty", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { // TODO: revisit empty cell path semantics for a record. description: "Check if more than one column are empty", example: "[[meal size]; [arepa small] [taco '']] | is-empty meal size", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, ] } diff --git a/crates/nu-command/src/filters/group.rs b/crates/nu-command/src/filters/group.rs index 30d06aa8a4..6636b19458 100644 --- a/crates/nu-command/src/filters/group.rs +++ b/crates/nu-command/src/filters/group.rs @@ -35,17 +35,11 @@ impl Command for Group { fn examples(&self) -> Vec { let stream_test_1 = vec![ Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(2)], span: Span::test_data(), }, Value::List { - vals: vec![ - Value::int(3, Span::test_data()), - Value::int(4, Span::test_data()), - ], + vals: vec![Value::test_int(3), Value::test_int(4)], span: Span::test_data(), }, ]; diff --git a/crates/nu-command/src/filters/reduce.rs b/crates/nu-command/src/filters/reduce.rs index ef48957ff8..4d81360126 100644 --- a/crates/nu-command/src/filters/reduce.rs +++ b/crates/nu-command/src/filters/reduce.rs @@ -3,7 +3,7 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Closure, Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, + Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -52,17 +52,17 @@ impl Command for Reduce { Example { example: "[ 1 2 3 4 ] | reduce {|it, acc| $it + $acc }", description: "Sum values of a list (same as 'math sum')", - result: Some(Value::int(10, Span::test_data())), + result: Some(Value::test_int(10)), }, Example { example: "[ 8 7 6 ] | reduce {|it, acc, ind| $acc + $it + $ind }", description: "Sum values of a list, plus their indexes", - result: Some(Value::int(22, Span::test_data())), + result: Some(Value::test_int(22)), }, Example { example: "[ 1 2 3 4 ] | reduce -f 10 {|it, acc| $acc + $it }", description: "Sum values with a starting value (fold)", - result: Some(Value::int(20, Span::test_data())), + result: Some(Value::test_int(20)), }, Example { example: r#"[ i o t ] | reduce -f "Arthur, King of the Britons" {|it, acc| $acc | str replace -a $it "X" }"#, diff --git a/crates/nu-command/src/filters/reject.rs b/crates/nu-command/src/filters/reject.rs index 5dab6e341d..6557f9843c 100644 --- a/crates/nu-command/src/filters/reject.rs +++ b/crates/nu-command/src/filters/reject.rs @@ -68,7 +68,7 @@ impl Command for Reject { example: "{a: 1, b: 2} | reject a", result: Some(Value::Record { cols: vec!["b".into()], - vals: vec![Value::int(2, Span::test_data())], + vals: vec![Value::test_int(2)], span: Span::test_data(), }), }, @@ -79,7 +79,7 @@ impl Command for Reject { cols: vec!["a".into()], vals: vec![Value::Record { cols: vec!["c".into()], - vals: vec![Value::int(5, Span::test_data())], + vals: vec![Value::test_int(5)], span: Span::test_data(), }], span: Span::test_data(), diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index 3ed6951d40..cf77726761 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -87,7 +87,7 @@ impl Command for Select { fn select( engine_state: &EngineState, - span: Span, + call_span: Span, columns: Vec, input: PipelineData, ignore_errors: bool, @@ -102,7 +102,7 @@ fn select( Some(PathMember::Int { val, span }) => { if members.len() > 1 { if ignore_errors { - return Ok(Value::nothing(Span::test_data()).into_pipeline_data()); + return Ok(Value::nothing(call_span).into_pipeline_data()); } return Err(ShellError::GenericError( "Select only allows row numbers for rows".into(), @@ -166,9 +166,7 @@ fn select( } Err(e) => { if ignore_errors { - return Ok( - Value::nothing(Span::test_data()).into_pipeline_data() - ); + return Ok(Value::nothing(call_span).into_pipeline_data()); } return Err(e); } @@ -202,15 +200,17 @@ fn select( } Err(e) => { if ignore_errors { - return Ok( - Value::nothing(Span::test_data()).into_pipeline_data() - ); + return Ok(Value::nothing(call_span).into_pipeline_data()); } return Err(e); } } } - values.push(Value::Record { cols, vals, span }); + values.push(Value::Record { + cols, + vals, + span: call_span, + }); } else { values.push(x); } @@ -234,7 +234,7 @@ fn select( } Err(e) => { if ignore_errors { - return Ok(Value::nothing(Span::test_data()).into_pipeline_data()); + return Ok(Value::nothing(call_span).into_pipeline_data()); } return Err(e); @@ -242,9 +242,13 @@ fn select( } } - Ok(Value::Record { cols, vals, span } - .into_pipeline_data() - .set_metadata(metadata)) + Ok(Value::Record { + cols, + vals, + span: call_span, + } + .into_pipeline_data() + .set_metadata(metadata)) } else { Ok(v.into_pipeline_data().set_metadata(metadata)) } diff --git a/crates/nu-command/src/filters/window.rs b/crates/nu-command/src/filters/window.rs index f33d9ab838..c56e150122 100644 --- a/crates/nu-command/src/filters/window.rs +++ b/crates/nu-command/src/filters/window.rs @@ -42,66 +42,41 @@ impl Command for Window { fn examples(&self) -> Vec { let stream_test_1 = vec![ Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(2)], span: Span::test_data(), }, Value::List { - vals: vec![ - Value::int(2, Span::test_data()), - Value::int(3, Span::test_data()), - ], + vals: vec![Value::test_int(2), Value::test_int(3)], span: Span::test_data(), }, Value::List { - vals: vec![ - Value::int(3, Span::test_data()), - Value::int(4, Span::test_data()), - ], + vals: vec![Value::test_int(3), Value::test_int(4)], span: Span::test_data(), }, ]; let stream_test_2 = vec![ Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(2)], span: Span::test_data(), }, Value::List { - vals: vec![ - Value::int(4, Span::test_data()), - Value::int(5, Span::test_data()), - ], + vals: vec![Value::test_int(4), Value::test_int(5)], span: Span::test_data(), }, Value::List { - vals: vec![ - Value::int(7, Span::test_data()), - Value::int(8, Span::test_data()), - ], + vals: vec![Value::test_int(7), Value::test_int(8)], span: Span::test_data(), }, ]; let stream_test_3 = vec![ Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - Value::int(3, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)], span: Span::test_data(), }, Value::List { - vals: vec![ - Value::int(4, Span::test_data()), - Value::int(5, Span::test_data()), - ], + vals: vec![Value::test_int(4), Value::test_int(5)], span: Span::test_data(), }, ]; diff --git a/crates/nu-command/src/filters/zip.rs b/crates/nu-command/src/filters/zip.rs index 57e1190de9..7ffe268a1c 100644 --- a/crates/nu-command/src/filters/zip.rs +++ b/crates/nu-command/src/filters/zip.rs @@ -36,26 +36,17 @@ impl Command for Zip { fn examples(&self) -> Vec { let test_row_1 = Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(4, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(4)], span: Span::test_data(), }; let test_row_2 = Value::List { - vals: vec![ - Value::int(2, Span::test_data()), - Value::int(5, Span::test_data()), - ], + vals: vec![Value::test_int(2), Value::test_int(5)], span: Span::test_data(), }; let test_row_3 = Value::List { - vals: vec![ - Value::int(3, Span::test_data()), - Value::int(6, Span::test_data()), - ], + vals: vec![Value::test_int(3), Value::test_int(6)], 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 15756ed9bc..1a13c43d96 100644 --- a/crates/nu-command/src/formats/from/json.rs +++ b/crates/nu-command/src/formats/from/json.rs @@ -31,7 +31,7 @@ impl Command for FromJson { description: "Converts json formatted string to table", result: Some(Value::Record { cols: vec!["a".to_string()], - vals: vec![Value::int(1, Span::test_data())], + vals: vec![Value::test_int(1)], span: Span::test_data(), }), }, @@ -41,12 +41,9 @@ impl Command for FromJson { result: Some(Value::Record { cols: vec!["a".to_string(), "b".to_string()], vals: vec![ - Value::int(1, Span::test_data()), + Value::test_int(1), Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(2)], span: Span::test_data(), }, ], diff --git a/crates/nu-command/src/formats/from/nuon.rs b/crates/nu-command/src/formats/from/nuon.rs index 039a0a8a9b..aec990ab89 100644 --- a/crates/nu-command/src/formats/from/nuon.rs +++ b/crates/nu-command/src/formats/from/nuon.rs @@ -29,7 +29,7 @@ impl Command for FromNuon { description: "Converts nuon formatted string to table", result: Some(Value::Record { cols: vec!["a".to_string()], - vals: vec![Value::int(1, Span::test_data())], + vals: vec![Value::test_int(1)], span: Span::test_data(), }), }, @@ -39,12 +39,9 @@ impl Command for FromNuon { result: Some(Value::Record { cols: vec!["a".to_string(), "b".to_string()], vals: vec![ - Value::int(1, Span::test_data()), + Value::test_int(1), Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(2)], 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 5ce3cc7c69..98012ce3dd 100644 --- a/crates/nu-command/src/formats/from/toml.rs +++ b/crates/nu-command/src/formats/from/toml.rs @@ -29,7 +29,7 @@ impl Command for FromToml { description: "Converts toml formatted string to record", result: Some(Value::Record { cols: vec!["a".to_string()], - vals: vec![Value::int(1, Span::test_data())], + vals: vec![Value::test_int(1)], span: Span::test_data(), }), }, @@ -40,12 +40,9 @@ b = [1, 2]' | from toml", result: Some(Value::Record { cols: vec!["a".to_string(), "b".to_string()], vals: vec![ - Value::int(1, Span::test_data()), + Value::test_int(1), Value::List { - vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - ], + vals: vec![Value::test_int(1), Value::test_int(2)], span: Span::test_data(), }, ], diff --git a/crates/nu-command/src/formats/from/xml.rs b/crates/nu-command/src/formats/from/xml.rs index 43c0bc8d5e..cb5c3ea4b6 100644 --- a/crates/nu-command/src/formats/from/xml.rs +++ b/crates/nu-command/src/formats/from/xml.rs @@ -200,7 +200,7 @@ mod tests { use nu_protocol::{Spanned, Value}; fn string(input: impl Into) -> Value { - Value::string(input, Span::test_data()) + Value::test_string(input) } fn row(entries: IndexMap) -> Value { diff --git a/crates/nu-command/src/formats/from/yaml.rs b/crates/nu-command/src/formats/from/yaml.rs index 8601b58db8..9ef97f9dfa 100644 --- a/crates/nu-command/src/formats/from/yaml.rs +++ b/crates/nu-command/src/formats/from/yaml.rs @@ -203,7 +203,7 @@ pub fn get_examples() -> Vec { description: "Converts yaml formatted string to table", result: Some(Value::Record { cols: vec!["a".to_string()], - vals: vec![Value::int(1, Span::test_data())], + vals: vec![Value::test_int(1)], span: Span::test_data(), }), }, diff --git a/crates/nu-command/src/generators/seq_date.rs b/crates/nu-command/src/generators/seq_date.rs index fb241d72d4..971d043213 100644 --- a/crates/nu-command/src/generators/seq_date.rs +++ b/crates/nu-command/src/generators/seq_date.rs @@ -59,8 +59,6 @@ impl Command for SeqDate { } fn examples(&self) -> Vec { - let span = Span::test_data(); - vec![ Example { description: "print the next 10 days in YYYY-MM-DD format with newline separator", @@ -82,18 +80,18 @@ impl Command for SeqDate { example: "seq date -b '2020-01-01' -e '2020-01-10'", result: Some(Value::List { vals: vec![ - Value::String { val: "2020-01-01".into(), span, }, - Value::String { val: "2020-01-02".into(), span, }, - Value::String { val: "2020-01-03".into(), span, }, - Value::String { val: "2020-01-04".into(), span, }, - Value::String { val: "2020-01-05".into(), span, }, - Value::String { val: "2020-01-06".into(), span, }, - Value::String { val: "2020-01-07".into(), span, }, - Value::String { val: "2020-01-08".into(), span, }, - Value::String { val: "2020-01-09".into(), span, }, - Value::String { val: "2020-01-10".into(), span, }, + Value::test_string("2020-01-01"), + Value::test_string("2020-01-02"), + Value::test_string("2020-01-03"), + Value::test_string("2020-01-04"), + Value::test_string("2020-01-05"), + Value::test_string("2020-01-06"), + Value::test_string("2020-01-07"), + Value::test_string("2020-01-08"), + Value::test_string("2020-01-09"), + Value::test_string("2020-01-10"), ], - span, + span: Span::test_data(), }), }, Example { @@ -101,15 +99,15 @@ impl Command for SeqDate { example: "seq date -b '2020-01-01' -e '2020-01-31' -n 5", result: Some(Value::List { vals: vec![ - Value::String { val: "2020-01-01".into(), span, }, - Value::String { val: "2020-01-06".into(), span, }, - Value::String { val: "2020-01-11".into(), span, }, - Value::String { val: "2020-01-16".into(), span, }, - Value::String { val: "2020-01-21".into(), span, }, - Value::String { val: "2020-01-26".into(), span, }, - Value::String { val: "2020-01-31".into(), span, }, + Value::test_string("2020-01-01"), + Value::test_string("2020-01-06"), + Value::test_string("2020-01-11"), + Value::test_string("2020-01-16"), + Value::test_string("2020-01-21"), + Value::test_string("2020-01-26"), + Value::test_string("2020-01-31"), ], - span, + span: Span::test_data(), }), }, ] @@ -155,7 +153,7 @@ impl Command for SeqDate { let inc = match increment { Some(i) => Value::int(i.item, i.span), - _ => Value::int(1_i64, Span::test_data()), + _ => Value::int(1_i64, call.head), }; let day_count = days.map(|i| Value::int(i.item, i.span)); @@ -165,10 +163,10 @@ impl Command for SeqDate { rev = reverse; } - Ok( - run_seq_dates(outformat, informat, begin, end, inc, day_count, rev)? - .into_pipeline_data(), - ) + Ok(run_seq_dates( + outformat, informat, begin, end, inc, day_count, rev, call.head, + )? + .into_pipeline_data()) } } @@ -189,6 +187,7 @@ pub fn run_seq_dates( increment: Value, day_count: Option, reverse: bool, + call_span: Span, ) -> Result { let today = Local::now().date_naive(); // if cannot convert , it will return error @@ -243,7 +242,7 @@ pub fn run_seq_dates( return Err(ShellError::GenericError( e.to_string(), "Failed to parse date".to_string(), - Some(Span::test_data()), + Some(call_span), None, Vec::new(), )) @@ -259,7 +258,7 @@ pub fn run_seq_dates( return Err(ShellError::GenericError( e.to_string(), "Failed to parse date".to_string(), - Some(Span::test_data()), + Some(call_span), None, Vec::new(), )) @@ -286,7 +285,7 @@ pub fn run_seq_dates( return Err(ShellError::GenericError( "integer value too large".to_string(), "integer value too large".to_string(), - Some(Span::test_data()), + Some(call_span), None, Vec::new(), )); @@ -308,7 +307,7 @@ pub fn run_seq_dates( return Err(ShellError::GenericError( "date is out of range".to_string(), "date is out of range".to_string(), - Some(Span::test_data()), + Some(call_span), None, Vec::new(), )); @@ -317,7 +316,7 @@ pub fn run_seq_dates( let mut ret = vec![]; loop { let date_string = &next.format(&out_format).to_string(); - ret.push(Value::string(date_string, Span::test_data())); + ret.push(Value::string(date_string, call_span)); next += Duration::days(step_size); if is_out_of_range(next) { @@ -327,7 +326,7 @@ pub fn run_seq_dates( Ok(Value::List { vals: ret, - span: Span::test_data(), + span: call_span, }) } diff --git a/crates/nu-command/src/math/abs.rs b/crates/nu-command/src/math/abs.rs index caad5cca4a..546a0ee427 100644 --- a/crates/nu-command/src/math/abs.rs +++ b/crates/nu-command/src/math/abs.rs @@ -46,7 +46,7 @@ impl Command for SubCommand { result: Some(Value::List { vals: vec![ Value::test_int(50), - Value::float(100.0, Span::test_data()), + Value::test_float(100.0), Value::test_int(25), ], span: Span::test_data(), diff --git a/crates/nu-command/src/math/avg.rs b/crates/nu-command/src/math/avg.rs index cc7d3f66cb..c081d2b3ee 100644 --- a/crates/nu-command/src/math/avg.rs +++ b/crates/nu-command/src/math/avg.rs @@ -40,7 +40,7 @@ impl Command for SubCommand { vec![Example { description: "Compute the average of a list of numbers", example: "[-50 100.0 25] | math avg", - result: Some(Value::float(25.0, Span::test_data())), + result: Some(Value::test_float(25.0)), }] } } diff --git a/crates/nu-command/src/math/eval.rs b/crates/nu-command/src/math/eval.rs index 3be0bea9ec..7eef75e45f 100644 --- a/crates/nu-command/src/math/eval.rs +++ b/crates/nu-command/src/math/eval.rs @@ -47,7 +47,7 @@ impl Command for SubCommand { vec![Example { description: "Evaluate math in the pipeline", example: "'10 / 4' | math eval", - result: Some(Value::float(2.5, Span::test_data())), + result: Some(Value::test_float(2.5)), }] } } diff --git a/crates/nu-command/src/math/median.rs b/crates/nu-command/src/math/median.rs index 03c3eda5b0..093709fcbe 100644 --- a/crates/nu-command/src/math/median.rs +++ b/crates/nu-command/src/math/median.rs @@ -46,7 +46,7 @@ impl Command for SubCommand { Example { description: "Compute the median of a list of numbers", example: "[3 8 9 12 12 15] | math median", - result: Some(Value::float(10.5, Span::test_data())), + result: Some(Value::test_float(10.5)), }, Example { description: "Compute the medians of the columns of a table", diff --git a/crates/nu-command/src/math/round.rs b/crates/nu-command/src/math/round.rs index 14495c2b61..3559fe5224 100644 --- a/crates/nu-command/src/math/round.rs +++ b/crates/nu-command/src/math/round.rs @@ -68,9 +68,9 @@ impl Command for SubCommand { example: "[1.555 2.333 -3.111] | math round -p 2", result: Some(Value::List { vals: vec![ - Value::float(1.56, Span::test_data()), - Value::float(2.33, Span::test_data()), - Value::float(-3.11, Span::test_data()), + Value::test_float(1.56), + Value::test_float(2.33), + Value::test_float(-3.11), ], span: Span::test_data(), }), diff --git a/crates/nu-command/src/math/stddev.rs b/crates/nu-command/src/math/stddev.rs index 27a643f790..8ccd54d4b0 100644 --- a/crates/nu-command/src/math/stddev.rs +++ b/crates/nu-command/src/math/stddev.rs @@ -54,12 +54,12 @@ impl Command for SubCommand { Example { description: "Compute the standard deviation of a list of numbers", example: "[1 2 3 4 5] | math stddev", - result: Some(Value::float(std::f64::consts::SQRT_2, Span::test_data())), + result: Some(Value::test_float(std::f64::consts::SQRT_2)), }, Example { description: "Compute the sample standard deviation of a list of numbers", example: "[1 2 3 4 5] | math stddev -s", - result: Some(Value::float(1.5811388300841898, Span::test_data())), + result: Some(Value::test_float(1.5811388300841898)), }, ] } diff --git a/crates/nu-command/src/math/variance.rs b/crates/nu-command/src/math/variance.rs index 799f702143..35f4486f63 100644 --- a/crates/nu-command/src/math/variance.rs +++ b/crates/nu-command/src/math/variance.rs @@ -46,12 +46,12 @@ impl Command for SubCommand { Example { description: "Get the variance of a list of numbers", example: "[1 2 3 4 5] | math variance", - result: Some(Value::float(2.0, Span::test_data())), + result: Some(Value::test_float(2.0)), }, Example { description: "Get the sample variance of a list of numbers", example: "[1 2 3 4 5] | math variance -s", - result: Some(Value::float(2.5, Span::test_data())), + result: Some(Value::test_float(2.5)), }, ] } diff --git a/crates/nu-command/src/network/port.rs b/crates/nu-command/src/network/port.rs index 812804747e..02fd1fb08f 100644 --- a/crates/nu-command/src/network/port.rs +++ b/crates/nu-command/src/network/port.rs @@ -5,7 +5,7 @@ use nu_protocol::IntoPipelineData; use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpListener}; use nu_protocol::{ - Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, + Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -51,7 +51,7 @@ impl Command for SubCommand { Example { description: "get a free port between 3121 and 4000", example: "port 3121 4000", - result: Some(Value::int(3121, Span::test_data())), + result: Some(Value::test_int(3121)), }, Example { description: "get a free port from system", diff --git a/crates/nu-command/src/path/exists.rs b/crates/nu-command/src/path/exists.rs index 5a0dae9f45..05f8825111 100644 --- a/crates/nu-command/src/path/exists.rs +++ b/crates/nu-command/src/path/exists.rs @@ -75,7 +75,7 @@ If you need to distinguish dirs and files, please use `path type`."# Example { description: "Check if a file exists", example: "'C:\\Users\\joe\\todo.txt' | path exists", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, Example { description: "Check if a file exists in a column", @@ -91,7 +91,7 @@ If you need to distinguish dirs and files, please use `path type`."# Example { description: "Check if a file exists", example: "'/home/joe/todo.txt' | path exists", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, Example { description: "Check if a file exists in a column", diff --git a/crates/nu-command/src/platform/dir_info.rs b/crates/nu-command/src/platform/dir_info.rs index 13d566b305..61ce71e38c 100644 --- a/crates/nu-command/src/platform/dir_info.rs +++ b/crates/nu-command/src/platform/dir_info.rs @@ -255,13 +255,13 @@ impl From for Value { }); cols.push("directories".into()); - vals.push(Value::nothing(Span::test_data())); + vals.push(Value::nothing(Span::unknown())); cols.push("files".into()); - vals.push(Value::nothing(Span::test_data())); + vals.push(Value::nothing(Span::unknown())); // cols.push("errors".into()); - // vals.push(Value::nothing(Span::test_data())); + // vals.push(Value::nothing(Span::unknown())); Value::Record { cols, diff --git a/crates/nu-command/src/platform/reedline_commands/keybindings_listen.rs b/crates/nu-command/src/platform/reedline_commands/keybindings_listen.rs index 1e454ddba5..e7e8fcf2a5 100644 --- a/crates/nu-command/src/platform/reedline_commands/keybindings_listen.rs +++ b/crates/nu-command/src/platform/reedline_commands/keybindings_listen.rs @@ -93,7 +93,7 @@ pub fn print_events(engine_state: &EngineState) -> Result { } terminal::disable_raw_mode()?; - Ok(Value::nothing(Span::test_data())) + Ok(Value::nothing(Span::unknown())) } // this fn is totally ripped off from crossterm's examples @@ -113,12 +113,12 @@ fn print_events_helper(event: Event) -> Result { "flags".into(), ], vals: vec![ - Value::string(format!("{}", c), Span::test_data()), - Value::string(format!("{:#08x}", u32::from(c)), Span::test_data()), - Value::string(format!("{:?}", modifiers), Span::test_data()), - Value::string(format!("{:#08b}", modifiers), Span::test_data()), + Value::string(format!("{}", c), Span::unknown()), + Value::string(format!("{:#08x}", u32::from(c)), Span::unknown()), + Value::string(format!("{:?}", modifiers), Span::unknown()), + Value::string(format!("{:#08b}", modifiers), Span::unknown()), ], - span: Span::test_data(), + span: Span::unknown(), }; Ok(record) } @@ -126,11 +126,11 @@ fn print_events_helper(event: Event) -> Result { let record = Value::Record { cols: vec!["code".into(), "modifier".into(), "flags".into()], vals: vec![ - Value::string(format!("{:?}", code), Span::test_data()), - Value::string(format!("{:?}", modifiers), Span::test_data()), - Value::string(format!("{:#08b}", modifiers), Span::test_data()), + Value::string(format!("{:?}", code), Span::unknown()), + Value::string(format!("{:?}", modifiers), Span::unknown()), + Value::string(format!("{:#08b}", modifiers), Span::unknown()), ], - span: Span::test_data(), + span: Span::unknown(), }; Ok(record) } @@ -138,8 +138,8 @@ fn print_events_helper(event: Event) -> Result { } else { let record = Value::Record { cols: vec!["event".into()], - vals: vec![Value::string(format!("{:?}", event), Span::test_data())], - span: Span::test_data(), + vals: vec![Value::string(format!("{:?}", event), Span::unknown())], + span: Span::unknown(), }; Ok(record) } diff --git a/crates/nu-command/src/platform/term_size.rs b/crates/nu-command/src/platform/term_size.rs index 0daf1bf2a3..1afb067272 100644 --- a/crates/nu-command/src/platform/term_size.rs +++ b/crates/nu-command/src/platform/term_size.rs @@ -1,8 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{ - Category, Example, IntoPipelineData, PipelineData, Signature, Span, Type, Value, -}; +use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Type, Value}; use terminal_size::{terminal_size, Height, Width}; #[derive(Clone)] @@ -66,8 +64,8 @@ impl Command for TermSize { Ok(Value::Record { cols: vec!["columns".into(), "rows".into()], vals: vec![ - Value::int(cols.0 as i64, Span::test_data()), - Value::int(rows.0 as i64, Span::test_data()), + Value::int(cols.0 as i64, head), + Value::int(rows.0 as i64, head), ], span: head, } diff --git a/crates/nu-command/src/sort_utils.rs b/crates/nu-command/src/sort_utils.rs index 00b597d126..4560a8505b 100644 --- a/crates/nu-command/src/sort_utils.rs +++ b/crates/nu-command/src/sort_utils.rs @@ -104,7 +104,7 @@ pub fn sort( for col in &sort_columns { let val = match item.get_data_by_key(col) { Some(v) => v, - None => Value::nothing(Span::test_data()), + None => Value::nothing(Span::unknown()), }; vals.push(val); } diff --git a/crates/nu-command/src/strings/encode_decode/base64.rs b/crates/nu-command/src/strings/encode_decode/base64.rs index 65673c3e5e..33908e70df 100644 --- a/crates/nu-command/src/strings/encode_decode/base64.rs +++ b/crates/nu-command/src/strings/encode_decode/base64.rs @@ -249,7 +249,7 @@ mod tests { #[test] fn base64_decode_binhex() { - let word = Value::string("A5\"KC9jRB@IIF'8bF!", Span::test_data()); + let word = Value::test_string("A5\"KC9jRB@IIF'8bF!"); let expected = Value::binary(b"a binhex test".as_slice(), Span::test_data()); let actual = action( @@ -272,7 +272,7 @@ mod tests { #[test] fn base64_decode_binhex_with_new_line_input() { - let word = Value::string("A5\"KC9jRB\n@IIF'8bF!", Span::test_data()); + let word = Value::test_string("A5\"KC9jRB\n@IIF'8bF!"); let expected = Value::binary(b"a binhex test".as_slice(), Span::test_data()); let actual = action( diff --git a/crates/nu-command/src/strings/encode_decode/encode_base64.rs b/crates/nu-command/src/strings/encode_decode/encode_base64.rs index 31e02abda2..4782afa7fb 100644 --- a/crates/nu-command/src/strings/encode_decode/encode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/encode_base64.rs @@ -2,7 +2,7 @@ use super::base64::{operate, ActionType, CHARACTER_SET_DESC}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, + Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -54,7 +54,7 @@ impl Command for EncodeBase64 { Example { description: "Encode a string with the binhex character set", example: "'Some Data' | encode base64 --character-set binhex", - result: Some(Value::string(r#"7epXB5"%A@4J"#, Span::test_data())), + result: Some(Value::test_string(r#"7epXB5"%A@4J"#)), }, ] } diff --git a/crates/nu-command/src/strings/size.rs b/crates/nu-command/src/strings/size.rs index 89904a6117..5875409a9c 100644 --- a/crates/nu-command/src/strings/size.rs +++ b/crates/nu-command/src/strings/size.rs @@ -55,11 +55,11 @@ impl Command for Size { "graphemes".into(), ], vals: vec![ - Value::int(1, Span::test_data()), - Value::int(7, Span::test_data()), - Value::int(38, Span::test_data()), - Value::int(38, Span::test_data()), - Value::int(38, Span::test_data()), + Value::test_int(1), + Value::test_int(7), + Value::test_int(38), + Value::test_int(38), + Value::test_int(38), ], span: Span::test_data(), }), @@ -76,11 +76,11 @@ impl Command for Size { "graphemes".into(), ], vals: vec![ - Value::int(1, Span::test_data()), - Value::int(6, Span::test_data()), - Value::int(18, Span::test_data()), - Value::int(6, Span::test_data()), - Value::int(6, Span::test_data()), + Value::test_int(1), + Value::test_int(6), + Value::test_int(18), + Value::test_int(6), + Value::test_int(6), ], span: Span::test_data(), }), @@ -97,11 +97,11 @@ impl Command for Size { "graphemes".into(), ], vals: vec![ - Value::int(1, Span::test_data()), - Value::int(2, Span::test_data()), - Value::int(15, Span::test_data()), - Value::int(14, Span::test_data()), - Value::int(13, Span::test_data()), + Value::test_int(1), + Value::test_int(2), + Value::test_int(15), + Value::test_int(14), + Value::test_int(13), ], 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 117866f2bf..f1df1b126a 100644 --- a/crates/nu-command/src/strings/str_/contains.rs +++ b/crates/nu-command/src/strings/str_/contains.rs @@ -73,12 +73,12 @@ impl Command for SubCommand { Example { description: "Check if input contains string", example: "'my_library.rb' | str contains '.rb'", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Check if input contains string case insensitive", example: "'my_library.rb' | str contains -i '.RB'", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Check if input contains string in a table", @@ -86,10 +86,7 @@ impl Command for SubCommand { result: Some(Value::List { vals: vec![Value::Record { cols: vec!["ColA".to_string(), "ColB".to_string()], - vals: vec![ - Value::boolean(true, Span::test_data()), - Value::test_int(100), - ], + vals: vec![Value::test_bool(true), Value::test_int(100)], span: Span::test_data(), }], span: Span::test_data(), @@ -101,10 +98,7 @@ impl Command for SubCommand { result: Some(Value::List { vals: vec![Value::Record { cols: vec!["ColA".to_string(), "ColB".to_string()], - vals: vec![ - Value::boolean(true, Span::test_data()), - Value::test_int(100), - ], + vals: vec![Value::test_bool(true), Value::test_int(100)], span: Span::test_data(), }], span: Span::test_data(), @@ -116,10 +110,7 @@ impl Command for SubCommand { result: Some(Value::List { vals: vec![Value::Record { cols: vec!["ColA".to_string(), "ColB".to_string()], - vals: vec![ - Value::boolean(true, Span::test_data()), - Value::boolean(true, Span::test_data()), - ], + vals: vec![Value::test_bool(true), Value::test_bool(true)], span: Span::test_data(), }], span: Span::test_data(), @@ -128,16 +119,16 @@ impl Command for SubCommand { Example { description: "Check if input string contains 'banana'", example: "'hello' | str contains 'banana'", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, Example { description: "Check if list contains string", example: "[one two three] | str contains o", result: Some(Value::List { vals: vec![ - Value::boolean(true, Span::test_data()), - Value::boolean(true, Span::test_data()), - Value::boolean(false, Span::test_data()), + Value::test_bool(true), + Value::test_bool(true), + Value::test_bool(false), ], span: Span::test_data(), }), @@ -147,9 +138,9 @@ impl Command for SubCommand { example: "[one two three] | str contains -n o", result: Some(Value::List { vals: vec![ - Value::boolean(false, Span::test_data()), - Value::boolean(false, Span::test_data()), - Value::boolean(true, Span::test_data()), + Value::test_bool(false), + Value::test_bool(false), + Value::test_bool(true), ], span: Span::test_data(), }), diff --git a/crates/nu-command/src/strings/str_/ends_with.rs b/crates/nu-command/src/strings/str_/ends_with.rs index b6054b8586..b490a40219 100644 --- a/crates/nu-command/src/strings/str_/ends_with.rs +++ b/crates/nu-command/src/strings/str_/ends_with.rs @@ -67,12 +67,12 @@ impl Command for SubCommand { Example { description: "Checks if string ends with '.rb'", example: "'my_library.rb' | str ends-with '.rb'", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Checks if string ends with '.txt'", example: "'my_library.rb' | str ends-with '.txt'", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, ] } diff --git a/crates/nu-command/src/strings/str_/starts_with.rs b/crates/nu-command/src/strings/str_/starts_with.rs index 4299bb5b0e..4a50b967fb 100644 --- a/crates/nu-command/src/strings/str_/starts_with.rs +++ b/crates/nu-command/src/strings/str_/starts_with.rs @@ -70,17 +70,17 @@ impl Command for SubCommand { Example { description: "Checks if input string starts with 'my'", example: "'my_library.rb' | str starts-with 'my'", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Checks if input string starts with 'my'", example: "'Cargo.toml' | str starts-with 'Car'", - result: Some(Value::boolean(true, Span::test_data())), + result: Some(Value::test_bool(true)), }, Example { description: "Checks if input string starts with 'my'", example: "'Cargo.toml' | str starts-with '.toml'", - result: Some(Value::boolean(false, Span::test_data())), + result: Some(Value::test_bool(false)), }, ] } diff --git a/crates/nu-command/src/strings/str_/substring.rs b/crates/nu-command/src/strings/str_/substring.rs index d72dec784d..3335a42fbc 100644 --- a/crates/nu-command/src/strings/str_/substring.rs +++ b/crates/nu-command/src/strings/str_/substring.rs @@ -333,7 +333,7 @@ mod tests { Span::test_data(), ); - assert_eq!(actual, Value::string(expected, Span::test_data())); + assert_eq!(actual, Value::test_string(expected)); } } } diff --git a/crates/nu-command/src/strings/str_/trim/trim_.rs b/crates/nu-command/src/strings/str_/trim/trim_.rs index 4011d3d805..5f807b9ff8 100644 --- a/crates/nu-command/src/strings/str_/trim/trim_.rs +++ b/crates/nu-command/src/strings/str_/trim/trim_.rs @@ -302,7 +302,7 @@ mod tests { cols: cols.iter().map(|x| x.to_string()).collect(), vals: vals .iter() - .map(|x| Value::string(x.to_string(), Span::test_data())) + .map(|x| Value::test_string(x.to_string())) .collect(), span: Span::test_data(), } @@ -312,7 +312,7 @@ mod tests { Value::List { vals: vals .iter() - .map(|x| Value::string(x.to_string(), Span::test_data())) + .map(|x| Value::test_string(x.to_string())) .collect(), span: Span::test_data(), } @@ -477,7 +477,7 @@ mod tests { let row = Value::List { vals: vec![ Value::test_string(" nu shell "), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string(" d"), ], span: Span::test_data(), @@ -485,7 +485,7 @@ mod tests { let expected = Value::List { vals: vec![ Value::test_string("nushell"), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string("d"), ], span: Span::test_data(), @@ -549,7 +549,7 @@ mod tests { let row = Value::List { vals: vec![ Value::test_string("##nu####shell##"), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string("#d"), ], span: Span::test_data(), @@ -557,7 +557,7 @@ mod tests { let expected = Value::List { vals: vec![ Value::test_string("nushell"), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string("d"), ], span: Span::test_data(), @@ -659,7 +659,7 @@ mod tests { let row = Value::List { vals: vec![ Value::test_string(" a "), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string(" d"), ], span: Span::test_data(), @@ -667,7 +667,7 @@ mod tests { let expected = Value::List { vals: vec![ Value::test_string("a "), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string("d"), ], span: Span::test_data(), @@ -784,7 +784,7 @@ mod tests { let row = Value::List { vals: vec![ Value::test_string(" a "), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string(" d"), ], span: Span::test_data(), @@ -792,7 +792,7 @@ mod tests { let expected = Value::List { vals: vec![ Value::test_string(" a"), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string(" d"), ], span: Span::test_data(), @@ -911,7 +911,7 @@ mod tests { let row = Value::List { vals: vec![ Value::test_string(" a b c d "), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string(" b c d e f"), ], span: Span::test_data(), @@ -919,7 +919,7 @@ mod tests { let expected = Value::List { vals: vec![ Value::test_string("a b c d"), - Value::int(65, Span::test_data()), + Value::test_int(65), Value::test_string("b c d e f"), ], span: Span::test_data(), diff --git a/crates/nu-command/src/system/registry_query.rs b/crates/nu-command/src/system/registry_query.rs index 224556fe94..3d484fcf34 100644 --- a/crates/nu-command/src/system/registry_query.rs +++ b/crates/nu-command/src/system/registry_query.rs @@ -94,6 +94,8 @@ fn registry_query( stack: &mut Stack, call: &Call, ) -> Result { + let call_span = call.head; + let registry_key: Spanned = call.req(engine_state, stack, 0)?; let registry_key_span = ®istry_key.clone().span; let registry_value: Option> = call.opt(engine_state, stack, 1)?; @@ -112,18 +114,18 @@ fn registry_query( key: registry_key.item, }; - let reg_key = get_reg_key(reg_params)?; + let reg_key = get_reg_key(reg_params, call_span)?; if registry_value.is_none() { let mut reg_values = vec![]; for (name, val) in reg_key.enum_values().flatten() { - let (nu_value, reg_type) = reg_value_to_nu_value(val); + let (nu_value, reg_type) = reg_value_to_nu_value(val, call_span); reg_values.push(Value::Record { cols: vec!["name".to_string(), "value".to_string(), "type".to_string()], vals: vec![ - Value::string(name, Span::test_data()), + Value::string(name, call_span), nu_value, - Value::string(format!("{:?}", reg_type), Span::test_data()), + Value::string(format!("{:?}", reg_type), call_span), ], span: *registry_key_span, }) @@ -135,13 +137,13 @@ fn registry_query( let reg_value = reg_key.get_raw_value(value.item.as_str()); match reg_value { Ok(val) => { - let (nu_value, reg_type) = reg_value_to_nu_value(val); + let (nu_value, reg_type) = reg_value_to_nu_value(val, call_span); Ok(Value::Record { cols: vec!["name".to_string(), "value".to_string(), "type".to_string()], vals: vec![ - Value::string(value.item, Span::test_data()), + Value::string(value.item, call_span), nu_value, - Value::string(format!("{:?}", reg_type), Span::test_data()), + Value::string(format!("{:?}", reg_type), call_span), ], span: value.span, } @@ -156,12 +158,12 @@ fn registry_query( )), } } - None => Ok(Value::nothing(Span::test_data()).into_pipeline_data()), + None => Ok(Value::nothing(call_span).into_pipeline_data()), } } } -fn get_reg_key(reg_params: RegistryQueryArgs) -> Result { +fn get_reg_key(reg_params: RegistryQueryArgs, call_span: Span) -> Result { let mut key_count = 0; let registry_key = if reg_params.hkcr { key_count += 1; @@ -201,7 +203,7 @@ fn get_reg_key(reg_params: RegistryQueryArgs) -> Result { return Err(ShellError::GenericError( "Only one registry key can be specified".into(), "Only one registry key can be specified".into(), - Some(Span::test_data()), + Some(call_span), None, Vec::new(), )); @@ -211,59 +213,57 @@ fn get_reg_key(reg_params: RegistryQueryArgs) -> Result { fn reg_value_to_nu_value( reg_value: winreg::RegValue, + call_span: Span, ) -> (nu_protocol::Value, winreg::enums::RegType) { match reg_value.vtype { - REG_NONE => (Value::nothing(Span::test_data()), reg_value.vtype), + REG_NONE => (Value::nothing(call_span), reg_value.vtype), REG_SZ => ( - Value::string(reg_value.to_string(), Span::test_data()), + Value::string(reg_value.to_string(), call_span), reg_value.vtype, ), REG_EXPAND_SZ => ( - Value::string(reg_value.to_string(), Span::test_data()), - reg_value.vtype, - ), - REG_BINARY => ( - Value::binary(reg_value.bytes, Span::test_data()), + Value::string(reg_value.to_string(), call_span), reg_value.vtype, ), + REG_BINARY => (Value::binary(reg_value.bytes, call_span), reg_value.vtype), REG_DWORD => ( Value::int( unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64, - Span::test_data(), + call_span, ), reg_value.vtype, ), REG_DWORD_BIG_ENDIAN => ( Value::int( unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64, - Span::test_data(), + call_span, ), reg_value.vtype, ), REG_LINK => ( - Value::string(reg_value.to_string(), Span::test_data()), + Value::string(reg_value.to_string(), call_span), reg_value.vtype, ), REG_MULTI_SZ => ( - Value::string(reg_value.to_string(), Span::test_data()), + Value::string(reg_value.to_string(), call_span), reg_value.vtype, ), REG_RESOURCE_LIST => ( - Value::string(reg_value.to_string(), Span::test_data()), + Value::string(reg_value.to_string(), call_span), reg_value.vtype, ), REG_FULL_RESOURCE_DESCRIPTOR => ( - Value::string(reg_value.to_string(), Span::test_data()), + Value::string(reg_value.to_string(), call_span), reg_value.vtype, ), REG_RESOURCE_REQUIREMENTS_LIST => ( - Value::string(reg_value.to_string(), Span::test_data()), + Value::string(reg_value.to_string(), call_span), reg_value.vtype, ), REG_QWORD => ( Value::int( unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64, - Span::test_data(), + call_span, ), reg_value.vtype, ), diff --git a/crates/nu-engine/src/env.rs b/crates/nu-engine/src/env.rs index 9545e8399f..9dc25e7e96 100644 --- a/crates/nu-engine/src/env.rs +++ b/crates/nu-engine/src/env.rs @@ -410,7 +410,7 @@ fn ensure_path(scope: &mut HashMap, env_path_name: &str) -> Optio Ok(sp) => sp, Err(e) => { error = error.or(Some(e)); - Span::test_data() // FIXME: any better span to use here? + Span::unknown() // FIXME: any better span to use here? } }; diff --git a/crates/nu-protocol/tests/test_value.rs b/crates/nu-protocol/tests/test_value.rs index b14fc7a9c4..be3f8e9395 100644 --- a/crates/nu-protocol/tests/test_value.rs +++ b/crates/nu-protocol/tests/test_value.rs @@ -3,9 +3,9 @@ use nu_protocol::{Span, Value}; #[test] fn test_comparison_nothing() { let values = vec![ - Value::int(1, Span::test_data()), + Value::test_int(1), Value::test_string("string"), - Value::float(1.0, Span::test_data()), + Value::test_float(1.0), ]; let nothing = Value::Nothing { diff --git a/crates/nu_plugin_query/src/query_json.rs b/crates/nu_plugin_query/src/query_json.rs index 616fd18c21..ef28a372b3 100644 --- a/crates/nu_plugin_query/src/query_json.rs +++ b/crates/nu_plugin_query/src/query_json.rs @@ -45,7 +45,7 @@ pub fn execute_json_query( if query_contains_modifiers(query_string) { let json_str = val.json(); - Ok(Value::string(json_str, Span::test_data())) + Ok(Value::string(json_str, call.head)) } else { Ok(convert_gjson_value_to_nu_value(&val, &call.head)) } diff --git a/crates/nu_plugin_query/src/query_web.rs b/crates/nu_plugin_query/src/query_web.rs index e96f7c5960..224572e274 100644 --- a/crates/nu_plugin_query/src/query_web.rs +++ b/crates/nu_plugin_query/src/query_web.rs @@ -17,7 +17,7 @@ impl Selector { query: String::new(), as_html: false, attribute: String::new(), - as_table: Value::string("".to_string(), Span::test_data()), + as_table: Value::string("".to_string(), Span::unknown()), inspect: false, } } diff --git a/crates/nu_plugin_query/src/query_xml.rs b/crates/nu_plugin_query/src/query_xml.rs index 75e08f56ab..aec6dd907f 100644 --- a/crates/nu_plugin_query/src/query_xml.rs +++ b/crates/nu_plugin_query/src/query_xml.rs @@ -61,20 +61,20 @@ pub fn execute_xpath_query( sxd_xpath::Value::Nodeset(ns) => { for n in ns.into_iter() { cols.push(key.to_string()); - vals.push(Value::string(n.string_value(), Span::test_data())); + vals.push(Value::string(n.string_value(), call.head)); } } sxd_xpath::Value::Boolean(b) => { cols.push(key.to_string()); - vals.push(Value::boolean(b, Span::test_data())); + vals.push(Value::boolean(b, call.head)); } sxd_xpath::Value::Number(n) => { cols.push(key.to_string()); - vals.push(Value::float(n, Span::test_data())); + vals.push(Value::float(n, call.head)); } sxd_xpath::Value::String(s) => { cols.push(key.to_string()); - vals.push(Value::string(s, Span::test_data())); + vals.push(Value::string(s, call.head)); } }; @@ -84,19 +84,19 @@ pub fn execute_xpath_query( records.push(Value::Record { cols: vec![k.to_string()], vals: vec![v.clone()], - span: Span::test_data(), + span: call.head, }) } Ok(Value::List { vals: records, - span: Span::test_data(), + span: call.head, }) } Err(_) => Err(LabeledError { label: "xpath query error".to_string(), msg: "xpath query error".to_string(), - span: Some(Span::test_data()), + span: Some(call.head), }), } } @@ -146,7 +146,7 @@ mod tests { let expected = Value::List { vals: vec![Value::Record { cols: vec!["count(//a/*[posit...".to_string()], - vals: vec![Value::float(1.0, Span::test_data())], + vals: vec![Value::test_float(1.0)], span: Span::test_data(), }], span: Span::test_data(), @@ -177,7 +177,7 @@ mod tests { let expected = Value::List { vals: vec![Value::Record { cols: vec!["count(//*[contain...".to_string()], - vals: vec![Value::float(1.0, Span::test_data())], + vals: vec![Value::test_float(1.0)], span: Span::test_data(), }], span: Span::test_data(), diff --git a/src/test_bins.rs b/src/test_bins.rs index 9144b5e184..e39b459241 100644 --- a/src/test_bins.rs +++ b/src/test_bins.rs @@ -5,7 +5,7 @@ use nu_command::create_default_context; use nu_engine::eval_block; use nu_parser::parse; use nu_protocol::engine::{EngineState, Stack, StateWorkingSet}; -use nu_protocol::{CliError, PipelineData, Span, Value}; +use nu_protocol::{CliError, PipelineData, Value}; // use nu_test_support::fs::in_directory; /// Echo's value of env keys from args @@ -149,10 +149,7 @@ pub fn nu_repl() { let mut engine_state = create_default_context(); let mut stack = Stack::new(); - stack.add_env_var( - "PWD".to_string(), - Value::string(cwd.to_string_lossy(), Span::test_data()), - ); + stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy())); let mut last_output = String::new();