forked from extern/nushell
Convert more examples and tests to record!
macro (#10840)
# Description Use `record!` macro instead of defining two separate `vec!` for `cols` and `vals` when appropriate. This visually aligns the key with the value. Further more you don't have to deal with the construction of `Record { cols, vals }` so we can hide the implementation details in the future. ## State Not covering all possible commands yet, also some tests/examples are better expressed by creating cols and vals separately. # User/Developer-Facing Changes The examples and tests should read more natural. No relevant functional change # Bycatch Where I noticed it I replaced usage of `Value` constructors with `Span::test_data()` or `Span::unknown()` to the `Value::test_...` constructors. This should make things more readable and also simplify changes to the `Span` system in the future.
This commit is contained in:
committed by
GitHub
parent
7d67ca3652
commit
4b301710d3
@@ -97,23 +97,17 @@ On Windows, an extra 'prefix' column is added."#
|
||||
|
||||
#[cfg(windows)]
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
use nu_protocol::record;
|
||||
|
||||
vec![
|
||||
Example {
|
||||
description: "Parse a single path",
|
||||
example: r"'C:\Users\viking\spam.txt' | path parse",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec![
|
||||
"prefix".into(),
|
||||
"parent".into(),
|
||||
"stem".into(),
|
||||
"extension".into(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("C:"),
|
||||
Value::test_string(r"C:\Users\viking"),
|
||||
Value::test_string("spam"),
|
||||
Value::test_string("txt"),
|
||||
],
|
||||
result: Some(Value::test_record(record! {
|
||||
"prefix" => Value::test_string("C:"),
|
||||
"parent" => Value::test_string(r"C:\Users\viking"),
|
||||
"stem" => Value::test_string("spam"),
|
||||
"extension" => Value::test_string("txt"),
|
||||
})),
|
||||
},
|
||||
Example {
|
||||
@@ -124,52 +118,28 @@ On Windows, an extra 'prefix' column is added."#
|
||||
Example {
|
||||
description: "Ignore the extension",
|
||||
example: r"'C:\Users\viking.d' | path parse --extension ''",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec![
|
||||
"prefix".into(),
|
||||
"parent".into(),
|
||||
"stem".into(),
|
||||
"extension".into(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("C:"),
|
||||
Value::test_string(r"C:\Users"),
|
||||
Value::test_string("viking.d"),
|
||||
Value::test_string(""),
|
||||
],
|
||||
result: Some(Value::test_record(record! {
|
||||
"prefix" => Value::test_string("C:"),
|
||||
"parent" => Value::test_string(r"C:\Users"),
|
||||
"stem" => Value::test_string("viking.d"),
|
||||
"extension" => Value::test_string(""),
|
||||
})),
|
||||
},
|
||||
Example {
|
||||
description: "Parse all paths in a list",
|
||||
example: r"[ C:\Users\viking.d C:\Users\spam.txt ] | path parse",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(Record {
|
||||
cols: vec![
|
||||
"prefix".into(),
|
||||
"parent".into(),
|
||||
"stem".into(),
|
||||
"extension".into(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("C:"),
|
||||
Value::test_string(r"C:\Users"),
|
||||
Value::test_string("viking"),
|
||||
Value::test_string("d"),
|
||||
],
|
||||
Value::test_record(record! {
|
||||
"prefix" => Value::test_string("C:"),
|
||||
"parent" => Value::test_string(r"C:\Users"),
|
||||
"stem" => Value::test_string("viking"),
|
||||
"extension" => Value::test_string("d"),
|
||||
}),
|
||||
Value::test_record(Record {
|
||||
cols: vec![
|
||||
"prefix".into(),
|
||||
"parent".into(),
|
||||
"stem".into(),
|
||||
"extension".into(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("C:"),
|
||||
Value::test_string(r"C:\Users"),
|
||||
Value::test_string("spam"),
|
||||
Value::test_string("txt"),
|
||||
],
|
||||
Value::test_record(record! {
|
||||
"prefix" => Value::test_string("C:"),
|
||||
"parent" => Value::test_string(r"C:\Users"),
|
||||
"stem" => Value::test_string("spam"),
|
||||
"extension" => Value::test_string("txt"),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
@@ -178,17 +148,16 @@ On Windows, an extra 'prefix' column is added."#
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
use nu_protocol::record;
|
||||
|
||||
vec![
|
||||
Example {
|
||||
description: "Parse a path",
|
||||
example: r"'/home/viking/spam.txt' | path parse",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["parent".into(), "stem".into(), "extension".into()],
|
||||
vals: vec![
|
||||
Value::test_string("/home/viking"),
|
||||
Value::test_string("spam"),
|
||||
Value::test_string("txt"),
|
||||
],
|
||||
result: Some(Value::test_record(record! {
|
||||
"parent" => Value::test_string("/home/viking"),
|
||||
"stem" => Value::test_string("spam"),
|
||||
"extension" => Value::test_string("txt"),
|
||||
})),
|
||||
},
|
||||
Example {
|
||||
@@ -199,34 +168,25 @@ On Windows, an extra 'prefix' column is added."#
|
||||
Example {
|
||||
description: "Ignore the extension",
|
||||
example: r"'/etc/conf.d' | path parse --extension ''",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["parent".into(), "stem".into(), "extension".into()],
|
||||
vals: vec![
|
||||
Value::test_string("/etc"),
|
||||
Value::test_string("conf.d"),
|
||||
Value::test_string(""),
|
||||
],
|
||||
result: Some(Value::test_record(record! {
|
||||
"parent" => Value::test_string("/etc"),
|
||||
"stem" => Value::test_string("conf.d"),
|
||||
"extension" => Value::test_string(""),
|
||||
})),
|
||||
},
|
||||
Example {
|
||||
description: "Parse all paths in a list",
|
||||
example: r"[ /home/viking.d /home/spam.txt ] | path parse",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(Record {
|
||||
cols: vec!["parent".into(), "stem".into(), "extension".into()],
|
||||
vals: vec![
|
||||
Value::test_string("/home"),
|
||||
Value::test_string("viking"),
|
||||
Value::test_string("d"),
|
||||
],
|
||||
Value::test_record(record! {
|
||||
"parent" => Value::test_string("/home"),
|
||||
"stem" => Value::test_string("viking"),
|
||||
"extension" => Value::test_string("d"),
|
||||
}),
|
||||
Value::test_record(Record {
|
||||
cols: vec!["parent".into(), "stem".into(), "extension".into()],
|
||||
vals: vec![
|
||||
Value::test_string("/home"),
|
||||
Value::test_string("spam"),
|
||||
Value::test_string("txt"),
|
||||
],
|
||||
Value::test_record(record! {
|
||||
"parent" => Value::test_string("/home"),
|
||||
"stem" => Value::test_string("spam"),
|
||||
"extension" => Value::test_string("txt"),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
|
Reference in New Issue
Block a user