mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 04:38:15 +02:00
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
@ -2,8 +2,7 @@ use super::url;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
record, Category, Example, PipelineData, Record, ShellError, Signature, Span, SyntaxShape,
|
||||
Type, Value,
|
||||
record, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
use url::Url;
|
||||
@ -56,36 +55,20 @@ impl Command for SubCommand {
|
||||
vec![Example {
|
||||
description: "Parses a url",
|
||||
example: "'http://user123:pass567@www.example.com:8081/foo/bar?param1=section&p2=&f[name]=vldc#hello' | url parse",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec![
|
||||
"scheme".to_string(),
|
||||
"username".to_string(),
|
||||
"password".to_string(),
|
||||
"host".to_string(),
|
||||
"port".to_string(),
|
||||
"path".to_string(),
|
||||
"query".to_string(),
|
||||
"fragment".to_string(),
|
||||
"params".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("http"),
|
||||
Value::test_string("user123"),
|
||||
Value::test_string("pass567"),
|
||||
Value::test_string("www.example.com"),
|
||||
Value::test_string("8081"),
|
||||
Value::test_string("/foo/bar"),
|
||||
Value::test_string("param1=section&p2=&f[name]=vldc"),
|
||||
Value::test_string("hello"),
|
||||
Value::test_record(Record {
|
||||
cols: vec!["param1".to_string(), "p2".to_string(), "f[name]".to_string()],
|
||||
vals: vec![
|
||||
Value::test_string("section"),
|
||||
Value::test_string(""),
|
||||
Value::test_string("vldc"),
|
||||
],
|
||||
result: Some(Value::test_record(record! {
|
||||
"scheme" => Value::test_string("http"),
|
||||
"username" => Value::test_string("user123"),
|
||||
"password" => Value::test_string("pass567"),
|
||||
"host" => Value::test_string("www.example.com"),
|
||||
"port" => Value::test_string("8081"),
|
||||
"path" => Value::test_string("/foo/bar"),
|
||||
"query" => Value::test_string("param1=section&p2=&f[name]=vldc"),
|
||||
"fragment" => Value::test_string("hello"),
|
||||
"params" => Value::test_record(record! {
|
||||
"param1" => Value::test_string("section"),
|
||||
"p2" => Value::test_string(""),
|
||||
"f[name]" => Value::test_string("vldc"),
|
||||
}),
|
||||
],
|
||||
})),
|
||||
}]
|
||||
}
|
||||
|
Reference in New Issue
Block a user