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
@@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoPipelineData, PipelineData, Record, ShellError, Signature, Span,
|
||||
record, Category, Example, IntoPipelineData, PipelineData, Record, ShellError, Signature, Span,
|
||||
Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
@@ -51,28 +51,21 @@ impl Command for Histogram {
|
||||
Example {
|
||||
description: "Compute a histogram for a list of numbers",
|
||||
example: "[1 2 1] | histogram",
|
||||
result: Some(Value::list (
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["value".to_string(), "count".to_string(), "quantile".to_string(), "percentage".to_string(), "frequency".to_string()],
|
||||
vals: vec![
|
||||
Value::test_int(1),
|
||||
Value::test_int(2),
|
||||
Value::test_float(0.6666666666666666),
|
||||
Value::test_string("66.67%"),
|
||||
Value::test_string("******************************************************************"),
|
||||
],
|
||||
result: Some(Value::test_list (
|
||||
vec![Value::test_record(record! {
|
||||
"value" => Value::test_int(1),
|
||||
"count" => Value::test_int(2),
|
||||
"quantile" => Value::test_float(0.6666666666666666),
|
||||
"percentage" => Value::test_string("66.67%"),
|
||||
"frequency" => Value::test_string("******************************************************************"),
|
||||
}),
|
||||
Value::test_record(Record {
|
||||
cols: vec!["value".to_string(), "count".to_string(), "quantile".to_string(), "percentage".to_string(), "frequency".to_string()],
|
||||
vals: vec![
|
||||
Value::test_int(2),
|
||||
Value::test_int(1),
|
||||
Value::test_float(0.3333333333333333),
|
||||
Value::test_string("33.33%"),
|
||||
Value::test_string("*********************************"),
|
||||
],
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(2),
|
||||
"count" => Value::test_int(1),
|
||||
"quantile" => Value::test_float(0.3333333333333333),
|
||||
"percentage" => Value::test_string("33.33%"),
|
||||
"frequency" => Value::test_string("*********************************"),
|
||||
})],
|
||||
Span::test_data(),
|
||||
)
|
||||
),
|
||||
},
|
||||
|
Reference in New Issue
Block a user