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:
Stefan Holderbach
2022-12-24 14:41:57 +01:00
committed by GitHub
parent dd6fe6a04a
commit 45fe3be83e
59 changed files with 236 additions and 310 deletions

View File

@ -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(),
},
],

View File

@ -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(),
},
],

View File

@ -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(),
},
],

View File

@ -200,7 +200,7 @@ mod tests {
use nu_protocol::{Spanned, 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 {

View File

@ -203,7 +203,7 @@ pub fn get_examples() -> Vec<Example> {
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(),
}),
},