mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:25:42 +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,7 +2,7 @@ use eml_parser::eml::*;
|
||||
use eml_parser::EmlParser;
|
||||
use indexmap::map::IndexMap;
|
||||
use nu_plugin::{EvaluatedCall, LabeledError};
|
||||
use nu_protocol::{record, PluginExample, Record, ShellError, Span, Value};
|
||||
use nu_protocol::{record, PluginExample, ShellError, Span, Value};
|
||||
|
||||
const DEFAULT_BODY_PREVIEW: usize = 50;
|
||||
pub const CMD_NAME: &str = "from eml";
|
||||
@ -24,31 +24,17 @@ Subject: Welcome
|
||||
To: someone@somewhere.com
|
||||
Test' | from eml"
|
||||
.into(),
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec![
|
||||
"Subject".to_string(),
|
||||
"From".to_string(),
|
||||
"To".to_string(),
|
||||
"Body".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("Welcome"),
|
||||
Value::test_record(Record {
|
||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||
vals: vec![
|
||||
Value::nothing(Span::test_data()),
|
||||
Value::test_string("test@email.com"),
|
||||
],
|
||||
result: Some(Value::test_record(record! {
|
||||
"Subject" => Value::test_string("Welcome"),
|
||||
"From" => Value::test_record(record! {
|
||||
"Name" => Value::nothing(Span::test_data()),
|
||||
"Address" => Value::test_string("test@email.com"),
|
||||
}),
|
||||
Value::test_record(Record {
|
||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||
vals: vec![
|
||||
Value::nothing(Span::test_data()),
|
||||
Value::test_string("someone@somewhere.com"),
|
||||
],
|
||||
"To" => Value::test_record(record! {
|
||||
"Name" => Value::nothing(Span::test_data()),
|
||||
"Address" => Value::test_string("someone@somewhere.com"),
|
||||
}),
|
||||
Value::test_string("Test"),
|
||||
],
|
||||
"Body" => Value::test_string("Test"),
|
||||
})),
|
||||
},
|
||||
PluginExample {
|
||||
@ -58,31 +44,17 @@ Subject: Welcome
|
||||
To: someone@somewhere.com
|
||||
Test' | from eml -b 1"
|
||||
.into(),
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec![
|
||||
"Subject".to_string(),
|
||||
"From".to_string(),
|
||||
"To".to_string(),
|
||||
"Body".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("Welcome"),
|
||||
Value::test_record(Record {
|
||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||
vals: vec![
|
||||
Value::nothing(Span::test_data()),
|
||||
Value::test_string("test@email.com"),
|
||||
],
|
||||
result: Some(Value::test_record(record! {
|
||||
"Subject" => Value::test_string("Welcome"),
|
||||
"From" => Value::test_record(record! {
|
||||
"Name" => Value::nothing(Span::test_data()),
|
||||
"Address" => Value::test_string("test@email.com"),
|
||||
}),
|
||||
Value::test_record(Record {
|
||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||
vals: vec![
|
||||
Value::nothing(Span::test_data()),
|
||||
Value::test_string("someone@somewhere.com"),
|
||||
],
|
||||
"To" => Value::test_record(record! {
|
||||
"Name" => Value::nothing(Span::test_data()),
|
||||
"Address" => Value::test_string("someone@somewhere.com"),
|
||||
}),
|
||||
Value::test_string("T"),
|
||||
],
|
||||
"Body" => Value::test_string("T"),
|
||||
})),
|
||||
},
|
||||
]
|
||||
|
@ -2,7 +2,7 @@ use ical::parser::ical::component::*;
|
||||
use ical::property::Property;
|
||||
use indexmap::map::IndexMap;
|
||||
use nu_plugin::{EvaluatedCall, LabeledError};
|
||||
use nu_protocol::{record, PluginExample, Record, ShellError, Span, Value};
|
||||
use nu_protocol::{record, PluginExample, ShellError, Span, Value};
|
||||
use std::io::BufReader;
|
||||
|
||||
pub const CMD_NAME: &str = "from ics";
|
||||
@ -55,29 +55,15 @@ pub fn examples() -> Vec<PluginExample> {
|
||||
END:VCALENDAR' | from ics"
|
||||
.into(),
|
||||
description: "Converts ics formatted string to table".into(),
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec![
|
||||
"properties".to_string(),
|
||||
"events".to_string(),
|
||||
"alarms".to_string(),
|
||||
"to-Dos".to_string(),
|
||||
"journals".to_string(),
|
||||
"free-busys".to_string(),
|
||||
"timezones".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::list(vec![], Span::test_data()),
|
||||
Value::list(vec![], Span::test_data()),
|
||||
Value::list(vec![], Span::test_data()),
|
||||
Value::list(vec![], Span::test_data()),
|
||||
Value::list(vec![], Span::test_data()),
|
||||
Value::list(vec![], Span::test_data()),
|
||||
Value::list(vec![], Span::test_data()),
|
||||
],
|
||||
})],
|
||||
Span::test_data(),
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"properties" => Value::test_list(vec![]),
|
||||
"events" => Value::test_list(vec![]),
|
||||
"alarms" => Value::test_list(vec![]),
|
||||
"to-Dos" => Value::test_list(vec![]),
|
||||
"journals" => Value::test_list(vec![]),
|
||||
"free-busys" => Value::test_list(vec![]),
|
||||
"timezones" => Value::test_list(vec![]),
|
||||
})])),
|
||||
}]
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nu_plugin::{EvaluatedCall, LabeledError};
|
||||
use nu_protocol::{PluginExample, Record, ShellError, Value};
|
||||
use nu_protocol::{record, PluginExample, Record, ShellError, Value};
|
||||
|
||||
pub const CMD_NAME: &str = "from ini";
|
||||
|
||||
@ -57,12 +57,11 @@ a=1
|
||||
b=2' | from ini"
|
||||
.into(),
|
||||
description: "Converts ini formatted string to record".into(),
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["foo".to_string()],
|
||||
vals: vec![Value::test_record(Record {
|
||||
cols: vec!["a".to_string(), "b".to_string()],
|
||||
vals: vec![Value::test_string("1"), Value::test_string("2")],
|
||||
})],
|
||||
result: Some(Value::test_record(record! {
|
||||
"foo" => Value::test_record(record! {
|
||||
"a" => Value::test_string("1"),
|
||||
"b" => Value::test_string("2"),
|
||||
}),
|
||||
})),
|
||||
}]
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use ical::parser::vcard::component::*;
|
||||
use ical::property::Property;
|
||||
use indexmap::map::IndexMap;
|
||||
use nu_plugin::{EvaluatedCall, LabeledError};
|
||||
use nu_protocol::{record, PluginExample, Record, ShellError, Span, Value};
|
||||
use nu_protocol::{record, PluginExample, ShellError, Span, Value};
|
||||
|
||||
pub const CMD_NAME: &str = "from vcf";
|
||||
|
||||
@ -55,53 +55,27 @@ EMAIL:foo@bar.com
|
||||
END:VCARD' | from vcf"
|
||||
.into(),
|
||||
description: "Converts ics formatted string to table".into(),
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["properties".to_string()],
|
||||
vals: vec![Value::list(
|
||||
vec![
|
||||
Value::test_record(Record {
|
||||
cols: vec![
|
||||
"name".to_string(),
|
||||
"value".to_string(),
|
||||
"params".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("N"),
|
||||
Value::test_string("Foo"),
|
||||
Value::nothing(Span::test_data()),
|
||||
],
|
||||
}),
|
||||
Value::test_record(Record {
|
||||
cols: vec![
|
||||
"name".to_string(),
|
||||
"value".to_string(),
|
||||
"params".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("FN"),
|
||||
Value::test_string("Bar"),
|
||||
Value::nothing(Span::test_data()),
|
||||
],
|
||||
}),
|
||||
Value::test_record(Record {
|
||||
cols: vec![
|
||||
"name".to_string(),
|
||||
"value".to_string(),
|
||||
"params".to_string(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::test_string("EMAIL"),
|
||||
Value::test_string("foo@bar.com"),
|
||||
Value::nothing(Span::test_data()),
|
||||
],
|
||||
}),
|
||||
],
|
||||
Span::test_data(),
|
||||
)],
|
||||
})],
|
||||
Span::test_data(),
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"properties" => Value::test_list(
|
||||
vec![
|
||||
Value::test_record(record! {
|
||||
"name" => Value::test_string("N"),
|
||||
"value" => Value::test_string("Foo"),
|
||||
"params" => Value::nothing(Span::test_data()),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"name" => Value::test_string("FN"),
|
||||
"value" => Value::test_string("Bar"),
|
||||
"params" => Value::nothing(Span::test_data()),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"name" => Value::test_string("EMAIL"),
|
||||
"value" => Value::test_string("foo@bar.com"),
|
||||
"params" => Value::nothing(Span::test_data()),
|
||||
}),
|
||||
],
|
||||
),
|
||||
})])),
|
||||
}]
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user