mirror of
https://github.com/nushell/nushell
synced 2024-12-25 20:43:09 +00:00
Further cleanup of Span::test_data
usage + span fixes (#7595)
# Description Inspired by #7592 For brevity use `Value::test_{string,int,float,bool}` Includes fixes to commands that were abusing `Span::test_data` in their implementation. Now the call span is used where possible or the explicit `Span::unknonw` is used. ## Command fixes - Fix abuse of `Span::test_data()` in `query_xml` - Fix abuse of `Span::test_data()` in `term size` - Fix abuse of `Span::test_data()` in `seq date` - Fix two abuses of `Span::test_data` in `nu-cli` - Change `Span::test_data` to `Span::unknown` in `keybindings listen` - Add proper call span to `registry query` - Fix span use in `nu_plugin_query` - Fix span assignment in `select` - Use `Span::unknown` instead of `test_data` in more places ## Other - Use `Value::test_int`/`test_float()` consistently - More `test_string` and `test_bool` - Fix unused imports # User-Facing Changes Some commands may now provide more helpful spans for downstream use in errors
This commit is contained in:
parent
dd6fe6a04a
commit
45fe3be83e
59 changed files with 236 additions and 310 deletions
|
@ -7,8 +7,7 @@ use nu_parser::parse;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
create_menus,
|
create_menus,
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
extract_value, Config, IntoPipelineData, ParsedKeybinding, ParsedMenu, PipelineData,
|
extract_value, Config, ParsedKeybinding, ParsedMenu, PipelineData, ShellError, Span, Value,
|
||||||
ShellError, Span, Value,
|
|
||||||
};
|
};
|
||||||
use reedline::{
|
use reedline::{
|
||||||
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
|
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 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)?;
|
let res = eval_block(&engine_state, &mut temp_stack, &block, input, false, false)?;
|
||||||
|
|
||||||
if let PipelineData::Value(value, None) = res {
|
if let PipelineData::Value(value, None) = res {
|
||||||
|
|
|
@ -639,7 +639,7 @@ pub fn eval_string_with_input(
|
||||||
false,
|
false,
|
||||||
true,
|
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 {
|
pub fn get_command_finished_marker(stack: &Stack, engine_state: &EngineState) -> String {
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Apply bits and to two numbers",
|
description: "Apply bits and to two numbers",
|
||||||
example: "2 | bits and 2",
|
example: "2 | bits and 2",
|
||||||
result: Some(Value::int(2, Span::test_data())),
|
result: Some(Value::test_int(2)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Apply logical and to a list of numbers",
|
description: "Apply logical and to a list of numbers",
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Apply bits or to two numbers",
|
description: "Apply bits or to two numbers",
|
||||||
example: "2 | bits or 6",
|
example: "2 | bits or 6",
|
||||||
result: Some(Value::int(6, Span::test_data())),
|
result: Some(Value::test_int(6)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Apply logical or to a list of numbers",
|
description: "Apply logical or to a list of numbers",
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Rotate left a number with 2 bits",
|
description: "Rotate left a number with 2 bits",
|
||||||
example: "17 | bits rol 2",
|
example: "17 | bits rol 2",
|
||||||
result: Some(Value::int(68, Span::test_data())),
|
result: Some(Value::test_int(68)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Rotate left a list of numbers with 2 bits",
|
description: "Rotate left a list of numbers with 2 bits",
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Rotate right a number with 60 bits",
|
description: "Rotate right a number with 60 bits",
|
||||||
example: "17 | bits ror 60",
|
example: "17 | bits ror 60",
|
||||||
result: Some(Value::int(272, Span::test_data())),
|
result: Some(Value::test_int(272)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Rotate right a list of numbers of one byte",
|
description: "Rotate right a list of numbers of one byte",
|
||||||
|
|
|
@ -81,17 +81,17 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Shift left a number by 7 bits",
|
description: "Shift left a number by 7 bits",
|
||||||
example: "2 | bits shl 7",
|
example: "2 | bits shl 7",
|
||||||
result: Some(Value::int(256, Span::test_data())),
|
result: Some(Value::test_int(256)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Shift left a number with 1 byte by 7 bits",
|
description: "Shift left a number with 1 byte by 7 bits",
|
||||||
example: "2 | bits shl 7 -n 1",
|
example: "2 | bits shl 7 -n 1",
|
||||||
result: Some(Value::int(0, Span::test_data())),
|
result: Some(Value::test_int(0)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Shift left a signed number by 1 bit",
|
description: "Shift left a signed number by 1 bit",
|
||||||
example: "0x7F | bits shl 1 -s",
|
example: "0x7F | bits shl 1 -s",
|
||||||
result: Some(Value::int(254, Span::test_data())),
|
result: Some(Value::test_int(254)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Shift left a list of numbers",
|
description: "Shift left a list of numbers",
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Shift right a number with 2 bits",
|
description: "Shift right a number with 2 bits",
|
||||||
example: "8 | bits shr 2",
|
example: "8 | bits shr 2",
|
||||||
result: Some(Value::int(2, Span::test_data())),
|
result: Some(Value::test_int(2)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Shift right a list of numbers",
|
description: "Shift right a list of numbers",
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Apply bits xor to two numbers",
|
description: "Apply bits xor to two numbers",
|
||||||
example: "2 | bits xor 2",
|
example: "2 | bits xor 2",
|
||||||
result: Some(Value::int(0, Span::test_data())),
|
result: Some(Value::test_int(0)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Apply logical xor to a list of numbers",
|
description: "Apply logical xor to a list of numbers",
|
||||||
|
|
|
@ -68,17 +68,17 @@ impl Command for BytesEndsWith {
|
||||||
Example {
|
Example {
|
||||||
description: "Checks if binary ends with `0x[AA]`",
|
description: "Checks if binary ends with `0x[AA]`",
|
||||||
example: "0x[1F FF AA AA] | bytes 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 {
|
Example {
|
||||||
description: "Checks if binary ends with `0x[FF AA AA]`",
|
description: "Checks if binary ends with `0x[FF AA AA]`",
|
||||||
example: "0x[1F FF AA AA] | bytes 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 {
|
Example {
|
||||||
description: "Checks if binary ends with `0x[11]`",
|
description: "Checks if binary ends with `0x[11]`",
|
||||||
example: "0x[1F FF AA AA] | bytes 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)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,17 +74,17 @@ impl Command for BytesStartsWith {
|
||||||
Example {
|
Example {
|
||||||
description: "Checks if binary starts with `0x[1F FF AA]`",
|
description: "Checks if binary starts with `0x[1F FF AA]`",
|
||||||
example: "0x[1F FF AA AA] | bytes 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 {
|
Example {
|
||||||
description: "Checks if binary starts with `0x[1F]`",
|
description: "Checks if binary starts with `0x[1F]`",
|
||||||
example: "0x[1F FF AA AA] | bytes 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 {
|
Example {
|
||||||
description: "Checks if binary starts with `0x[1F]`",
|
description: "Checks if binary starts with `0x[1F]`",
|
||||||
example: "0x[1F FF AA AA] | bytes starts-with 0x[11]",
|
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)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Convert file size to integer",
|
description: "Convert file size to integer",
|
||||||
example: "4KB | into int",
|
example: "4KB | into int",
|
||||||
result: Some(Value::int(4000, Span::test_data())),
|
result: Some(Value::test_int(4000)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert bool to integer",
|
description: "Convert bool to integer",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use nu_protocol::ast::{Call, Expr, Expression};
|
use nu_protocol::ast::{Call, Expr, Expression};
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -85,7 +85,7 @@ This command is a parser keyword. For details, check:
|
||||||
Example {
|
Example {
|
||||||
description: "Hide an environment variable",
|
description: "Hide an environment variable",
|
||||||
example: r#"let-env HZ_ENV_ABC = 1; hide HZ_ENV_ABC; 'HZ_ENV_ABC' in (env).name"#,
|
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)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ use nu_engine::CallExt;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
did_you_mean, Category, Example, PipelineData, ShellError, Signature, Span, Spanned,
|
did_you_mean, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape,
|
||||||
SyntaxShape, Type, Value,
|
Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -70,7 +70,7 @@ impl Command for HideEnv {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Hide an environment variable",
|
description: "Hide an environment variable",
|
||||||
example: r#"let-env HZ_ENV_ABC = 1; hide-env HZ_ENV_ABC; 'HZ_ENV_ABC' in (env).name"#,
|
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)),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use nu_engine::{eval_block, CallExt};
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Block, Command, EngineState, Stack};
|
use nu_protocol::engine::{Block, Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -81,7 +81,7 @@ impl Command for Loop {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Loop while a condition is true",
|
description: "Loop while a condition is true",
|
||||||
example: "mut x = 0; loop { if $x > 10 { break }; $x = $x + 1 }; $x",
|
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)),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,10 +209,7 @@ mod test_examples {
|
||||||
let mut stack = Stack::new();
|
let mut stack = Stack::new();
|
||||||
|
|
||||||
// Set up PWD
|
// Set up PWD
|
||||||
stack.add_env_var(
|
stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy()));
|
||||||
"PWD".to_string(),
|
|
||||||
Value::string(cwd.to_string_lossy(), Span::test_data()),
|
|
||||||
);
|
|
||||||
|
|
||||||
engine_state
|
engine_state
|
||||||
.merge_env(&mut stack, cwd)
|
.merge_env(&mut stack, cwd)
|
||||||
|
@ -294,10 +291,7 @@ mod test_examples {
|
||||||
|
|
||||||
let mut stack = Stack::new();
|
let mut stack = Stack::new();
|
||||||
|
|
||||||
stack.add_env_var(
|
stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy()));
|
||||||
"PWD".to_string(),
|
|
||||||
Value::string(cwd.to_string_lossy(), Span::test_data()),
|
|
||||||
);
|
|
||||||
|
|
||||||
match nu_engine::eval_block(engine_state, &mut stack, &block, input, true, true) {
|
match nu_engine::eval_block(engine_state, &mut stack, &block, input, true, true) {
|
||||||
Err(err) => panic!("test eval error in `{}`: {:?}", "TODO", err),
|
Err(err) => panic!("test eval error in `{}`: {:?}", "TODO", err),
|
||||||
|
|
|
@ -54,11 +54,7 @@ with 'transpose' first."#
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let stream_test_1 = vec![
|
let stream_test_1 = vec![Value::test_int(2), Value::test_int(4), Value::test_int(6)];
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
Value::int(4, Span::test_data()),
|
|
||||||
Value::int(6, Span::test_data()),
|
|
||||||
];
|
|
||||||
|
|
||||||
let stream_test_2 = vec![
|
let stream_test_2 = vec![
|
||||||
Value::Nothing {
|
Value::Nothing {
|
||||||
|
|
|
@ -42,10 +42,7 @@ impl Command for EachWhile {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let stream_test_1 = vec![
|
let stream_test_1 = vec![Value::test_int(2), Value::test_int(4)];
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
Value::int(4, Span::test_data()),
|
|
||||||
];
|
|
||||||
let stream_test_2 = vec![
|
let stream_test_2 = vec![
|
||||||
Value::test_string("Output: 1"),
|
Value::test_string("Output: 1"),
|
||||||
Value::test_string("Output: 2"),
|
Value::test_string("Output: 2"),
|
||||||
|
|
|
@ -2,7 +2,7 @@ use nu_engine::CallExt;
|
||||||
use nu_protocol::ast::{Call, CellPath};
|
use nu_protocol::ast::{Call, CellPath};
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Type, Value,
|
Category, Example, IntoPipelineData, PipelineData, Signature, SyntaxShape, Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -43,18 +43,18 @@ impl Command for Empty {
|
||||||
Example {
|
Example {
|
||||||
description: "Check if a string is empty",
|
description: "Check if a string is empty",
|
||||||
example: "'' | is-empty",
|
example: "'' | is-empty",
|
||||||
result: Some(Value::boolean(true, Span::test_data())),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check if a list is empty",
|
description: "Check if a list is empty",
|
||||||
example: "[] | is-empty",
|
example: "[] | is-empty",
|
||||||
result: Some(Value::boolean(true, Span::test_data())),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
// TODO: revisit empty cell path semantics for a record.
|
// TODO: revisit empty cell path semantics for a record.
|
||||||
description: "Check if more than one column are empty",
|
description: "Check if more than one column are empty",
|
||||||
example: "[[meal size]; [arepa small] [taco '']] | is-empty meal size",
|
example: "[[meal size]; [arepa small] [taco '']] | is-empty meal size",
|
||||||
result: Some(Value::boolean(false, Span::test_data())),
|
result: Some(Value::test_bool(false)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,17 +35,11 @@ impl Command for Group {
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let stream_test_1 = vec![
|
let stream_test_1 = vec![
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(3), Value::test_int(4)],
|
||||||
Value::int(3, Span::test_data()),
|
|
||||||
Value::int(4, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -3,7 +3,7 @@ use nu_engine::{eval_block, CallExt};
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Closure, Command, EngineState, Stack};
|
use nu_protocol::engine::{Closure, Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -52,17 +52,17 @@ impl Command for Reduce {
|
||||||
Example {
|
Example {
|
||||||
example: "[ 1 2 3 4 ] | reduce {|it, acc| $it + $acc }",
|
example: "[ 1 2 3 4 ] | reduce {|it, acc| $it + $acc }",
|
||||||
description: "Sum values of a list (same as 'math sum')",
|
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 {
|
||||||
example: "[ 8 7 6 ] | reduce {|it, acc, ind| $acc + $it + $ind }",
|
example: "[ 8 7 6 ] | reduce {|it, acc, ind| $acc + $it + $ind }",
|
||||||
description: "Sum values of a list, plus their indexes",
|
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 {
|
||||||
example: "[ 1 2 3 4 ] | reduce -f 10 {|it, acc| $acc + $it }",
|
example: "[ 1 2 3 4 ] | reduce -f 10 {|it, acc| $acc + $it }",
|
||||||
description: "Sum values with a starting value (fold)",
|
description: "Sum values with a starting value (fold)",
|
||||||
result: Some(Value::int(20, Span::test_data())),
|
result: Some(Value::test_int(20)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
example: r#"[ i o t ] | reduce -f "Arthur, King of the Britons" {|it, acc| $acc | str replace -a $it "X" }"#,
|
example: r#"[ i o t ] | reduce -f "Arthur, King of the Britons" {|it, acc| $acc | str replace -a $it "X" }"#,
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl Command for Reject {
|
||||||
example: "{a: 1, b: 2} | reject a",
|
example: "{a: 1, b: 2} | reject a",
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["b".into()],
|
cols: vec!["b".into()],
|
||||||
vals: vec![Value::int(2, Span::test_data())],
|
vals: vec![Value::test_int(2)],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -79,7 +79,7 @@ impl Command for Reject {
|
||||||
cols: vec!["a".into()],
|
cols: vec!["a".into()],
|
||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["c".into()],
|
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(),
|
||||||
}],
|
}],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl Command for Select {
|
||||||
|
|
||||||
fn select(
|
fn select(
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
span: Span,
|
call_span: Span,
|
||||||
columns: Vec<CellPath>,
|
columns: Vec<CellPath>,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
ignore_errors: bool,
|
ignore_errors: bool,
|
||||||
|
@ -102,7 +102,7 @@ fn select(
|
||||||
Some(PathMember::Int { val, span }) => {
|
Some(PathMember::Int { val, span }) => {
|
||||||
if members.len() > 1 {
|
if members.len() > 1 {
|
||||||
if ignore_errors {
|
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(
|
return Err(ShellError::GenericError(
|
||||||
"Select only allows row numbers for rows".into(),
|
"Select only allows row numbers for rows".into(),
|
||||||
|
@ -166,9 +166,7 @@ fn select(
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if ignore_errors {
|
if ignore_errors {
|
||||||
return Ok(
|
return Ok(Value::nothing(call_span).into_pipeline_data());
|
||||||
Value::nothing(Span::test_data()).into_pipeline_data()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
@ -202,15 +200,17 @@ fn select(
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if ignore_errors {
|
if ignore_errors {
|
||||||
return Ok(
|
return Ok(Value::nothing(call_span).into_pipeline_data());
|
||||||
Value::nothing(Span::test_data()).into_pipeline_data()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
values.push(Value::Record { cols, vals, span });
|
values.push(Value::Record {
|
||||||
|
cols,
|
||||||
|
vals,
|
||||||
|
span: call_span,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
values.push(x);
|
values.push(x);
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ fn select(
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if ignore_errors {
|
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);
|
return Err(e);
|
||||||
|
@ -242,9 +242,13 @@ fn select(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Record { cols, vals, span }
|
Ok(Value::Record {
|
||||||
.into_pipeline_data()
|
cols,
|
||||||
.set_metadata(metadata))
|
vals,
|
||||||
|
span: call_span,
|
||||||
|
}
|
||||||
|
.into_pipeline_data()
|
||||||
|
.set_metadata(metadata))
|
||||||
} else {
|
} else {
|
||||||
Ok(v.into_pipeline_data().set_metadata(metadata))
|
Ok(v.into_pipeline_data().set_metadata(metadata))
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,66 +42,41 @@ impl Command for Window {
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let stream_test_1 = vec![
|
let stream_test_1 = vec![
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(2), Value::test_int(3)],
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
Value::int(3, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(3), Value::test_int(4)],
|
||||||
Value::int(3, Span::test_data()),
|
|
||||||
Value::int(4, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let stream_test_2 = vec![
|
let stream_test_2 = vec![
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(4), Value::test_int(5)],
|
||||||
Value::int(4, Span::test_data()),
|
|
||||||
Value::int(5, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(7), Value::test_int(8)],
|
||||||
Value::int(7, Span::test_data()),
|
|
||||||
Value::int(8, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let stream_test_3 = vec![
|
let stream_test_3 = vec![
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
Value::int(3, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(4), Value::test_int(5)],
|
||||||
Value::int(4, Span::test_data()),
|
|
||||||
Value::int(5, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -36,26 +36,17 @@ impl Command for Zip {
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let test_row_1 = Value::List {
|
let test_row_1 = Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(4)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(4, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let test_row_2 = Value::List {
|
let test_row_2 = Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(2), Value::test_int(5)],
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
Value::int(5, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let test_row_3 = Value::List {
|
let test_row_3 = Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(3), Value::test_int(6)],
|
||||||
Value::int(3, Span::test_data()),
|
|
||||||
Value::int(6, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl Command for FromJson {
|
||||||
description: "Converts json formatted string to table",
|
description: "Converts json formatted string to table",
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["a".to_string()],
|
cols: vec!["a".to_string()],
|
||||||
vals: vec![Value::int(1, Span::test_data())],
|
vals: vec![Value::test_int(1)],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -41,12 +41,9 @@ impl Command for FromJson {
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["a".to_string(), "b".to_string()],
|
cols: vec!["a".to_string(), "b".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::test_int(1),
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl Command for FromNuon {
|
||||||
description: "Converts nuon formatted string to table",
|
description: "Converts nuon formatted string to table",
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["a".to_string()],
|
cols: vec!["a".to_string()],
|
||||||
vals: vec![Value::int(1, Span::test_data())],
|
vals: vec![Value::test_int(1)],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -39,12 +39,9 @@ impl Command for FromNuon {
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["a".to_string(), "b".to_string()],
|
cols: vec!["a".to_string(), "b".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::test_int(1),
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl Command for FromToml {
|
||||||
description: "Converts toml formatted string to record",
|
description: "Converts toml formatted string to record",
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["a".to_string()],
|
cols: vec!["a".to_string()],
|
||||||
vals: vec![Value::int(1, Span::test_data())],
|
vals: vec![Value::test_int(1)],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -40,12 +40,9 @@ b = [1, 2]' | from toml",
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["a".to_string(), "b".to_string()],
|
cols: vec!["a".to_string(), "b".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::test_int(1),
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||||
Value::int(1, Span::test_data()),
|
|
||||||
Value::int(2, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -200,7 +200,7 @@ mod tests {
|
||||||
use nu_protocol::{Spanned, Value};
|
use nu_protocol::{Spanned, Value};
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
Value::string(input, Span::test_data())
|
Value::test_string(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
|
|
|
@ -203,7 +203,7 @@ pub fn get_examples() -> Vec<Example> {
|
||||||
description: "Converts yaml formatted string to table",
|
description: "Converts yaml formatted string to table",
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Record {
|
||||||
cols: vec!["a".to_string()],
|
cols: vec!["a".to_string()],
|
||||||
vals: vec![Value::int(1, Span::test_data())],
|
vals: vec![Value::test_int(1)],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,8 +59,6 @@ impl Command for SeqDate {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let span = Span::test_data();
|
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "print the next 10 days in YYYY-MM-DD format with newline separator",
|
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'",
|
example: "seq date -b '2020-01-01' -e '2020-01-10'",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::String { val: "2020-01-01".into(), span, },
|
Value::test_string("2020-01-01"),
|
||||||
Value::String { val: "2020-01-02".into(), span, },
|
Value::test_string("2020-01-02"),
|
||||||
Value::String { val: "2020-01-03".into(), span, },
|
Value::test_string("2020-01-03"),
|
||||||
Value::String { val: "2020-01-04".into(), span, },
|
Value::test_string("2020-01-04"),
|
||||||
Value::String { val: "2020-01-05".into(), span, },
|
Value::test_string("2020-01-05"),
|
||||||
Value::String { val: "2020-01-06".into(), span, },
|
Value::test_string("2020-01-06"),
|
||||||
Value::String { val: "2020-01-07".into(), span, },
|
Value::test_string("2020-01-07"),
|
||||||
Value::String { val: "2020-01-08".into(), span, },
|
Value::test_string("2020-01-08"),
|
||||||
Value::String { val: "2020-01-09".into(), span, },
|
Value::test_string("2020-01-09"),
|
||||||
Value::String { val: "2020-01-10".into(), span, },
|
Value::test_string("2020-01-10"),
|
||||||
],
|
],
|
||||||
span,
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
|
@ -101,15 +99,15 @@ impl Command for SeqDate {
|
||||||
example: "seq date -b '2020-01-01' -e '2020-01-31' -n 5",
|
example: "seq date -b '2020-01-01' -e '2020-01-31' -n 5",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::String { val: "2020-01-01".into(), span, },
|
Value::test_string("2020-01-01"),
|
||||||
Value::String { val: "2020-01-06".into(), span, },
|
Value::test_string("2020-01-06"),
|
||||||
Value::String { val: "2020-01-11".into(), span, },
|
Value::test_string("2020-01-11"),
|
||||||
Value::String { val: "2020-01-16".into(), span, },
|
Value::test_string("2020-01-16"),
|
||||||
Value::String { val: "2020-01-21".into(), span, },
|
Value::test_string("2020-01-21"),
|
||||||
Value::String { val: "2020-01-26".into(), span, },
|
Value::test_string("2020-01-26"),
|
||||||
Value::String { val: "2020-01-31".into(), span, },
|
Value::test_string("2020-01-31"),
|
||||||
],
|
],
|
||||||
span,
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -155,7 +153,7 @@ impl Command for SeqDate {
|
||||||
|
|
||||||
let inc = match increment {
|
let inc = match increment {
|
||||||
Some(i) => Value::int(i.item, i.span),
|
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));
|
let day_count = days.map(|i| Value::int(i.item, i.span));
|
||||||
|
@ -165,10 +163,10 @@ impl Command for SeqDate {
|
||||||
rev = reverse;
|
rev = reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(
|
Ok(run_seq_dates(
|
||||||
run_seq_dates(outformat, informat, begin, end, inc, day_count, rev)?
|
outformat, informat, begin, end, inc, day_count, rev, call.head,
|
||||||
.into_pipeline_data(),
|
)?
|
||||||
)
|
.into_pipeline_data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +187,7 @@ pub fn run_seq_dates(
|
||||||
increment: Value,
|
increment: Value,
|
||||||
day_count: Option<Value>,
|
day_count: Option<Value>,
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
|
call_span: Span,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let today = Local::now().date_naive();
|
let today = Local::now().date_naive();
|
||||||
// if cannot convert , it will return error
|
// if cannot convert , it will return error
|
||||||
|
@ -243,7 +242,7 @@ pub fn run_seq_dates(
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
"Failed to parse date".to_string(),
|
"Failed to parse date".to_string(),
|
||||||
Some(Span::test_data()),
|
Some(call_span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
))
|
))
|
||||||
|
@ -259,7 +258,7 @@ pub fn run_seq_dates(
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
"Failed to parse date".to_string(),
|
"Failed to parse date".to_string(),
|
||||||
Some(Span::test_data()),
|
Some(call_span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
))
|
))
|
||||||
|
@ -286,7 +285,7 @@ pub fn run_seq_dates(
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
"integer value too large".to_string(),
|
"integer value too large".to_string(),
|
||||||
"integer value too large".to_string(),
|
"integer value too large".to_string(),
|
||||||
Some(Span::test_data()),
|
Some(call_span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
));
|
));
|
||||||
|
@ -308,7 +307,7 @@ pub fn run_seq_dates(
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
"date is out of range".to_string(),
|
"date is out of range".to_string(),
|
||||||
"date is out of range".to_string(),
|
"date is out of range".to_string(),
|
||||||
Some(Span::test_data()),
|
Some(call_span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
));
|
));
|
||||||
|
@ -317,7 +316,7 @@ pub fn run_seq_dates(
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
loop {
|
loop {
|
||||||
let date_string = &next.format(&out_format).to_string();
|
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);
|
next += Duration::days(step_size);
|
||||||
|
|
||||||
if is_out_of_range(next) {
|
if is_out_of_range(next) {
|
||||||
|
@ -327,7 +326,7 @@ pub fn run_seq_dates(
|
||||||
|
|
||||||
Ok(Value::List {
|
Ok(Value::List {
|
||||||
vals: ret,
|
vals: ret,
|
||||||
span: Span::test_data(),
|
span: call_span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl Command for SubCommand {
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_int(50),
|
Value::test_int(50),
|
||||||
Value::float(100.0, Span::test_data()),
|
Value::test_float(100.0),
|
||||||
Value::test_int(25),
|
Value::test_int(25),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl Command for SubCommand {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Compute the average of a list of numbers",
|
description: "Compute the average of a list of numbers",
|
||||||
example: "[-50 100.0 25] | math avg",
|
example: "[-50 100.0 25] | math avg",
|
||||||
result: Some(Value::float(25.0, Span::test_data())),
|
result: Some(Value::test_float(25.0)),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl Command for SubCommand {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Evaluate math in the pipeline",
|
description: "Evaluate math in the pipeline",
|
||||||
example: "'10 / 4' | math eval",
|
example: "'10 / 4' | math eval",
|
||||||
result: Some(Value::float(2.5, Span::test_data())),
|
result: Some(Value::test_float(2.5)),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Compute the median of a list of numbers",
|
description: "Compute the median of a list of numbers",
|
||||||
example: "[3 8 9 12 12 15] | math median",
|
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 {
|
Example {
|
||||||
description: "Compute the medians of the columns of a table",
|
description: "Compute the medians of the columns of a table",
|
||||||
|
|
|
@ -68,9 +68,9 @@ impl Command for SubCommand {
|
||||||
example: "[1.555 2.333 -3.111] | math round -p 2",
|
example: "[1.555 2.333 -3.111] | math round -p 2",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::float(1.56, Span::test_data()),
|
Value::test_float(1.56),
|
||||||
Value::float(2.33, Span::test_data()),
|
Value::test_float(2.33),
|
||||||
Value::float(-3.11, Span::test_data()),
|
Value::test_float(-3.11),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -54,12 +54,12 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Compute the standard deviation of a list of numbers",
|
description: "Compute the standard deviation of a list of numbers",
|
||||||
example: "[1 2 3 4 5] | math stddev",
|
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 {
|
Example {
|
||||||
description: "Compute the sample standard deviation of a list of numbers",
|
description: "Compute the sample standard deviation of a list of numbers",
|
||||||
example: "[1 2 3 4 5] | math stddev -s",
|
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)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,12 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Get the variance of a list of numbers",
|
description: "Get the variance of a list of numbers",
|
||||||
example: "[1 2 3 4 5] | math variance",
|
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 {
|
Example {
|
||||||
description: "Get the sample variance of a list of numbers",
|
description: "Get the sample variance of a list of numbers",
|
||||||
example: "[1 2 3 4 5] | math variance -s",
|
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)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use nu_protocol::IntoPipelineData;
|
||||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpListener};
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpListener};
|
||||||
|
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -51,7 +51,7 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "get a free port between 3121 and 4000",
|
description: "get a free port between 3121 and 4000",
|
||||||
example: "port 3121 4000",
|
example: "port 3121 4000",
|
||||||
result: Some(Value::int(3121, Span::test_data())),
|
result: Some(Value::test_int(3121)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "get a free port from system",
|
description: "get a free port from system",
|
||||||
|
|
|
@ -75,7 +75,7 @@ If you need to distinguish dirs and files, please use `path type`."#
|
||||||
Example {
|
Example {
|
||||||
description: "Check if a file exists",
|
description: "Check if a file exists",
|
||||||
example: "'C:\\Users\\joe\\todo.txt' | path exists",
|
example: "'C:\\Users\\joe\\todo.txt' | path exists",
|
||||||
result: Some(Value::boolean(false, Span::test_data())),
|
result: Some(Value::test_bool(false)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check if a file exists in a column",
|
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 {
|
Example {
|
||||||
description: "Check if a file exists",
|
description: "Check if a file exists",
|
||||||
example: "'/home/joe/todo.txt' | path exists",
|
example: "'/home/joe/todo.txt' | path exists",
|
||||||
result: Some(Value::boolean(false, Span::test_data())),
|
result: Some(Value::test_bool(false)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check if a file exists in a column",
|
description: "Check if a file exists in a column",
|
||||||
|
|
|
@ -255,13 +255,13 @@ impl From<FileInfo> for Value {
|
||||||
});
|
});
|
||||||
|
|
||||||
cols.push("directories".into());
|
cols.push("directories".into());
|
||||||
vals.push(Value::nothing(Span::test_data()));
|
vals.push(Value::nothing(Span::unknown()));
|
||||||
|
|
||||||
cols.push("files".into());
|
cols.push("files".into());
|
||||||
vals.push(Value::nothing(Span::test_data()));
|
vals.push(Value::nothing(Span::unknown()));
|
||||||
|
|
||||||
// cols.push("errors".into());
|
// cols.push("errors".into());
|
||||||
// vals.push(Value::nothing(Span::test_data()));
|
// vals.push(Value::nothing(Span::unknown()));
|
||||||
|
|
||||||
Value::Record {
|
Value::Record {
|
||||||
cols,
|
cols,
|
||||||
|
|
|
@ -93,7 +93,7 @@ pub fn print_events(engine_state: &EngineState) -> Result<Value, ShellError> {
|
||||||
}
|
}
|
||||||
terminal::disable_raw_mode()?;
|
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
|
// this fn is totally ripped off from crossterm's examples
|
||||||
|
@ -113,12 +113,12 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
|
||||||
"flags".into(),
|
"flags".into(),
|
||||||
],
|
],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::string(format!("{}", c), Span::test_data()),
|
Value::string(format!("{}", c), Span::unknown()),
|
||||||
Value::string(format!("{:#08x}", u32::from(c)), Span::test_data()),
|
Value::string(format!("{:#08x}", u32::from(c)), Span::unknown()),
|
||||||
Value::string(format!("{:?}", modifiers), Span::test_data()),
|
Value::string(format!("{:?}", modifiers), Span::unknown()),
|
||||||
Value::string(format!("{:#08b}", modifiers), Span::test_data()),
|
Value::string(format!("{:#08b}", modifiers), Span::unknown()),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::unknown(),
|
||||||
};
|
};
|
||||||
Ok(record)
|
Ok(record)
|
||||||
}
|
}
|
||||||
|
@ -126,11 +126,11 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
|
||||||
let record = Value::Record {
|
let record = Value::Record {
|
||||||
cols: vec!["code".into(), "modifier".into(), "flags".into()],
|
cols: vec!["code".into(), "modifier".into(), "flags".into()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::string(format!("{:?}", code), Span::test_data()),
|
Value::string(format!("{:?}", code), Span::unknown()),
|
||||||
Value::string(format!("{:?}", modifiers), Span::test_data()),
|
Value::string(format!("{:?}", modifiers), Span::unknown()),
|
||||||
Value::string(format!("{:#08b}", modifiers), Span::test_data()),
|
Value::string(format!("{:#08b}", modifiers), Span::unknown()),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::unknown(),
|
||||||
};
|
};
|
||||||
Ok(record)
|
Ok(record)
|
||||||
}
|
}
|
||||||
|
@ -138,8 +138,8 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
|
||||||
} else {
|
} else {
|
||||||
let record = Value::Record {
|
let record = Value::Record {
|
||||||
cols: vec!["event".into()],
|
cols: vec!["event".into()],
|
||||||
vals: vec![Value::string(format!("{:?}", event), Span::test_data())],
|
vals: vec![Value::string(format!("{:?}", event), Span::unknown())],
|
||||||
span: Span::test_data(),
|
span: Span::unknown(),
|
||||||
};
|
};
|
||||||
Ok(record)
|
Ok(record)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Type, Value};
|
||||||
Category, Example, IntoPipelineData, PipelineData, Signature, Span, Type, Value,
|
|
||||||
};
|
|
||||||
use terminal_size::{terminal_size, Height, Width};
|
use terminal_size::{terminal_size, Height, Width};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -66,8 +64,8 @@ impl Command for TermSize {
|
||||||
Ok(Value::Record {
|
Ok(Value::Record {
|
||||||
cols: vec!["columns".into(), "rows".into()],
|
cols: vec!["columns".into(), "rows".into()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::int(cols.0 as i64, Span::test_data()),
|
Value::int(cols.0 as i64, head),
|
||||||
Value::int(rows.0 as i64, Span::test_data()),
|
Value::int(rows.0 as i64, head),
|
||||||
],
|
],
|
||||||
span: head,
|
span: head,
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ pub fn sort(
|
||||||
for col in &sort_columns {
|
for col in &sort_columns {
|
||||||
let val = match item.get_data_by_key(col) {
|
let val = match item.get_data_by_key(col) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => Value::nothing(Span::test_data()),
|
None => Value::nothing(Span::unknown()),
|
||||||
};
|
};
|
||||||
vals.push(val);
|
vals.push(val);
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_decode_binhex() {
|
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 expected = Value::binary(b"a binhex test".as_slice(), Span::test_data());
|
||||||
|
|
||||||
let actual = action(
|
let actual = action(
|
||||||
|
@ -272,7 +272,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_decode_binhex_with_new_line_input() {
|
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 expected = Value::binary(b"a binhex test".as_slice(), Span::test_data());
|
||||||
|
|
||||||
let actual = action(
|
let actual = action(
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::base64::{operate, ActionType, CHARACTER_SET_DESC};
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -54,7 +54,7 @@ impl Command for EncodeBase64 {
|
||||||
Example {
|
Example {
|
||||||
description: "Encode a string with the binhex character set",
|
description: "Encode a string with the binhex character set",
|
||||||
example: "'Some Data' | encode base64 --character-set binhex",
|
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"#)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ impl Command for Size {
|
||||||
"graphemes".into(),
|
"graphemes".into(),
|
||||||
],
|
],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::test_int(1),
|
||||||
Value::int(7, Span::test_data()),
|
Value::test_int(7),
|
||||||
Value::int(38, Span::test_data()),
|
Value::test_int(38),
|
||||||
Value::int(38, Span::test_data()),
|
Value::test_int(38),
|
||||||
Value::int(38, Span::test_data()),
|
Value::test_int(38),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
|
@ -76,11 +76,11 @@ impl Command for Size {
|
||||||
"graphemes".into(),
|
"graphemes".into(),
|
||||||
],
|
],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::test_int(1),
|
||||||
Value::int(6, Span::test_data()),
|
Value::test_int(6),
|
||||||
Value::int(18, Span::test_data()),
|
Value::test_int(18),
|
||||||
Value::int(6, Span::test_data()),
|
Value::test_int(6),
|
||||||
Value::int(6, Span::test_data()),
|
Value::test_int(6),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
|
@ -97,11 +97,11 @@ impl Command for Size {
|
||||||
"graphemes".into(),
|
"graphemes".into(),
|
||||||
],
|
],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::test_int(1),
|
||||||
Value::int(2, Span::test_data()),
|
Value::test_int(2),
|
||||||
Value::int(15, Span::test_data()),
|
Value::test_int(15),
|
||||||
Value::int(14, Span::test_data()),
|
Value::test_int(14),
|
||||||
Value::int(13, Span::test_data()),
|
Value::test_int(13),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -73,12 +73,12 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Check if input contains string",
|
description: "Check if input contains string",
|
||||||
example: "'my_library.rb' | str contains '.rb'",
|
example: "'my_library.rb' | str contains '.rb'",
|
||||||
result: Some(Value::boolean(true, Span::test_data())),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check if input contains string case insensitive",
|
description: "Check if input contains string case insensitive",
|
||||||
example: "'my_library.rb' | str contains -i '.RB'",
|
example: "'my_library.rb' | str contains -i '.RB'",
|
||||||
result: Some(Value::boolean(true, Span::test_data())),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check if input contains string in a table",
|
description: "Check if input contains string in a table",
|
||||||
|
@ -86,10 +86,7 @@ impl Command for SubCommand {
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
||||||
vals: vec![
|
vals: vec![Value::test_bool(true), Value::test_int(100)],
|
||||||
Value::boolean(true, Span::test_data()),
|
|
||||||
Value::test_int(100),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -101,10 +98,7 @@ impl Command for SubCommand {
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
||||||
vals: vec![
|
vals: vec![Value::test_bool(true), Value::test_int(100)],
|
||||||
Value::boolean(true, Span::test_data()),
|
|
||||||
Value::test_int(100),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -116,10 +110,7 @@ impl Command for SubCommand {
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
cols: vec!["ColA".to_string(), "ColB".to_string()],
|
||||||
vals: vec![
|
vals: vec![Value::test_bool(true), Value::test_bool(true)],
|
||||||
Value::boolean(true, Span::test_data()),
|
|
||||||
Value::boolean(true, Span::test_data()),
|
|
||||||
],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -128,16 +119,16 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Check if input string contains 'banana'",
|
description: "Check if input string contains 'banana'",
|
||||||
example: "'hello' | str contains 'banana'",
|
example: "'hello' | str contains 'banana'",
|
||||||
result: Some(Value::boolean(false, Span::test_data())),
|
result: Some(Value::test_bool(false)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check if list contains string",
|
description: "Check if list contains string",
|
||||||
example: "[one two three] | str contains o",
|
example: "[one two three] | str contains o",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::boolean(true, Span::test_data()),
|
Value::test_bool(true),
|
||||||
Value::boolean(true, Span::test_data()),
|
Value::test_bool(true),
|
||||||
Value::boolean(false, Span::test_data()),
|
Value::test_bool(false),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
|
@ -147,9 +138,9 @@ impl Command for SubCommand {
|
||||||
example: "[one two three] | str contains -n o",
|
example: "[one two three] | str contains -n o",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::boolean(false, Span::test_data()),
|
Value::test_bool(false),
|
||||||
Value::boolean(false, Span::test_data()),
|
Value::test_bool(false),
|
||||||
Value::boolean(true, Span::test_data()),
|
Value::test_bool(true),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -67,12 +67,12 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Checks if string ends with '.rb'",
|
description: "Checks if string ends with '.rb'",
|
||||||
example: "'my_library.rb' | str 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 {
|
Example {
|
||||||
description: "Checks if string ends with '.txt'",
|
description: "Checks if string ends with '.txt'",
|
||||||
example: "'my_library.rb' | str 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)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,17 +70,17 @@ impl Command for SubCommand {
|
||||||
Example {
|
Example {
|
||||||
description: "Checks if input string starts with 'my'",
|
description: "Checks if input string starts with 'my'",
|
||||||
example: "'my_library.rb' | str 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 {
|
Example {
|
||||||
description: "Checks if input string starts with 'my'",
|
description: "Checks if input string starts with 'my'",
|
||||||
example: "'Cargo.toml' | str starts-with 'Car'",
|
example: "'Cargo.toml' | str starts-with 'Car'",
|
||||||
result: Some(Value::boolean(true, Span::test_data())),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Checks if input string starts with 'my'",
|
description: "Checks if input string starts with 'my'",
|
||||||
example: "'Cargo.toml' | str starts-with '.toml'",
|
example: "'Cargo.toml' | str starts-with '.toml'",
|
||||||
result: Some(Value::boolean(false, Span::test_data())),
|
result: Some(Value::test_bool(false)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,7 +333,7 @@ mod tests {
|
||||||
Span::test_data(),
|
Span::test_data(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual, Value::string(expected, Span::test_data()));
|
assert_eq!(actual, Value::test_string(expected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,7 +302,7 @@ mod tests {
|
||||||
cols: cols.iter().map(|x| x.to_string()).collect(),
|
cols: cols.iter().map(|x| x.to_string()).collect(),
|
||||||
vals: vals
|
vals: vals
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| Value::string(x.to_string(), Span::test_data()))
|
.map(|x| Value::test_string(x.to_string()))
|
||||||
.collect(),
|
.collect(),
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ mod tests {
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vals
|
vals: vals
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| Value::string(x.to_string(), Span::test_data()))
|
.map(|x| Value::test_string(x.to_string()))
|
||||||
.collect(),
|
.collect(),
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ mod tests {
|
||||||
let row = Value::List {
|
let row = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string(" nu shell "),
|
Value::test_string(" nu shell "),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string(" d"),
|
Value::test_string(" d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -485,7 +485,7 @@ mod tests {
|
||||||
let expected = Value::List {
|
let expected = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string("nushell"),
|
Value::test_string("nushell"),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string("d"),
|
Value::test_string("d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -549,7 +549,7 @@ mod tests {
|
||||||
let row = Value::List {
|
let row = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string("##nu####shell##"),
|
Value::test_string("##nu####shell##"),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string("#d"),
|
Value::test_string("#d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -557,7 +557,7 @@ mod tests {
|
||||||
let expected = Value::List {
|
let expected = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string("nushell"),
|
Value::test_string("nushell"),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string("d"),
|
Value::test_string("d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -659,7 +659,7 @@ mod tests {
|
||||||
let row = Value::List {
|
let row = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string(" a "),
|
Value::test_string(" a "),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string(" d"),
|
Value::test_string(" d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -667,7 +667,7 @@ mod tests {
|
||||||
let expected = Value::List {
|
let expected = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string("a "),
|
Value::test_string("a "),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string("d"),
|
Value::test_string("d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -784,7 +784,7 @@ mod tests {
|
||||||
let row = Value::List {
|
let row = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string(" a "),
|
Value::test_string(" a "),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string(" d"),
|
Value::test_string(" d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -792,7 +792,7 @@ mod tests {
|
||||||
let expected = Value::List {
|
let expected = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string(" a"),
|
Value::test_string(" a"),
|
||||||
Value::int(65, Span::test_data()),
|
Value::test_int(65),
|
||||||
Value::test_string(" d"),
|
Value::test_string(" d"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -911,7 +911,7 @@ mod tests {
|
||||||
let row = Value::List {
|
let row = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string(" a b c d "),
|
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"),
|
Value::test_string(" b c d e f"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -919,7 +919,7 @@ mod tests {
|
||||||
let expected = Value::List {
|
let expected = Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::test_string("a b c d"),
|
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"),
|
Value::test_string("b c d e f"),
|
||||||
],
|
],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
|
|
@ -94,6 +94,8 @@ fn registry_query(
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
|
let call_span = call.head;
|
||||||
|
|
||||||
let registry_key: Spanned<String> = call.req(engine_state, stack, 0)?;
|
let registry_key: Spanned<String> = call.req(engine_state, stack, 0)?;
|
||||||
let registry_key_span = ®istry_key.clone().span;
|
let registry_key_span = ®istry_key.clone().span;
|
||||||
let registry_value: Option<Spanned<String>> = call.opt(engine_state, stack, 1)?;
|
let registry_value: Option<Spanned<String>> = call.opt(engine_state, stack, 1)?;
|
||||||
|
@ -112,18 +114,18 @@ fn registry_query(
|
||||||
key: registry_key.item,
|
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() {
|
if registry_value.is_none() {
|
||||||
let mut reg_values = vec![];
|
let mut reg_values = vec![];
|
||||||
for (name, val) in reg_key.enum_values().flatten() {
|
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 {
|
reg_values.push(Value::Record {
|
||||||
cols: vec!["name".to_string(), "value".to_string(), "type".to_string()],
|
cols: vec!["name".to_string(), "value".to_string(), "type".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::string(name, Span::test_data()),
|
Value::string(name, call_span),
|
||||||
nu_value,
|
nu_value,
|
||||||
Value::string(format!("{:?}", reg_type), Span::test_data()),
|
Value::string(format!("{:?}", reg_type), call_span),
|
||||||
],
|
],
|
||||||
span: *registry_key_span,
|
span: *registry_key_span,
|
||||||
})
|
})
|
||||||
|
@ -135,13 +137,13 @@ fn registry_query(
|
||||||
let reg_value = reg_key.get_raw_value(value.item.as_str());
|
let reg_value = reg_key.get_raw_value(value.item.as_str());
|
||||||
match reg_value {
|
match reg_value {
|
||||||
Ok(val) => {
|
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 {
|
Ok(Value::Record {
|
||||||
cols: vec!["name".to_string(), "value".to_string(), "type".to_string()],
|
cols: vec!["name".to_string(), "value".to_string(), "type".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::string(value.item, Span::test_data()),
|
Value::string(value.item, call_span),
|
||||||
nu_value,
|
nu_value,
|
||||||
Value::string(format!("{:?}", reg_type), Span::test_data()),
|
Value::string(format!("{:?}", reg_type), call_span),
|
||||||
],
|
],
|
||||||
span: value.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<RegKey, ShellError> {
|
fn get_reg_key(reg_params: RegistryQueryArgs, call_span: Span) -> Result<RegKey, ShellError> {
|
||||||
let mut key_count = 0;
|
let mut key_count = 0;
|
||||||
let registry_key = if reg_params.hkcr {
|
let registry_key = if reg_params.hkcr {
|
||||||
key_count += 1;
|
key_count += 1;
|
||||||
|
@ -201,7 +203,7 @@ fn get_reg_key(reg_params: RegistryQueryArgs) -> Result<RegKey, ShellError> {
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
"Only one registry key can be specified".into(),
|
"Only one registry key can be specified".into(),
|
||||||
"Only one registry key can be specified".into(),
|
"Only one registry key can be specified".into(),
|
||||||
Some(Span::test_data()),
|
Some(call_span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
));
|
));
|
||||||
|
@ -211,59 +213,57 @@ fn get_reg_key(reg_params: RegistryQueryArgs) -> Result<RegKey, ShellError> {
|
||||||
|
|
||||||
fn reg_value_to_nu_value(
|
fn reg_value_to_nu_value(
|
||||||
reg_value: winreg::RegValue,
|
reg_value: winreg::RegValue,
|
||||||
|
call_span: Span,
|
||||||
) -> (nu_protocol::Value, winreg::enums::RegType) {
|
) -> (nu_protocol::Value, winreg::enums::RegType) {
|
||||||
match reg_value.vtype {
|
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 => (
|
REG_SZ => (
|
||||||
Value::string(reg_value.to_string(), Span::test_data()),
|
Value::string(reg_value.to_string(), call_span),
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
REG_EXPAND_SZ => (
|
REG_EXPAND_SZ => (
|
||||||
Value::string(reg_value.to_string(), Span::test_data()),
|
Value::string(reg_value.to_string(), call_span),
|
||||||
reg_value.vtype,
|
|
||||||
),
|
|
||||||
REG_BINARY => (
|
|
||||||
Value::binary(reg_value.bytes, Span::test_data()),
|
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
|
REG_BINARY => (Value::binary(reg_value.bytes, call_span), reg_value.vtype),
|
||||||
REG_DWORD => (
|
REG_DWORD => (
|
||||||
Value::int(
|
Value::int(
|
||||||
unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64,
|
unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64,
|
||||||
Span::test_data(),
|
call_span,
|
||||||
),
|
),
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
REG_DWORD_BIG_ENDIAN => (
|
REG_DWORD_BIG_ENDIAN => (
|
||||||
Value::int(
|
Value::int(
|
||||||
unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64,
|
unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64,
|
||||||
Span::test_data(),
|
call_span,
|
||||||
),
|
),
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
REG_LINK => (
|
REG_LINK => (
|
||||||
Value::string(reg_value.to_string(), Span::test_data()),
|
Value::string(reg_value.to_string(), call_span),
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
REG_MULTI_SZ => (
|
REG_MULTI_SZ => (
|
||||||
Value::string(reg_value.to_string(), Span::test_data()),
|
Value::string(reg_value.to_string(), call_span),
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
REG_RESOURCE_LIST => (
|
REG_RESOURCE_LIST => (
|
||||||
Value::string(reg_value.to_string(), Span::test_data()),
|
Value::string(reg_value.to_string(), call_span),
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
REG_FULL_RESOURCE_DESCRIPTOR => (
|
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_value.vtype,
|
||||||
),
|
),
|
||||||
REG_RESOURCE_REQUIREMENTS_LIST => (
|
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_value.vtype,
|
||||||
),
|
),
|
||||||
REG_QWORD => (
|
REG_QWORD => (
|
||||||
Value::int(
|
Value::int(
|
||||||
unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64,
|
unsafe { *(reg_value.bytes.as_ptr() as *const u32) } as i64,
|
||||||
Span::test_data(),
|
call_span,
|
||||||
),
|
),
|
||||||
reg_value.vtype,
|
reg_value.vtype,
|
||||||
),
|
),
|
||||||
|
|
|
@ -410,7 +410,7 @@ fn ensure_path(scope: &mut HashMap<String, Value>, env_path_name: &str) -> Optio
|
||||||
Ok(sp) => sp,
|
Ok(sp) => sp,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error = error.or(Some(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?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ use nu_protocol::{Span, Value};
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comparison_nothing() {
|
fn test_comparison_nothing() {
|
||||||
let values = vec![
|
let values = vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::test_int(1),
|
||||||
Value::test_string("string"),
|
Value::test_string("string"),
|
||||||
Value::float(1.0, Span::test_data()),
|
Value::test_float(1.0),
|
||||||
];
|
];
|
||||||
|
|
||||||
let nothing = Value::Nothing {
|
let nothing = Value::Nothing {
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn execute_json_query(
|
||||||
|
|
||||||
if query_contains_modifiers(query_string) {
|
if query_contains_modifiers(query_string) {
|
||||||
let json_str = val.json();
|
let json_str = val.json();
|
||||||
Ok(Value::string(json_str, Span::test_data()))
|
Ok(Value::string(json_str, call.head))
|
||||||
} else {
|
} else {
|
||||||
Ok(convert_gjson_value_to_nu_value(&val, &call.head))
|
Ok(convert_gjson_value_to_nu_value(&val, &call.head))
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl Selector {
|
||||||
query: String::new(),
|
query: String::new(),
|
||||||
as_html: false,
|
as_html: false,
|
||||||
attribute: String::new(),
|
attribute: String::new(),
|
||||||
as_table: Value::string("".to_string(), Span::test_data()),
|
as_table: Value::string("".to_string(), Span::unknown()),
|
||||||
inspect: false,
|
inspect: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,20 +61,20 @@ pub fn execute_xpath_query(
|
||||||
sxd_xpath::Value::Nodeset(ns) => {
|
sxd_xpath::Value::Nodeset(ns) => {
|
||||||
for n in ns.into_iter() {
|
for n in ns.into_iter() {
|
||||||
cols.push(key.to_string());
|
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) => {
|
sxd_xpath::Value::Boolean(b) => {
|
||||||
cols.push(key.to_string());
|
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) => {
|
sxd_xpath::Value::Number(n) => {
|
||||||
cols.push(key.to_string());
|
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) => {
|
sxd_xpath::Value::String(s) => {
|
||||||
cols.push(key.to_string());
|
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 {
|
records.push(Value::Record {
|
||||||
cols: vec![k.to_string()],
|
cols: vec![k.to_string()],
|
||||||
vals: vec![v.clone()],
|
vals: vec![v.clone()],
|
||||||
span: Span::test_data(),
|
span: call.head,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::List {
|
Ok(Value::List {
|
||||||
vals: records,
|
vals: records,
|
||||||
span: Span::test_data(),
|
span: call.head,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(_) => Err(LabeledError {
|
Err(_) => Err(LabeledError {
|
||||||
label: "xpath query error".to_string(),
|
label: "xpath query error".to_string(),
|
||||||
msg: "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 {
|
let expected = Value::List {
|
||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["count(//a/*[posit...".to_string()],
|
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(),
|
||||||
}],
|
}],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -177,7 +177,7 @@ mod tests {
|
||||||
let expected = Value::List {
|
let expected = Value::List {
|
||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["count(//*[contain...".to_string()],
|
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(),
|
||||||
}],
|
}],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
|
|
@ -5,7 +5,7 @@ use nu_command::create_default_context;
|
||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
use nu_parser::parse;
|
use nu_parser::parse;
|
||||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
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;
|
// use nu_test_support::fs::in_directory;
|
||||||
|
|
||||||
/// Echo's value of env keys from args
|
/// 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 engine_state = create_default_context();
|
||||||
let mut stack = Stack::new();
|
let mut stack = Stack::new();
|
||||||
|
|
||||||
stack.add_env_var(
|
stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy()));
|
||||||
"PWD".to_string(),
|
|
||||||
Value::string(cwd.to_string_lossy(), Span::test_data()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut last_output = String::new();
|
let mut last_output = String::new();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue